Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1041425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:21:04+00:00 2026-05-16T15:21:04+00:00

I had written a blob tracking algorithm in VC++. I had run it in

  • 0

I had written a blob tracking algorithm in VC++. I had run it in a console program, it just performed brilliantly.

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.

Now, in C#, after running for around 2 minutes, the application is throwing an error;

Insufficient memory (Out of memory)
in function cvAlloc, .\cxalloc.cpp(111)

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.

Can anyone please help me on what is causing it?

Thank You.

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->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->status = 1;
          return;
        }

        gray_img  = cvCreateImage( cvGetSize(img), img->depth, 1);
        thres_img = cvCreateImage( cvGetSize(img), img->depth, 1);
        blobs_img = cvCreateImage( cvGetSize(img), img->depth, 3);
    }


        /* Obtain a frame from the device */
        img = cvQueryFrame( capture );

        /* Always check if the device returns a frame */
        if( !img ) 
        {
         data->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 && blobs.GetNumBlobs()>i)
        {
         currentBlocb = blobs.GetBlob(i);
         rect = currentBlob->GetBoundingBox();
         PosX = currentBlob->MinX();
         PosY = currentBlob->MinY();

         currentBlob->FillBlob( blobs_img, CV_RGB(255,0,0));
        }

        cvZero(blobs_img);

        data->X=PosX;
        data->Y=PosY;
        data->status=1;
        return;

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#.

Apart from this, I am having a struct too

struct resultData
 {
     int X, Y, status;
     char* error;
 };

but I wonder if it would throw an OpenCV Exception, if any.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:21:04+00:00Added an answer on May 16, 2026 at 3:21 pm

    What about memory leaks? It doesn’t seem that you’re freeing all the resources like pointers to images and blobs. That should be your main concern. And cvAlloc() is internal function that OpenCV uses for memory allocation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had written a program in Python 3, but now want to convert it
I had written a small utility app just for my phone, which stopped the
As I had written in title, I have SQL query, run on Oracle DB,
This question has baffled myself and my cohorts. In the program I had written
I had earlier written a program in java which takes in as input a
I had written a Sudoku game including a solver in C, and wanted to
I had written a program in C to implement a simple stack. But I
I had written a small thread program when i compiled cc filename.c, i got
I had created a new console application in VS 2010. I had written some
I wanted to use qDebug in the Qt unit testing, i had written the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.