opencv裁剪图片c++
时间: 2023-09-12 11:11:57 浏览: 220
opencv 图像切割
3星 · 编辑精心推荐
要使用OpenCV裁剪图片,你可以使用以下代码示例中的任一方法:
1.
```c++
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
// 读取图片
Mat img = imread("test.jpg");
// 裁剪图片
Mat cropped_image = img(Range(400,1200), Range(350,700));
// 显示原始图片和裁剪后的图片
imshow("原始图片", img);
imshow("裁剪后的图片", cropped_image);
// 保存裁剪后的图片
imwrite("裁剪后的图片.jpg", cropped_image);
// 等待按键退出
waitKey(0);
// 销毁窗口
destroyAllWindows();
return 0;
}
```
2.
```c++
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main() {
// 读取图片
cv::Mat img;
cv::Rect m_select;
img = imread("F://Visual Studio 2015//ROItest01//ROItest01//01.jpg");
// 显示原始图片
imshow("原图", img);
// 裁剪图片
m_select = Rect(0,0,111,217);
Mat ROI = img(m_select);
// 显示裁剪后的图片
#### 引用[.reference_title]
- *1* [opencv图像裁剪(C++)](https://blog.csdn.net/weixin_44487231/article/details/112849701)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [OpenCV入门(C++/Python)-使用OpenCV裁剪图像(四)](https://blog.csdn.net/weixin_42010722/article/details/128183509)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文