2012-03-30 77 views
2

我想閱讀視頻文件(.avi或.mov),並使用Opencv檢測運動和邊緣。我可以幫助我使用代碼嗎?我想創建一個GUI,在其中可以選擇視頻文件,那麼我們可以在opencv中執行圖像處理功能嗎?opencv中的視頻文件

+1

兄弟,它不是將變得容易。你仍然需要自己學習基礎知識。 – 2012-03-30 10:50:17

+0

http://www.laganiere.name/opencvCookbook/檢查這本書。簡潔明瞭,將幫助您開始使用OpenCV的 – 2012-03-30 10:51:10

回答

2

這適用於我,我正在使用AVI文件。 使用文件名稱調用視頻,在您的主循環中獲取下一幀並在終止或切換到另一個視頻之前關閉。

IplImage *videoframe; 
int videoFps;  
CvCapture *videoCapture=NULL; 

int video(char *videoFile) { 
    int  key; 
    /* load the AVI file */ 
    videoCapture = cvCaptureFromAVI(videoFile); 
    /* always check */ 
    if(!videoCapture) 
     return 0;  
    /* get fps, needed to set the delay */ 
    videoFps = (int)cvGetCaptureProperty(videoCapture, CV_CAP_PROP_FPS); 
    /* display video */ 
    cvNamedWindow("video", 0); 
} 

void videoNext() { 
     if (! videoCapture) return; 
     videoframe = cvQueryFrame(videoCapture); 
     if(!videoframe) return; 
     cvShowImage("video", videoframe); 
     /* quit if user press 'q' */ 
     int key = cvWaitKey(1000/videoFps); 
} 

void videoShutdown() { 
    /* free memory */ 
    cvReleaseCapture(&videoCapture); 
    cvDestroyWindow("video"); 
    return; 
} 

注:opencv的不支持音頻播放 關於如何使用ffmmpeg與OpenCV中看到audio-output-with-video-processing-with-opencv

1

最短例如從視頻閱讀框架:

cap = cv::VideoCapture("foo.avi"); 
frame = cv::Mat; 
cap >> frame; 
11
+2

你搖滾,你有某種形式的計算機視覺常見問題的數據庫? :P – 2012-07-04 09:32:39

1

你應該看看包含在python文件夾中的opencv樣本。 他們將在這裏找到:OpenCV的\樣本\ python2

在那裏,你會發現許多的OpenCV中的基本和高級功能(在CV2格式)證明。也有很多教程(主要是C++)網站在這裏:http://opencv.itseez.com/doc/tutorials/tutorials.html

讀寫視頻圖像是在這裏:http://opencv.itseez.com/trunk/modules/highgui/doc/reading_and_writing_images_and_video.html

對於來自AVI最初的視頻捕捉:

import cv2 
import cv2.cv as cv 
import numpy as np 

cap = cv2.VideoCapture(filename) 
img = cv2.VideoCapture.read() 
if img: 
    print img.get(cv.CV_CAP_PROP_FRAME_HEIGHT) 
    print type(img) 
# loop through rest of frames reading one at a time 
+0

您確定該代碼嗎?根據文檔,'cv2.VideoCapture.read()'返回一個元組:RetVal,Image。 – LarsH 2013-09-26 13:50:53