2017-09-19 121 views
2

我想讀取視頻文件,但它的拋出錯誤。 的代碼是:無法讀取視頻在opencv

#include <iostream> 
#include <opencv/highgui.h> 
#include <opencv/cv.h> 
#include <opencv2/opencv.hpp> 
using namespace cv; 
int main(int argc, char* argv[]) 
{ 
    Mat inputVideo; 
    Mat frame; 
    Mat HSV; 
    Mat tracking; 
    char checkKey; 
    VideoCapture capture; 
    capture.open("video/input.mp4"); 
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640); 
    capture.set(CV_CAP_PROP_FRAME_HEIGHT,480);  
    namedWindow("Original Video", WINDOW_AUTOSIZE); 
    while(1){ 
     capture.read(inputVideo); 
     if (!inputVideo.empty()) 
     { 
      imshow("Original Video",inputVideo); 

     } 
     waitKey(20); 

    } 
    return 0; 
} 

在運行這段代碼,我得到的錯誤是:

無法停止流:用於設備不適當的ioctl

(video_reading:3459): GLib-GObject-CRITICAL **:g_object_set: 斷言'G_IS_OBJECT(object)'失敗

我試過尋找解決方案,但我沒有得到它。有人能幫我解決這個錯誤嗎?

+0

可能是ffmpeg錯誤。嘗試使用cmake再次構建 – Anirudh

+0

@Ran是否使用Gstreamer構建'opencv'? –

+0

我不知道什麼是gstreamer。我不得不使用建立的OpenCV以下命令的cmake -D CMAKE_BUILD_TYPE = RELEASE -D CMAKE_INSTALL_PREFIX =的/ usr /本地-D WITH_TBB = ON -D BUILD_NEW_PYTHON_SUPPORT = ON -D WITH_V4L = ON -D INSTALL_C_EXAMPLES = ON -D INSTALL_PYTHON_EXAMPLES = ON -D BUILD_EXAMPLES = ON -D WITH_QT = ON -D WITH_OPENGL = ON -D OPENCV_EXTRA_MODULES_PATH = ../../opencv_contrib /模塊-D PYTHON_EXECUTABLE =的/ usr /斌/ python3 -D WITH_CUDA = ON -D WITH_FFMPEG = ON -D ENABLE_FAST_MATH = 1 - d CUDA_FAST_MATH = 1 -D WITH_CUBLAS = 1 .. – Ran

回答

0

我做你的代碼變化不大。試試這個:

#include <iostream> 
#include <opencv/highgui.h> 
#include <opencv/cv.h> 
#include <opencv2/opencv.hpp> 
using namespace cv; 
int main(int argc, char* argv[]) 
{ 
    Mat inputVideo; 
    Mat frame; 
    Mat HSV; 
    Mat tracking; 
    char checkKey; 
    VideoCapture capture; 
    capture.open("video/input.mp4"); 
    capture.set(CV_CAP_PROP_FRAME_WIDTH, 640); 
    capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480); 
    namedWindow("Original Video", WINDOW_AUTOSIZE); 
    while (1) { 
     capture >> inputVideo; 
     if (inputVideo.empty()) 
      break; 
     imshow("Original Video", inputVideo); 
     waitKey(1); 
    } 
    capture.release(); 
    return 0; 
} 
+1

我覺得這並不能解決問題,可能仍給你同樣的錯誤 – Anirudh

+0

@jazz耶作爲Anirudh說的話,我收到了同樣的錯誤,如上所述。 – Ran

+1

好的。然後你必須再次用cmake構建它。對於我的系統,它工作。 – Jazz