OpenCV实现图像切割功能
2019-01-15 00:03
651 查看
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]="\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)切割后图像:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- 基于opencv的相机之图像修补功能实现(十二)
- 使用opencv实现图像局部放大功能
- 本图片处理类功能非常之强大可以实现几乎所有WEB开发中对图像的处理功能都集成了,包括有缩放图像、切割图像、图像类型转换、彩色转黑白、文字水印、图片水印等功能
- openCV实现图像切割
- Python使用matplotlib实现的图像读取、切割裁剪功能示例
- opencv 截取轮廓中的图像——实现PS中的抠图功能 Opencv extract area circled by contour
- 用OpenCV实现Photoshop曲线功能的'在图像中取样设置黑场'
- opencv 截取轮廓中的图像——实现PS中的抠图功能 Opencv extract area circled by contour
- opencv实现图像的拼接功能
- opencv 截取轮廓中的图像——实现PS中的抠图功能 Opencv extract area circled by contour
- opencv 截取轮廓中的图像——实现PS中的抠图功能
- 双目测距与三维重建的OpenCV实现问题集锦(一)图像获取与单目定标
- 运用opencv 读取BMP图像像素信息 代码及实现
- OpenCV下实现单窗口显示多幅图像的源码!
- 学习opencv之(六)-图像切割,使用ROI
- 【图像处理】基于OpenCV底层实现的滤波
- OpenCV实现fft2、ifft2变换和matlab中psf2otf()函数的功能
- PCL+OpenCV+WebCam实现模拟深度图像实时点云数据采集
- 3、opencv 图像显示功能
- 基于GraphCuts图割算法的图像分割----OpenCV代码与实现