Note that there are some explanatory texts on larger screens.

plurals
  1. POMemory Overflow problem-OpenCV
    text
    copied!<p>I had written a blob tracking algorithm in VC++. I had run it in a console program, it just performed brilliantly.</p> <p>Now, I wanted to write the rest of my application in c#, so I made a dll of the VC++ code. And I am calling this dll from C# code. </p> <p>Now, in C#, after running for around 2 minutes, the application is throwing an error;</p> <pre><code>Insufficient memory (Out of memory) in function cvAlloc, .\cxalloc.cpp(111) </code></pre> <p>I am no where in the code, allocating memory using cvAlloc so I am just wondering what is causing it to throw this error. Moreover, the same code runs for hours when I run it in console without making it's dll. </p> <p>Can anyone please help me on what is causing it?</p> <p>Thank You.</p> <p>Code:</p> <pre><code>int NumberBlob = 0, PosX = 0, PosY = 0; IplImage *img = 0; IplImage *gray_img = 0; IplImage *thres_img = 0; IplImage *blobs_img = 0; int key = 0; /* Always check if the program can find a device */ if ( !capture ) { data-&gt;status = 0; return; } CBlobResult blobs; CBlob *currentBlob; CvRect rect; int frame_count = 0; int i = 0; int screen_x = GetSystemMetrics(SM_CXSCREEN); int screen_y = GetSystemMetrics(SM_CYSCREEN); int mouse_x,mouse_y; double x=0; double y=0; if( frame_count == 0 ) { /* Obtain a frame from the device */ img = cvQueryFrame( capture ); /* Always check if the device returns a frame */ if( !img ) { data-&gt;status = 1; return; } gray_img = cvCreateImage( cvGetSize(img), img-&gt;depth, 1); thres_img = cvCreateImage( cvGetSize(img), img-&gt;depth, 1); blobs_img = cvCreateImage( cvGetSize(img), img-&gt;depth, 3); } /* Obtain a frame from the device */ img = cvQueryFrame( capture ); /* Always check if the device returns a frame */ if( !img ) { data-&gt;status=2; return; } frame_count = frame_count + 1; /* Flip image once, after blob processing it is flipped back */ cvFlip(img,img,NULL); /* Convert image from Color to grayscale and then to binary (thresholded at 180) */ cvCvtColor(img,gray_img,CV_RGB2GRAY); cvThreshold(gray_img,thres_img,200,255,CV_THRESH_BINARY); /* Find Blobs that are White, Hence 'uchar backgroundColor = 0' (Black) */ blobs = CBlobResult(thres_img, NULL,0); /* Remove blobs if it does not cover minimum area specified below */ blobs.Filter( blobs, B_EXCLUDE, CBlobGetArea(),B_LESS,5,50); /* Number of blobs */ NumberBlob = blobs.GetNumBlobs(); /* 'i' points to blob 0, i.e., first blob */ /* If some blobs are detected then find the first blob */ if(i==0 &amp;&amp; blobs.GetNumBlobs()&gt;i) { currentBlocb = blobs.GetBlob(i); rect = currentBlob-&gt;GetBoundingBox(); PosX = currentBlob-&gt;MinX(); PosY = currentBlob-&gt;MinY(); currentBlob-&gt;FillBlob( blobs_img, CV_RGB(255,0,0)); } cvZero(blobs_img); data-&gt;X=PosX; data-&gt;Y=PosY; data-&gt;status=1; return; </code></pre> <p>This is all I am doing. This logic works fine when I run the code in an independent console application, but fails when I wrap it in a dll and call it from c#.</p> <p>Apart from this, I am having a struct too</p> <pre><code>struct resultData { int X, Y, status; char* error; }; </code></pre> <p>but I wonder if it would throw an OpenCV Exception, if any.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload