图像切割实例
        【摘要】 
                    
                        
                    
                    #include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/...
    
    
    
    #include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>
#include <iostream>
using namespace std;
using namespace cv;
#define m_count 8
cv::Mat img;
cv::Rect m_select;
int main()
{
	img = imread("E:\\11.jpg",3);
	namedWindow("原图", WINDOW_NORMAL);
	cvResizeWindow("原图",img.cols/3 , img.rows/3);
	imshow("原图", img);
	int lens = img.rows;
	int width = img.cols;
	string m_path_name;
	string m_file_name;
	char first[3] = {0};
	char second[3] = {0};
	for (int i = 0; i < m_count; ++i)
	{
		m_file_name = "";
		m_path_name = "";
		_itoa_s(i, first, 10);
		m_path_name = "E:\\photo\\S5\\";
		for (int j = 0; j < m_count; ++j)
		{
			m_file_name = "";
			_itoa_s(j, second, 10);
			int a = j * width / m_count;
			int b = i* lens / m_count;
			//int c = (j + 1) * width / m_count;
			//int d = (i + 1) * lens / m_count;
			int c = width / m_count;
			int d =  lens / m_count;
			m_select = Rect(a,b ,c ,d );
			Mat ROI = img(m_select);
			ROI = img(m_select);
			m_file_name += first;
			m_file_name += second;
			m_path_name = "E:\\photo\\S5\\";
			m_path_name += m_file_name;
			m_path_name += ".jpg";
			imshow(m_file_name.c_str(), ROI);
			imwrite(m_path_name.c_str(), ROI);
		}
	}
	
#if 0
	m_select = Rect(0, 0, 288*1, 216*1);
	Mat ROI = img(m_select);
	ROI = img(m_select);
	imshow("剪裁图", ROI);
	imwrite("E\\:0011.jpg", ROI);
	m_select = Rect(0, 0, 288 * 2, 216 * 2);
	ROI = img(m_select);
	imshow("剪裁图1", ROI);
	imwrite("E:\\0012.jpg", ROI);
#endif
	waitKey(0);
	return 0;
}
  
 - 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
文章来源: blog.csdn.net,作者:IM-STONE,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/doubleintfloat/article/details/121414217
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)