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 8062853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:48:57+00:00 2026-06-05T10:48:57+00:00

I have a program that uses the OpenCV library (version 2.4.1) to capture video

  • 0

I have a program that uses the OpenCV library (version 2.4.1) to capture video from my laptop’s webcam (or any other connected camera) and save it to an .avi file. When I debug in Visual Studio 2010, I get an unhandled exception at the very end of the program, when either the CvCapture or the IplImage are being released. Here is the code:

    // WriteRealTimeCapturedVideo.cpp : Defines the entry point for the console application.
    #include "stdafx.h"
    #include "cv.h"
    #include "highgui.h"
    #include <stdio.h>

    int main()
    {
        CvCapture* capture = cvCaptureFromCAM( 1 ); //CV_CAP_ANY
        if ( !capture )
        {
            fprintf( stderr, "ERROR: capture is NULL \n" );
            getchar();
            return -1;
        }
        // Create a window in which the captured images will be presented
        cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );

        double fps = cvGetCaptureProperty (capture, CV_CAP_PROP_FPS);

        CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH), (int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT));

        #ifndef NOWRITE
        CvVideoWriter* writer = cvCreateVideoWriter("Capture.avi", CV_FOURCC('M','J','P','G'), fps, size); //CV_FOURCC('M','J','P','G')
        #endif

        int width = (int)(cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH));
        int height = (int)(cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT));

        IplImage* frame = cvCreateImage( cvSize( width,height ), IPL_DEPTH_8U, 1);

        while ( 1 )
        {
            // Get one frame
            frame = cvQueryFrame( capture );
            if ( !frame ) 
            {
                fprintf( stderr, "ERROR: frame is null...\n" );
                getchar();
                break;
            }
            cvShowImage( "mywindow", frame );
            #ifndef NOWRITE
            cvWriteToAVI( writer, frame );
            #endif
            char c = cvWaitKey(33);
            if( c == 27 ) break;
        }
        #ifndef NOWRITE
        cvReleaseVideoWriter( &writer );
        #endif
        cvDestroyWindow( "mywindow" );
        cvReleaseImage( &frame );
        cvReleaseCapture( &capture );
        return 0;
    }

I found that I have to have tbb.dll and tbb_debug.dll in the same directory as the source code (.cpp files) for the program to work. These dll’s can be downloaded from Intel.

The video capture works, that is, the window appears and displays the video, but the exception occurs no matter how I rearrange the release statements. If I remove the release statements (except for the VideoWriter), I don’t get the exception, but then the .avi file produced cannot be opened. The program exits the while loop when the user presses the Esc key.

  • 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-05T10:48:59+00:00Added an answer on June 5, 2026 at 10:48 am

    From openCV docu:

    cvQueryFrame

    Grabs and returns a frame from camera or file

    IplImage* cvQueryFrame( CvCapture* capture );

    capture
    video capturing structure.

    The function cvQueryFrame grabs a frame from camera or video file,
    decompresses and returns it. This function is just a combination of
    cvGrabFrame and cvRetrieveFrame in one call. The returned image should
    not be released or modified by user.

    So you don’t have to allocate or release the “frame”

    delete:

    IplImage* frame = cvCreateImage( cvSize( width,height ), IPL_DEPTH_8U, 1);
    

    and

    cvReleaseImage( &frame );
    

    and replace

    frame = cvQueryFrame( capture );
    

    with

    IplImage* frame = cvQueryFrame( capture );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that uses pthread library to do the matrix multiplication of
I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages.
I have a program that uses the win32com library to control iTunes, but have
I have a multithreaded openCV program that uses 4 threads to do the following:
I have created a c/c++ program which uses opencv library. I want to convert
I have a program that uses content from sd-card. I want to listen to
I have a program that uses the mt19937 random number generator from boost::random. I
I have a C# program that uses a class from another assembly, and this
I have written a program that uses widgets as container (for other widgets). Because
I am trying to run a program that uses OpenCV and I have gotten

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.