为什么 OpenCV 会为此代码发出"Bad flag in unknown function"?



我一直在尝试使用Open CV API来获得一个真正的基本视频播放器。一切似乎都很顺利,直到视频剪辑结束,然后我得到了这个错误:

OpenCV错误:未知函数中的错误标志,文件。。。。。。。。\ocv\opencv\modules\core\src\array.cpp

这在imshow("视频",帧)的代码中造成了一个中断,我发现这是一个wierd,因为这是有效播放视频的部分,所以为什么它只会在剪辑的结尾引起骚动??我发现,在我播放的每个视频的最后90%中,它似乎都会给我这个错误,所以目前我正在努力解决这个问题,告诉它在播放完90%的视频后停止播放,但这不是一个很好的程序,所以有人能给我一些建议/帮助吗?

我看过其他人关于这件事的帖子,到目前为止,没有一个建议的解决方案对我有效。

这是我的密码。。。这只是一个实验性的作品,所以如果有点混乱,我很抱歉:

感谢您提前提供的帮助

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <direct.h>
#include <iostream>
using namespace cv;
void onTrackBarSlide(int);
double the_next_play_frame;
VideoCapture video("test.MOV"); // open the video file
int main(int, char**)
{
if(!video.isOpened())  // check if we succeeded
{
    return -1;
}
int no_of_frames =  video.get(CV_CAP_PROP_FRAME_COUNT); //total number of frames in       video
std::cout << no_of_frames << std::endl;
std::cout << video.get(CV_CAP_PROP_FPS) << std::endl;
namedWindow("Video", 1);
cvCreateTrackbar("trackbar", "Video", 0, 40, onTrackBarSlide);
double stop_at = no_of_frames * 0.999;
    for(;;){

    if(the_next_play_frame >= double(stop_at))
    {
        break;
    }
     Mat frame;
    video >> frame; // get a new frame from camera  
    imshow("Video", frame); // <---------- place where break/error occurs   
    if(waitKey(30) >= 0) 
    {
        break;
    }

}
return 0;
}
void onTrackBarSlide(int pos)
{
std::cout << getTrackbarPos("trackbar", "Video") << std::endl;
double frameratio = video.get(CV_CAP_PROP_FRAME_COUNT)/40; //10005 is the maximum   value the slider can actual hold
double next_play_frame = frameratio * getTrackbarPos("trackbar", "Video");
video.set(CV_CAP_PROP_POS_FRAMES,next_play_frame);
the_next_play_frame = next_play_frame;
}
VideoCapture video("test.MOV"); // open the video file
int main(int, char**)
{
if(!video.isOpened())  // check if we succeeded
{
    return -1;
}
}

尝试将VideoCapture实例化放入main中。

int main(){
 VideoCapture video("test.MOV"); // open the video file
...
}

最新更新