2013-03-04 36 views
0

您好我已經在OpenCV中編寫了以下代碼。基本上它從文件中讀取視頻。現在,我想創建一個調整視頻大小的函數,但我不確定如何從主函數調用「VideoCapture」類。我寫了一個示例函數來查看它是否會讀取任何內容,但它會編譯主函數中的精細顯示內容,但是不會從新創建的函數中編譯。任何幫助? P.S我不是很有經驗,忍受着我LOL。在OpenCV中的函數

 using namespace cv; 
    using namespace std; 

    void resize_video(VideoCapture capture); 

    int main(int argc, char** argv) 
    { 
     VideoCapture capture; //the C++ API class to capture the video from file 

     if(argc == 2) 
     capture.open(argv[1]); 
     else 
     capture.open(0); 

     if(!capture.isOpened()) 
     { 
      cout << "Cannot open video file " << endl; 
      return -1; 
     } 

     Mat frame; 
     namedWindow("display", CV_WINDOW_AUTOSIZE); 
     cout << "Get the video dimensions " << endl; 
     int fps = capture.get((int)CV_CAP_PROP_FPS); 
     int height = capture.get((int)CV_CAP_PROP_FRAME_HEIGHT); 
     int width = capture.get((int)CV_CAP_PROP_FRAME_WIDTH); 
     int noF = capture.get((int)CV_CAP_PROP_FRAME_COUNT); 
     CvSize size = cvSize(width , height); 

     cout << "Dimensions: " << width << height << endl; 
     cout << "Number of frames: " << noF << endl; 
     cout << "Frames per second: " << fps << endl; 


     while(true) 
     { 
      capture >> frame; 
      if(frame.empty()) 
      break; 
      imshow("display", frame); 
      if (waitKey(30)== 'i') 
      break; 
     } 
     //resize_video(); 
    } 

    void resize_video(VideoCapture capture) 
    { 
    cout << "Begin resizing video " << endl; 

    //return 0; 
    } 

回答

0

你想打電話給你的函數內部while循環,它(爲時已晚,在節目)

因此,它可能看起來沒有經過是這樣的:

void resize_video(Mat & image) 
{ 
    // 
    // do your processing 
    // 
    cout << "Begin resizing video " << endl; 
} 

,並調用它像:

while(true) 
    { 
     capture >> frame; 
     if(frame.empty()) 
     break; 

     resize_video(frame); 

     imshow("display", frame); 
     if (waitKey(30)== 'i') 
     break; 
    } 
+0

好的謝謝一堆! – user2035796 2013-03-04 14:33:31