裁剪图像,然后添加边框
Crop image and then add border
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));
我有一个问题..我需要为图像添加边框。
但首先我必须裁剪一些内容。
问题是之后添加边框时,我刚刚裁剪的内容又回来了。
是否可以在添加边框之前以某种方式在裁剪后"提交"更改?
您应该使用新Mat
并克隆 ROI。
#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;
}
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 如何在C++中从两个单独的for循环中添加两个数组
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 如何仅为一个函数添加延迟
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 如何将更多文件夹添加到c++include路径
- 如何将元素添加到数组的线程安全函数?
- QT通过C++添加映射QML项目
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 为什么Mat类的两个对象可以在不重载运算符+的情况下添加
- 如何防止clang格式在流运算符调用之间添加换行符<<
- 只能向C++添加一定数量的字符
- Qt和C++:将QLineEdit添加到QTabWidget中
- 在QT中为小部件添加彩色边框的最佳方法是什么
- 向 QPixmap 添加边框
- 如何在opencv中为图像添加边框,边框颜色必须与图像颜色相同
- 添加边框
- 裁剪图像,然后添加边框