CvMat:输入参数的大小不匹配

CvMat: sizes of input arguments do not match

我的代码打开带有路标的图像,检测它们,重新缩放到指定大小,然后将它们放入矩阵中。

vector<vector<Point> > contours; 
vector<Vec4i> hierarchy;    findContours(maski, contours, hierarchy,    CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); 
Mat output1= Mat::zeros(cropImg.rows,cropImg.cols, CV_8UC3);
for(int i = 0; i < contours.size(); i++)
{
    drawContours(output1 , contours, i, Scalar(0,0,255), 1, 8, hierarchy );
    imshow("kontury z findContours", output1);
}

vector<Rect> boundRect( contours.size() );                    

Mat drawing1 = Mat::zeros(cropImg.size(), CV_8UC3 );
Mat image_roi = Mat::zeros(Size(1000,1000), CV_8UC3 );
Mat przeskalowane1;

for( int i = 0; i < contours.size(); i++ )
{ 
    double obwod = arcLength(Mat(contours[i]), true);
    if(obwod>150)
    {                                                    
        boundRect[i] = boundingRect(Mat(contours[i]));
        cout<<"Obwod: "<<obwod<<" Wymiar: "<<boundRect[i].width<<"x"<<boundRect[i].height<<endl;
        if(boundRect[i].height > 50 && boundRect[i].width > 50)
        {
            drawContours( drawing1, contours, i, Scalar(3, 200, 2), CV_FILLED, 8, hierarchy, 0, Point() ); 
            imshow("kontury brane pod uwage przed skalowaniem", drawing1);
            Rect mask(boundRect[i].x, boundRect[i].y, boundRect[i].width, boundRect[i].height);
            //cout << "#" << i << " rectangle x:" << mask.x << " y:" << mask.y << " " << mask.width << "x" << mask.height << endl;
            Mat image_roi = drawing1(mask);
            double wys = boundRect[i].height;
            double szer = boundRect[i].width;    
            double skala1 = wys/128;
            double y = wys/skala1;
            double x = szer/skala1;
            resize(image_roi, image_roi, Size(x,y));
            przeskalowane1.push_back(image_roi);


        } // ERROR in this line
    }
} 
if(przeskalowane1.cols > 0)
{   
    cout<<"Przeskalowane: "<<przeskalowane1.cols<<"x"<<przeskalowane1.rows<<endl;
    imshow("Przeskalowane", przeskalowane1);
    cvMoveWindow("Przeskalowane", 1128, 0);
    cvtColor(przeskalowane1, przeskalowane1, CV_BGR2GRAY);
} 

当只找到一个道路标志或图像中发现的标志与指定尺寸非常相似时,一切正常。如果找到的标志大小不同,则会出现以下错误:

Error: Sizes of input arguments do not match <> in unknown function, file......\modules\core\src\matrix.cpp, line 598"

matrix中有这些标志对我来说非常重要。

cv::Mat::push_back 方法的帮助页面说:

The methods add one or more elements to the bottom of the matrix. They emulate the corresponding method of the STL vector class. When elem is Mat , its type and the number of columns must be the same as in the container matrix.

因此,为了将多个图像添加到 przeskalowane1,您需要将它们重新调整为相同的宽度(而不是高度)。

Mat image_roi = drawing1(mask);
double wys = boundRect[i].height;
double szer = boundRect[i].width;    
double x = 128;
double skala1 = szer/x;
double y = wys/skala1;
resize(image_roi, image_roi, Size(x, y));