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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:37:56+00:00 2026-06-05T03:37:56+00:00

I have a simple program which takes a video and plays it (though it

  • 0

I have a simple program which takes a video and plays it (though it does some image processing on the video). The video can be retrieved from a Dialog Box result, or directly by giving the path of the file. When I use cv::CvCapture capture1, I get the properties like capture1.isOpen(), capture1.get(CV_CAP_PROP_FRAME_COUNT) etc. but when I use CvCapture* capture2 I get weird errors.

I want to use cv::CvCapture capture1 because of my functions are in accordance with capture1. Or is there any way to use both types with some kind of conversion between them like type casting or something else.

Actually I had two programs, the functions of the program1 was for cv::CvCapture and the functions of the program2 was for CvCapture*. I mean the two programs read the video file in different manners.

I then merged these two programs to use some functions from program1 and some functions from program2. But I can’t convert cv::CvCapture to CvCapture*.

I am using OpenCv with Qt Creator.

My code is very long to post here but I have simplified my code to make it smaller and understandable. My code may not compile correctly because I modified it to make it simpler.

Any help would be appreciated. Thanks in advance 🙂

void MainWindow::on_pushButton_clicked()
{

 std::string fileName = QFileDialog::getOpenFileName(this,tr("Open Video"), ".",tr("Video Files (*.mp4 *.avi)")).toStdString();

cv::VideoCapture  capture1(fileName);       // when I use the cv::VideoCapture capture it gives  an error

//error: cannot convert 'cv::VideoCapture' to 'CvCapture*' for argument '1' to 'IplImage* cvQueryFrame(CvCapture*)
    //CvCapture* capture2 = cvCaptureFromCAM(-1);
    // but when i use the CvCapture* capture2, it does not recognize capture2.isOpend() and capture2.get(CV_CAP_PROP_FRAME_COUNT) etc. don't work.
    // Is there any way to convert VideoCapture to CvCapture*?
    if (!capture.isOpened())
        {
            QMessageBox msgBox;
            msgBox.exec(); // some messagebox message. not important actually
        }
 cvNamedWindow( name );
 IplImage* Ximage = cvQueryFrame(capture);
 if (!Ximage)
   {
     QMessageBox msgBox;
     msgBox.exec();
    }

 double rate= capture.get(CV_CAP_PROP_FPS);
 int frames=(int)capture.get(CV_CAP_PROP_FRAME_COUNT);
int frameno=(int)capture.get(CV_CAP_PROP_POS_FRAMES);
 bool stop(false);

 capture.read(imgsize);

 cv::Mat out(imgsize.rows,imgsize.cols,CV_8SC1);
 cv::Mat out2(imgsize.rows,imgsize.cols,CV_8SC1);
        //I print the frame numbers and the total frames on  a label.
            ui->label_3->setText(QString::number(frameno/1000)+" / "+QString::number(frames/1000)); 
            ui->label->setScaledContents(true); 
            ui->label->setPixmap(QPixmap::fromImage(img1)); // here I show the frames on a label.
  }
  • 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-05T03:37:58+00:00Added an answer on June 5, 2026 at 3:37 am

    cv::VideoCapture is from the C++ interface of OpenCV, and can be used to capture from a camera device and from a file on the disk

    cv::VideoCapture  capture1(fileName); 
    if (!capture.isOpened())
    {
        // failed, print error message
    }
    

    and cvCaptureFromCAM() is a function from the C interface of OpenCV that is used only to capture from a camera device:

    CvCapture* capture2 = cvCaptureFromCAM(-1);
    if (!capture2)
    {
        // failed, print error message
    }
    

    Don’t mix/merge this interfaces together, pick one and stick with it.

    If you want to use the C interface to capture from a video file, use cvCaptureFromFile() instead:

    CvCapture* capture  = cvCaptureFromFile(fileName);
    if (!capture)
    {
        // print error, quit application
    }
    

    Check these examples:

    • Camera capture using the C interface
    • Camera capture using the C++ interface
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a simple program which takes argument input in one of the
I have a simple Ruby program which takes the command line arguments and posts
I have a program Sample which takes input both from stdin and a non-standard
I have a rather simple program which takes in a URL and spits out
I have a simple WebView application which takes some time to load up when
I have avery simple program which uses MediaPLayer. I am new to java and
Below, I have a simple program which uses the CImg library (http://cimg.sourceforge.net/) which iterates
I have a simple Delphi program that I'm working on, in which I am
I have been trying to create a simple program with Python which uses OpenCV
In my google maps program I have simple KML parser which retrieve only coordinates

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.