错误消息:
(-215)0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in 函数cv :: Mat :: Mat
这是我的代码
Rect eye_rec(200, 300, 168, 168);
Point hand_pos(100, 100);
Mat des, mask = (cv::Mat::zeros(hand.size(), CV_8UC1));
mask(eye_rec).setTo(255);
seamlessClone(eye,hand, mask,hand_pos,des,NORMAL_CLONE);
imshow("clone", des);
waitKey(0);
虽然我无法真正理解错误消息。
答案 0 :(得分:1)
您的错误代码通常意味着您要裁剪的ROI超出了源矩阵的范围-例如源矩阵的尺寸为480x480,并且您要从位置(200、200)(其中300 + 200> 480)中裁剪出尺寸为300x300的ROI。
根据docs
src – Input 8-bit 3-channel image.
dst – Input 8-bit 3-channel image.
mask – Input 8-bit 1 or 3-channel image.
result – Output image with the same size and type as dst.
src,dst和结果应为CV_8UC3
类型-三个通道图像,而您仅传递一个通道图像CV_8UC1
,这很可能在这里引起错误。
解决方案是使用3通道(彩色)图像或接受1通道图像的其他操作。
答案 1 :(得分:0)
hand.convertTo(hand, CV_8UC3);
eye.convertTo(eye, CV_8UC3);
Point hand_pos(hand.cols/2,hand.rows/2); //this code should put the eye image in the middle of the hand image
Mat des, mask = (cv::Mat::zeros(eye.size(), CV_8UC3));
des.convertTo(des, CV_8UC3);
mask = 255 * Mat::ones(eye.rows, eye.cols, eye.depth()); // creating a mask of all white from the eye image
seamlessClone(eye,hand, mask,hand_pos,des,NORMAL_CLONE);
imshow("normalclone", des); waitKey(0);
seamlessClone(eye,hand,mask,hand_pos,des, MIXED_CLONE);
imshow("mixclone",des); waitKey(0)
waitKey(0);
此更改对我有所帮助,希望对其他人也有所帮助,谢谢@FilipKočica