cvCaptureFromFile始终为NULL

时间:2018-08-15 15:23:47

标签: opencv visual-c++ video-capture

opencv版本3.4.1 Visual Studio 2017 C ++

我已经编译了一个代码,该代码显示有关图像的信息并输出图像。但是,即使在该路径中有一个文件,也会激活功能“如果”并且输出“找不到视频文件”。我尝试使用该方法通过搜索Internet重命名ffmpeg341_64,但它已经是ffmpeg341_64。请告诉我如何。 下面是您编写的代码。

#include "opencv\cv.h"
#include "opencv\highgui.h"
#include <stdio.h>

int main()
{
CvCapture *capture = cvCaptureFromFile("c:/opencv/Capture.mp4");
if (!capture)
{
    printf("the video file was not found");
        return 0;
}
int width = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
int height = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
double fps = cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
int nTotalFrame = (int)cvGetCaptureProperty(capture,CV_CAP_PROP_FRAME_COUNT);
int fourcc = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FOURCC);

printf("fps= %f, frame_size= (%d, %d) \n", fps, width, height);
printf("nTotalFrame = %d\n", nTotalFrame);
char *ptr=(char *)&fourcc;
printf("fourcc = %c%c%c%c \n", ptr[0], ptr[1], ptr[2], ptr[3]);

IplImage *frame;
cvNamedWindow("video frame", CV_WINDOW_AUTOSIZE);
for (;;)
{
    frame = cvQueryFrame(capture);
    if (!frame)
        break;
    cvShowImage("video frame", frame);
    char chKey = cvWaitKey(10);
    if (chKey == 27)
        break;
}
cvDestroyAllWindows();
cvReleaseCapture(&capture);
return 0;
 }

0 个答案:

没有答案