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

  • Home
  • SEARCH
  • 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 8348163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:36:41+00:00 2026-06-09T07:36:41+00:00

The code is for motion tracking. It tracks different points across 2 images. However,

  • 0

The code is for motion tracking. It tracks different points across 2 images. However, the memory size increases a lot every time the function is called.
I know it probably has something to do with the cvPoints probably. What’s a good way to fix it? Thanks

 float calcorient(IplImage *imgA, IplImage *imgB) {
    // Initialize, load two images from the file system, and
    // allocate the images and other structures we will need for
    // results.
    //
    const int MAX_CORNERS = 500;
    CvSize    img_sz   = cvGetSize( imgA );
    int       win_size = 10;
    IplImage* imgC = cvCreateImage( img_sz, IPL_DEPTH_32F, 3 );
    // The first thing we need to do is get the features
    // we want to track.
    //
    IplImage* eig_image = cvCreateImage( img_sz, IPL_DEPTH_32F, 1 );
    IplImage* tmp_image = cvCreateImage( img_sz, IPL_DEPTH_32F, 1 );
    int           corner_count = MAX_CORNERS;
    CvPoint2D32f* cornersA     = new CvPoint2D32f[ MAX_CORNERS ];
    cvGoodFeaturesToTrack(
        imgA,
        eig_image,
        tmp_image,
        cornersA,
        &corner_count,
        0.01,
        5.0,
        0,
        3,
        0,
        0.04
        );
    cvFindCornerSubPix(
        imgA,
        cornersA,
        corner_count,
        cvSize(win_size,win_size),
        cvSize(-1,-1),
        cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03)
        );
    // Call the Lucas Kanade algorithm
    //
    char  features_found[ MAX_CORNERS ];
    float feature_errors[ MAX_CORNERS ];
    CvSize pyr_sz = cvSize( imgA->width+8, imgB->height/3 );
    IplImage* pyrA = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1 );
    IplImage* pyrB = cvCreateImage( pyr_sz, IPL_DEPTH_32F, 1 );
    CvPoint2D32f* cornersB     = new CvPoint2D32f[ MAX_CORNERS ];
    cvCalcOpticalFlowPyrLK(
        imgA,
        imgB, 
        pyrA,
        pyrB,
        cornersA,
        cornersB,
        corner_count,
        cvSize( win_size,win_size ),
        5,
        features_found,
        feature_errors,
        cvTermCriteria( CV_TERMCRIT_ITER | CV_TERMCRIT_EPS, 20, .3 ),
        0
        );
    // Now make some image of what we are looking at:
    //
    float sum=0;

    for( int i=0; i<corner_count; i++ ) {
        if( features_found[i]==0|| feature_errors[i]>550 ) {
            //printf("Error is %f\n",feature_errors[i]);
            continue;
        }
        //printf("Got it\n");
        sum+=cornersA[i].x-cornersB[i].x;
        //printf("%f\n",sum);
        CvPoint p0 = cvPoint(
            cvRound( cornersA[i].x ),
            cvRound( cornersA[i].y )
            );
        CvPoint p1 = cvPoint(
            cvRound( cornersB[i].x ),
            cvRound( cornersB[i].y )
            );
        cvLine( imgC, p0, p1, CV_RGB(255,0,0),2 );
    }
    //cvNamedWindow("ImageA",0);
    //cvNamedWindow("ImageB",0);
    //cvNamedWindow("LKpyr_OpticalFlow",0);
    //cvShowImage("ImageA",imgA);
    //cvShowImage("ImageB",imgB);
    //cvShowImage("LKpyr_OpticalFlow",imgC);
    //cvWaitKey(1);
    return sum;
}
  • 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-06-09T07:36:42+00:00Added an answer on June 9, 2026 at 7:36 am

    Looks like you’re allocating a bunch of memory and not deleting it.

    Try adding the lines:

    delete [] cornersA; 
    delete [] cornersB;
    

    at the end of your function.

    You might also check out the cvCreate calls — if they are not getting freed up elsewhere those could be contributing to the problem.

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

Sidebar

Related Questions

I'm using core motion in my app. This code works fine: motionManager = [[CMMotionManager
When I save the code for a Motion Chart into an html file and
I have written code for an application. It has some motion events. The motion
Ruby Motion comes with a lot of pre-built functions that are formatted like this:
The following code works until I add a link around the images. It works
Possible Duplicate: Is it worth it to code different functionality for users with javascript
Is it possible to make a motion tween with as2 code only ( not
As I wanted to animate an image in projectile motion, My code is as
This code renders the motion of the player, changing the picture. Locally it works
I want the javascript code to show a div in slow motion. function showDiv(divID)

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.