不能将“CV :: VideoCapture'到'CvCapture *' [英] cannot convert 'cv::VideoCapture' to 'CvCapture*'

查看:814
本文介绍了不能将“CV :: VideoCapture'到'CvCapture *'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的程序,它需要一个视频,并播放它(尽管它的一些视频图像处理)。视频可从对话框结果直接给予该文件的路径检索,或。当我使用 CV :: CvCapture捕捉1 后,我得到的属性,如capture1.isOpen(), capture1.get(CV_CAP_PROP_FRAME_COUNT)等,但是当我使用 CvCapture *捕捉2 我得到奇怪的错误。

我想使用 CV :: CvCapture捕捉1,因为我的功能都是按照捕捉1 即可。或者是有什么办法可以用某种它们之间的转换例如类型转换或别的东西。

使用这两种类型

其实我有两个节目,程序1的功能是的 CV :: CvCapture 并在该Program2中的功能是的 CvCapture * 。我的意思是这两个程序读取以不同的方式的视频文件。

我再合并这两个程序使用来自program1的某些功能和某些功能的Program2中。但我无法转换的 CV :: CvCapture CvCapture *

我使用的OpenCV与Qt Creator的。

我的code是非常长的,张贴在这里,但我已经简化我的code,使其体积更小,可以理解的。因为我修改了它,使其更简单我的code可能不正确编译。

任何帮助将是AP preciated。在此先感谢:)

 无效的MainWindow :: on_pushButton_clicked()
{ 性病::字符串文件名= QFileDialog :: getOpenFileName(这一点,TR(打开视频),TR(视频文件(* .MP4 * .AVI)))。toStdString()。CV :: VideoCapture捕捉器(文件名); //当我用CV :: VideoCapture捕捉它给出了一个错误//错误:无法转换'简历:: VideoCapture'到'CvCapture *'的参数'1'到'的IplImage * cvQueryFrame(CvCapture *)
    // CvCapture *捕捉2 = cvCaptureFromCAM(-1);
    //但是当我使用CvCapture *捕捉2,它不承认capture2.isOpend()和capture2.get(CV_CAP_PROP_FRAME_COUNT)等不工作。
    //有什么办法来VideoCapture转换为CvCapture *?
    如果(!capture.isOpened())
        {
            QMessageBox提示MSGBOX;
            msgBox.exec(); //一些消息框消息。不重要实际上
        }
 cvNamedWindow(名);
 *的IplImage = Ximage cvQueryFrame(捕捉);
 如果(!Ximage)
   {
     QMessageBox提示MSGBOX;
     msgBox.exec();
    } 双率= capture.get(CV_CAP_PROP_FPS);
 诠释帧=(int)的capture.get(CV_CAP_PROP_FRAME_COUNT);
INT frameno =(int)的capture.get(CV_CAP_PROP_POS_FRAMES);
 布尔车站(假); capture.read(imgsize); CV ::垫出来(imgsize.rows,imgsize.cols,CV_8SC1);
 CV ::垫OUT2(imgsize.rows,imgsize.cols,CV_8SC1);
        //我打印在标签上的帧号和总的帧。
            UI-> label_3->的setText(的QString ::号码(frameno / 1000)+/+的QString ::号码(帧/ 1000));
            用户界面 - > label-> setScaledContents(真);
            用户界面 - > label-> setPixmap(::的QPixmap fromImage(IMG1)); //我在这里展示的标签上的帧。
  }


解决方案

CV :: VideoCapture 是从 C ++接口 OpenCV的,并可用于从相机设备和从文件盘上捕获

  CV :: VideoCapture捕捉器(文件名);
如果(!capture.isOpened())
{
    //失败,打印错误信息
}

cvCaptureFromCAM()是从 C接口的OpenCV的函数这只是用来从摄像装置拍摄:

  CvCapture *捕捉2 = cvCaptureFromCAM(-1);
如果(!捕捉2)
{
    //失败,打印错误信息
}

不要混用/合并这个接口绑定在一起,选择一个,并坚持下去。

如果您想使用C接口从视频文件中获取,使用 cvCaptureFromFile()而不是:

  CvCapture *捕获= cvCaptureFromFile(文件名);
如果(!捕获)
{
    //打印错误,退出应用程序
}

检查这些例子:

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

解决方案

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:

这篇关于不能将“CV :: VideoCapture'到'CvCapture *'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆