在调用seamlessClone()的时候报错:error: (-215: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 in function 'Mat'
出错代码:
seamlessClone(src, dst, mask, center, output, NORMAL_CLONE);
报错原因:可以看seamlessClone源码(opencv/modules/photo/src/seamless_cloning.cpp),在执行seamlessClone的时候,会先求mask内物体的boundingRect,然后会把这个最小框矩形复制到dst上,矩形中心对齐center,这个过程中可能矩形会超出dst的边界范围,就会报上面的roi边界错误
避免报错可以加判断:
Rect roi_s = boundingRect(mask);
Rect roi_d(center.x - roi_s.width / 2, center.y - roi_s.height / 2, roi_