我有一個奇怪的問題。如果我使用cvCvtColor圖像上它的工作原理,但如果我想修改圖像,並使用cvCvtColor它有一個錯誤:OpenCV錯誤:輸入參數的大小不匹配
:OpenCV Error: Sizes of input arguments do not match() in cvCvtColor, file /build/buildd-opencv_2.1.0-3-i386-PaiiLK/opencv-2.1.0/src/cv/cvcolor.cpp, line 2208 terminate called after throwing an instance of 'cv::Exception'
,因爲我有作爲輸出應該不會出現這個錯誤
targetImage->width =300, targetImage->height =300 cap->width =300, cap->height =300
即:大小是一樣的。所以這是無稽之談.. 任何可能的解決方案的想法?
相關的代碼是在這裏:
printf("\ntargetImage->width =%d, targetImage->height =%d ",targetImage->width,targetImage->height);
cap = cvCreateImage(cvSize(targetImage->width,targetImage->height), IPL_DEPTH_8U, 1);
cvCvtColor(targetImage, cap, CV_BGR2GRAY);//HERE NO PROBLEM
CvRect xargetRect = cvRect(0,0,300,300);
subImage(targetImage, &showImg, xargetRect);
cap = cvCreateImage(cvSize(targetImage->width,targetImage->height), IPL_DEPTH_8U, 1);
printf("\ntargetImage->width =%d, targetImage->height =%d ",targetImage->width,targetImage->height);
printf("\ncap->width =%d, cap->height =%d ",cap->width,cap->height);
cvCvtColor(targetImage, cap, CV_BGR2GRAY); //HERE THE PROBLEM
感謝
這是子圖像代碼:
/// Modifies an already allocated image header to map
/// a subwindow inside another image.
inline void subImage(IplImage *dest, const IplImage *orig, const CvRect &r) {
dest->width = r.width;
dest->height = r.height;
dest->imageSize = r.height * orig->widthStep;
dest->imageData = orig->imageData + r.y * orig->widthStep + r.x * orig->nChannels;
dest->widthStep = orig->widthStep;
dest->roi = NULL;
dest->nSize = sizeof(IplImage);
dest->depth = orig->depth;
dest->nChannels = orig->nChannels;
dest->dataOrder = IPL_DATA_ORDER_PIXEL;
}
你可以發佈subImage的代碼嗎? – razlebe 2011-03-30 16:41:47
我剛剛看到您的評論,抱歉的延遲;) – marinila 2011-03-30 17:07:58
我認爲你的'widthStep'和'imageSize'都不正確,你將不得不重新計算那些基於新圖像的尺寸,因爲子窗口。 – 2011-03-30 17:39:33