2012-02-15 73 views
0

我想閱讀彩色視頻並將輸出視爲灰度視頻。下面是我有的代碼,它運行得很好,但輸出是我的相同顏色的視頻。任何人都可以找出問題嗎?將視頻從彩色轉換爲灰度

//Convert a video to grayscale 
//argv[1]: input video file 
//argv[2]: name of new output file 

#include "cv.h" 
#include "highgui.h" 

int main(int argc, char* argv) { 
CvCapture* capture = cvCaptureFromAVI("C:\\walking\\lady walking.avi"); 
if(!capture){ 
    return -1; 
} 

IplImage *bgr_frame=cvQueryFrame(capture);//Init the video read 
double fps = cvGetCaptureProperty (
    capture, 
    CV_CAP_PROP_FPS 
    ); 

CvSize size = cvSize(
    (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH), 
    (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT) 
    ); 

CvVideoWriter *writer = cvCreateVideoWriter(
    "Output video",//filename for new file 
    CV_FOURCC('M','J','P','G'),//video codec to compress video stream 
    fps, 
    size 
    ); 
IplImage* logpolar_frame = cvCreateImage(
    size, 
    IPL_DEPTH_8U, 
    3 
    ); 
while((bgr_frame=cvQueryFrame(capture)) != NULL) { 
    cvLogPolar(bgr_frame, logpolar_frame, 
     cvPoint2D32f(bgr_frame->width/2, 
     bgr_frame->height/2), 
     40, 
     CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS); 
    cvWriteFrame(writer, logpolar_frame); 
} 
cvReleaseVideoWriter(&writer); 
cvReleaseImage(&logpolar_frame); 
cvReleaseCapture(&capture); 

IplImage*image; 
CvCapture*recorder = cvCaptureFromAVI("C:\\walking\\lady walking.avi"); 
cvNamedWindow("Output video",1); 
while(1) { 
    image=cvQueryFrame(recorder); 
    if(image==NULL) 
    { 
     break; 
    } 
    cvShowImage("Output video",image); 
    char c= cvWaitKey(30); 
    if(c==27) 
    { 
     break; 
    } 

} 
cvReleaseCapture(&capture); 
cvDestroyWindow("Output video"); 
return 0; 
} 

回答

2

看起來對我來說,就好像你的問題很簡單,你在「輸出視頻」窗口中顯示的視頻其實是你的「小姐walking.avi」輸入視頻,沒有視頻輸出結果。

+0

哇,我沒有意識到這一點。非常感謝 – 2012-02-15 08:23:26

相關問題