没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
OpenCV实现图像切割功能实现图像切割功能
主要为大家详细介绍了OpenCV实现图像切割功能,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
openCV实现将图像切成m*n块,供大家参考,具体内容如下
一、代码部分:一、代码部分:
#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
#include<string>
#include<sstream>
using namespace std;
using namespace cv;
//Cut an image into m*n patch
void Cut_img(Mat src_img, int m, int n, vector<Mat> ceil_img)
{
int t = m * n;
int height = src_img.rows;
int width = src_img.cols;
int ceil_height = height / m;
int ceil_width = width / n;
Mat roi_img;
//String concatenation
ostringstream oss;
string str, str1, str2;
Point p1, p2;
for (int i = 0; i<m; i++)
{
for (int j = 0; j<n; j++)
{
Rect rect(j*ceil_width, i*ceil_height, ceil_width, ceil_height);
src_img(rect).copyTo(roi_img);
ceil_img.push_back(roi_img);
oss << i;
str1 = oss.str();
oss.str("");
oss << j;
str2 = oss.str();
oss.str("");
str = "roi_img_" + str1 + "_" + str2;
imshow(str, roi_img);
IplImage *ipl_roi_img=&IplImage(roi_img);
//save processed img
char tmp[100]=" ";
sprintf(tmp,"..\post_img\71253_%d_%d.jpg",i,j);
cvSaveImage(tmp,ipl_roi_img);
}
}
}
int _tmain(int argc, _TCHAR* argv[])
{
char *img_name_path="..\image\71253.jpg";
Mat img = imread(img_name_path,1);
imshow("src_img", img);
waitKey(0);
int m = 2;
int n = 2;
vector<Mat> ceil_img ;
Cut_img(img, m, n, ceil_img);
cvWaitKey(0);
return 0;
}
二、程序运行结果:二、程序运行结果:
(1)原图像:
资源评论
weixin_38618784
- 粉丝: 11
- 资源: 884
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功