openCV实现图像切割
来源:互联网 发布:nginx强制别名访问 编辑:程序博客网 时间:2024/05/21 17:07
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 patchvoid 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]="\0"; 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)原图像:
(2)切割后图像:
阅读全文
0 0
- openCV实现图像切割
- python,opencv切割图像操作
- 【OpenCV】复制、切割出图像ROI区域
- matlab实现对图像的切割
- 医疗图像切割FCN的Keras实现
- OpenCV实现对图片的切割
- 学习opencv之(六)-图像切割,使用ROI
- 学习opencv之(六)-图像切割,使用ROI
- 学习opencv之(六)-图像切割,使用ROI
- opencv实现图像旋转
- opencv实现图像旋转
- Opencv实现图像旋转
- OpenCV实现图像旋转
- opencv实现图像缩放
- OpenCV实现图像缩放
- opencv实现图像旋转
- opencv实现图像旋转
- opencv实现图像旋转
- 桥接、NAT和host-only间的差别
- 文章标题
- tensorflow73 使用RNN生成古诗和藏头诗
- POI之读写Excel-yellowcong
- java基础--1.基础-2.java简介
- openCV实现图像切割
- Type JAX-RS (REST Web Services) 2.0 requires Java 1.6 or newer
- jsp的response对象
- spring基础
- 好久没敲代码了(强行补上今天的博客。。。)
- 学习struts2框架
- userbean 那一节的代码 待定啊
- Python3播放MP3(支持MAC,WIN,LINUX)
- C++:动态分配内存(malloc,free)