我有一个简单的程序,可以拍摄视频并播放它(尽管它对视频进行了一些图像处理)。可以从对话框结果中检索视频,也可以直接通过给出文件路径来检索视频。当我使用CV::CvCapture 捕获1,我得到像 capture1.isOpen() 这样的属性,capture1.get(CV_CAP_PROP_FRAME_COUNT)等等,但是当我使用时CvCapture* 捕获2我收到奇怪的错误。
我想用简历::CvCapture 捕获1因为我的职能符合capture1。或者有什么方法可以使用这两种类型并在它们之间进行某种转换,例如类型铸造或者是其他东西。
实际上我有两个程序,程序1的功能是简历::CvCapture程序2的功能是简历捕获*。我的意思是这两个程序以不同的方式读取视频文件。
然后我合并这两个程序以使用program1 中的一些函数和program2 中的一些函数。但我无法转换简历::CvCapture to 简历捕获*.
我正在使用 OpenCv 和 Qt Creator。
我的代码很长,无法在这里发布,但我简化了代码,使其更小且易于理解。我的代码可能无法正确编译,因为我修改了它以使其更简单。
任何帮助,将不胜感激。提前致谢 :)
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.
}