我是opencv的新手。我试图将灰度放入更大的黑色图像,我的代码在下面。
Mat imageGray, padded;
imageGray= imread("/home/nick/workspace/trial/src/imageGray.bmp", CV_LOAD_IMAGE_GRAYSCALE);
int padding = 20;
padded.create(imageGray.rows + 2*padding, imageGray.cols + 2*padding , imageGray.type());
padded.setTo(cv::Scalar::all(0));
imageGray.copyTo(padded(Rect(padding, padding, imageGray.rows, imageGray.cols)));
imshow("Trial",padded);
我收到断言错误
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows)
答案 0 :(得分:2)
创建Rect的语法是(x,y,WIDTH,HEIGHT)
,请尝试:
imageGray.copyTo(padded(Rect(padding, padding, imageGray.cols, imageGray.rows)));
^ ^