国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C > 正文

OpenCV實(shí)現(xiàn)圖像切割功能

2020-01-26 13:34:30
字體:
供稿:網(wǎng)友

openCV實(shí)現(xiàn)將圖像切成m*n塊,供大家參考,具體內(nèi)容如下

一、代碼部分:

#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;}

二、程序運(yùn)行結(jié)果:

(1)原圖像:

(2)切割后圖像:

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 拜城县| 呼图壁县| 格尔木市| 娱乐| 九江市| 珲春市| 宁明县| 郁南县| 科尔| 昭通市| 赞皇县| 阳高县| 门源| 司法| 杭锦后旗| 通渭县| 南郑县| 峡江县| 多伦县| 花莲县| 昆山市| 壤塘县| 仁化县| 河津市| 西林县| 井陉县| 西乌珠穆沁旗| 东兰县| 宁阳县| 象州县| 乐平市| 大安市| 郎溪县| 大连市| 错那县| 门头沟区| 仙居县| 建水县| 调兵山市| 灵山县| 宿松县|