我有以下的源代碼來檢測BLOB和我使用的MS 2008,OpenVC 2.1無法創建/保存輸出的AVI文件在OpenCV中
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
/*You may change the values of the sthreshold and hlower and hupper to get different results....*/
const int sthreshold=210;
const double hlower=178;
const double hupper=3;
int main(int argc, char* argv[]) {
int i,j,k;//for iterations
int height,width,step,channels;/*HSV means the frame after color conversion*/
int heightmono,widthmono,stepmono,channelsmono;/*mono means the frame which has the monochrome image*/
const char string1[]="monoimg.avi";/*This is the name of the video which would be the outcome of the blob detection program..*/
uchar *data,*datamono;
i=j=k=0;
IplImage *frame = 0;
int key = 0;/*Initializing the capture from the video...*/
CvCapture* capture = cvCreateFileCapture("partofvideo3.avi");
double fps = cvGetCaptureProperty (/*getting the capture properties......the frame rate..*/
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(string1, CV_FOURCC('D', 'I', 'V', 'X') ,fps,size) ;
if(writer !=NULL)
printf("Loaded\n");
else
printf("Not Loaded\n");
/* always check */
if (!capture) {
fprintf (stderr, "Cannot open video file!\n");
return(1);
}
height = frame->height;
width = frame->width;
step = frame->widthStep;
channels = frame->nChannels;
data = (uchar *)frame->imageData;
cvNamedWindow("monoimage", CV_WINDOW_AUTOSIZE);
cvNamedWindow("original frame", CV_WINDOW_AUTOSIZE);
for (;;) {/*keep looping till we are out of frames...*/
if (!cvGrabFrame(capture)) {
break;
}
frame = cvRetrieveFrame(capture);
IplImage *colimgbot = cvCreateImage(cvGetSize(frame), 8, 3);
IplImage *monoimgbot = cvCreateImage(cvGetSize(frame), 8, 1);
cvCvtColor(frame,frame,CV_RGB2HSV);
for(i=0;i< (height);i++)
{
for(j=0;j<(width);j++)
{
if((data[(height-i)*step+j*channels]<=hlower) && (data[(height-i)*step+j*channels]>=hupper))
{
if((data[(height-i)*step+j*(channels)+1])>sthreshold)
/*"height-i" because if we use only "i" we were getting vertically inverted result...hence reinverting the same
would do the required....*/
datamono[i*stepmono+j*channelsmono]=255;
else
datamono[i*stepmono+j*channelsmono]=0;}
else datamono[i*stepmono+j*channelsmono]=0;
}
}
cvErode(monoimgbot,monoimgbot,0,14);
cvDilate(monoimgbot,monoimgbot,0,15);
cvWriteFrame(writer, monoimgbot);
cvShowImage("original frame", frame);
cvShowImage("monoimage", monoimgbot);
if((cvWaitKey(10) & 255) == 27) break;
}
cvReleaseVideoWriter(&writer) ;
cvDestroyWindow("monoimage");
cvReleaseCapture(&capture);
return 0;
}
當我運行程序我得到以下運行時錯誤 當下面的行遇到
CvVideoWriter* writer=cvCreateVideoWriter(string1, CV_FOURCC(‘D’,'I’,'V’,'X’),fps,size) ;
輸出#0,AVI,爲 'monoimg.avi': 流#0.0:視頻mgeg4,YUV420P,q = 2-31,90K TBN [MPEG4 @ 0x37e5c0]幀率不設置爲 OpenCV錯誤:錯誤參數(無法打開的編解碼器「MPEG 4':未指定的錯誤)的未知函數,文件 C:\用戶\ VP \ OCV \的OpenCV \ SRC \ highgui \ cvcap_ffmpeg.cpp,線1306
我已經安裝了DIVX解碼包,我曾試圖在同一時間我試圖FLV1也由30手動設置fps的,但這次我收到以下錯誤 輸出#0,AVI,以「monoimg.avi」: 流#0.0:視頻:flv,yuv420p,q = 2-31,90k tbn,50 tbc 編譯器未對齊堆棧變量。 Libavcodec已被編譯錯誤 並可能非常緩慢或崩潰。這不是libavcodec, 中的錯誤,而是編譯器中的錯誤。您可以嘗試使用gcc> = 4.2進行重新編譯。 不要向FFmpeg開發人員報告崩潰。 圖片大小無效(爲0x0) 最後一條消息重複2次 AVI @ 0x37bfd0]尺寸沒有設置 – Hunt 2010-07-25 17:31:55
設置fps至30手動爲我工作在OSX opencv2.2和編解碼器支持MPEG-4 – PhoebeB 2010-12-29 11:29:13
請你幫我回答這個問題問題http://stackoverflow.com/questions/9063746/opencv-cv-fourccf-lv-1-not-working – Wazzzy 2012-01-31 13:58:39