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