我有這個計劃,應該RGB視頻轉換爲灰度:轉換RGB視頻灰度OpenCV中
CvCapture* capture = 0;
capture = cvCreateFileCapture("sample.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("izlaz.avi",CV_FOURCC_DEFAULT,fps,size);
IplImage *grayScaleImage = cvCreateImage(size ,IPL_DEPTH_8U,1);
while((bgr_frame=cvQueryFrame(capture)) != NULL)
{
cvCvtColor(bgr_frame, grayScaleImage, CV_BGR2GRAY);
cvWriteFrame(writer, grayScaleImage);
}
cvReleaseVideoWriter(&writer);
cvReleaseCapture(&capture);
這是情況並非如此。任何人都可以幫助我修改它以正確地工作嗎?謝謝你:)
[http://stackoverflow.com/questions/9289705/convert-video-from-colour-to-grayscale](http://stackoverflow.com/questions/9289705/convert-video-from-顏色到灰度) – 2013-04-28 18:21:55
@AlexSmith我試過這個代碼,但它不起作用。輸出視頻只是旋轉和奇怪:) – user2329672 2013-04-28 18:28:26