为什么OpenCV会为此代码发出“未知函数中的错误标志”?

时间:2011-06-15 15:40:19

标签: c++ opencv

我一直在努力让一个真正的基本视频播放器使用Open CV API。在视频剪辑结束之前,一切似乎都顺利进行,然后我收到了这个错误:

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

这会在imshow(“video”,frame)的代码中创建一个中断,我发现这很奇怪,因为这是有效播放视频的部分所以为什么它只会在剪辑结束时大惊小怪呢? ?我发现它似乎在我播放的每个视频的最后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;

}

1 个答案:

答案 0 :(得分:1)

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

...
}
相关问题