I am using cvFindContours to find the contours of edge detected frames. First I use cvCanny to get the edges frame from actual frame. Then I am trying to find the contours.Here is my code structure
//used cvcanny to get cur and next frames
CvMemStorage curstorage=CvMemStorage.create();
CvMemStorage nextstorage=CvMemStorage.create();
CvSeq cursquares = new CvContour();
CvSeq nextsquares = new CvContour();
cvFindContours(cur, curstorage, cursquares, Loader.sizeof(CvContour.class),CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
cvFindContours(next, nextstorage, nextsquares, Loader.sizeof(CvContour.class),CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
When I run the code I get Access Violation Exception.Here is the exception details.
A fatal error has been detected by the Java Runtime Environment:
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000062e3c320, pid=9184, tid=6236
JRE version: 7.0_17-b02 Java VM: Java HotSpot(TM) 64-Bit Server VM (23.7-b01 mixed mode windows-amd64 compressed oops) Problematic frame: C [msvcr100.dll+0x3c320] memset+0x80
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
I am not sure where I am going wrong as I have just started using javacv.Any suggestions regarding this will be helpful.Thank you.
You probably do not reference your CvMemStorage
instances after the cvFindContours
calls, only the CvSeq
's. The storage might be evaluated as not referenced and thus GCed, while you still need to use CvSeq, which depends on the storage. This will cause EXCEPTION_ACCESS_VIOLATION at the first usage of CvSeq after the GC happens.
Try to add:
curstorage.release();
nextstorage.release();
after you quit using CvSeq. It has two advantages: it proactively releases native memory without waiting to GC and it prevents the GC from releasing storages too early. See my question here: JavaCV native object deallocation.