opencv 截取图片一部分,在OpenCV中下移图像的一部分(剪切和粘贴)

I have a part of image and I want to shift it down say by 25 pixels like shown in the picture.

f0336fe63294c92345759f492ebd1811.png

I have mask of the region I want to shift down. The total image size should not change. So, the operation is cut and paste. The region where I cut can be filled with 0 or 255.

Platform is C++

解决方案

Create two sub-images: the first sub1 around the pattern you want to move and the second sub2, same size than sub1, around the destination. Copy sub1 into sub2 then fill sub1 with black or white color. You need obviously to use the mask cropped at the same size than the two sub-images.

This is pseudo-code, to illustrate the idea:

cv::Mat YourImage;

cv::Mat YourMask;

std::vector<:point> YourPatternContour;

cv::Rect sub1ROI = cv::boundingRect(YourPatternContour);

cv::Mat sub1 = YourImage(sub1ROI);

cv::Mat mask = YourMask(sub1ROI);

cv::Rect sub2ROI = sub1ROI + cv::Point(25,25);

cv::Mat sub2 = YourImage(sub2ROI);

sub1.copyTo(sub2, mask);

sub1.set(0, mask);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值