Mat img = imread(input);
// Crop a part out of the image
img = img(Rect(x, y, width, height));
// Add a white border around the cropped image
int border = 100;
copyMakeBorder(img, img, border, border, border, border, BORDER_CONSTANT, Scalar(0, 255, 255));
我遇到了问题..我需要为图片添加边框..
但首先我必须裁掉一些内容..
问题是,之后添加边框时我刚裁剪的内容会重新出现..
有可能以某种方式提交"提交"在添加边框之前进行裁剪后的更改?
答案 0 :(得分:3)
您应该使用新的Mat
并克隆投资回报率。
#include "opencv2/highgui.hpp"
using namespace cv;
int main(int argc, char* argv[])
{
Mat img = imread(argv[1]);
// Crop a part out of the image
Mat cropped = img(Rect(10, 10, 100, 100)).clone();
// Add a white border around the cropped image
int border = 100;
copyMakeBorder(cropped, cropped, border, border, border, border, BORDER_CONSTANT, Scalar(0, 255, 255));
imshow("cropped", cropped);
waitKey();
return 0;
}