kallyani1989 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Invalid memory access using adaptive SURF feature detector #141

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I'm trying to detect features using the DynamicAdaptedFeatureDetector detector 
provided by OpenCV: the first loop completes successfully, but the second 
crashes with the error

Invalid memory access of location 0x7fac78c31750 rip=0x7fac78c31750

as soon as the detect method is called on the surf object. I've read on the 
OpenCV Reference Manual that it's necessary to keep the detector persisted, so 
I have the doubt that I'm creating the AdjusterAdapterPtr correctly: is that so?
I'm running the latest build of OpenCV with the latest JavaCV libraries on a 
MacBook Pro (MACOSX Lion).
Thanks in advance for any reply (and for JavaCV as well)!

Allan

    OpenCVFrameGrabber grabber = new OpenCVFrameGrabber(0);
    grabber.start();
    IplImage frame = grabber.grab();

    IplImage gray = IplImage.create(frame.width(), frame.height(), IPL_DEPTH_8U, 1);

    CanvasFrame canvasFrame = new CanvasFrame("Adaptive feature detector test");
    canvasFrame.setCanvasSize(frame.width(), frame.height());

    int adjuster_min_keypoints = 1000;
    int adjuster_max_keypoints = 1800;
    int surf_adjuster_max_iterations = 5;

    AdjusterAdapterPtr aaPtr = new AdjusterAdapterPtr().put(new SurfAdjuster());
    DynamicAdaptedFeatureDetector surf = new DynamicAdaptedFeatureDetector(aaPtr, adjuster_min_keypoints,
                adjuster_max_keypoints, surf_adjuster_max_iterations);

    KeyPoint kp;
    while (canvasFrame.isVisible()) {
        frame = grabber.grab();
        // Convert grabbed frame in grayscale
        cvCvtColor(frame, gray, CV_RGB2GRAY);

        // Detect features with dynamic adapted SURF
        kp = new KeyPoint(null);
        surf.detect(gray, kp, null);

        // Draw keypoints on original frame
        drawKeypoints(frame, kp, frame, CV_RGB(255, 0, 0), DrawMatchesFlags.DRAW_RICH_KEYPOINTS);

        canvasFrame.showImage(frame);

    }

    grabber.stop();
    canvasFrame.dispose();

Original issue reported on code.google.com by satto...@gmail.com on 23 Dec 2011 at 5:24

GoogleCodeExporter commented 8 years ago
You keep no reference to `new SurfAdjuster()` anywhere, so Java probably 
garbage collects it at some point, which deallocates C++ memory while its at 
it.. Let me know if keeping a reference somewhere solves this issue, and next 
time please post your questions on the mailing list if possible, thank you

Original comment by samuel.a...@gmail.com on 27 Dec 2011 at 9:31

GoogleCodeExporter commented 8 years ago
Adding a SurfAdjuster variable to keep the reference solved the problem, thank 
you for the advice!
Sorry about not posting the problem on the mailing list first, I'll definitely 
use it next time if necessary.
Thanks again for your availability,
Best regards,
Allan

Original comment by satto...@gmail.com on 27 Dec 2011 at 12:20

GoogleCodeExporter commented 8 years ago
Nice! Thanks

Original comment by samuel.a...@gmail.com on 29 Dec 2011 at 10:10