Ruh*_*boy 2 c c++ opencv image-processing computer-vision
我有一个简单的程序,它拍摄视频并播放它(虽然它对视频进行了一些图像处理).可以从对话框结果中检索视频,也可以直接通过提供文件的路径来检索视频.当我使用cv :: CvCapture capture1时,我得到了像capture1.isOpen(),capture1.get(CV_CAP_PROP_FRAME_COUNT)等属性,但是当我使用CvCapture*capture2时,我得到了奇怪的错误.
我想使用cv :: CvCapture capture1,因为我的函数与capture1一致.或者是否有任何方法可以使用这两种类型,在它们之间进行某种转换,如类型转换或其他类型.
其实我有两个节目,程序1的功能是为CV :: CvCapture和程序2的功能是为CvCapture*.我的意思是这两个程序以不同的方式读取视频文件.
然后我合并了这两个程序,以使用program1中的一些函数和program2中的一些函数.但我无法将cv :: CvCapture转换为CvCapture*.
我正在使用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.
}
Run Code Online (Sandbox Code Playgroud)
cv::VideoCapture
来自OpenCV 的C++接口,可用于从摄像机设备和磁盘上的文件中捕获
cv::VideoCapture capture1(fileName);
if (!capture.isOpened())
{
// failed, print error message
}
Run Code Online (Sandbox Code Playgroud)
并且cvCaptureFromCAM()
是来自OpenCV 的C接口的功能,仅用于从相机设备捕获:
CvCapture* capture2 = cvCaptureFromCAM(-1);
if (!capture2)
{
// failed, print error message
}
Run Code Online (Sandbox Code Playgroud)
不要将这些接口混合/合并在一起,选择一个并坚持下去.
如果要使用C接口从视频文件中捕获,请cvCaptureFromFile()
改用:
CvCapture* capture = cvCaptureFromFile(fileName);
if (!capture)
{
// print error, quit application
}
Run Code Online (Sandbox Code Playgroud)
检查以下示例:
归档时间: |
|
查看次数: |
11216 次 |
最近记录: |