完成opencv圖象裁剪分屏顯示示例。本站提示廣大學習愛好者:(完成opencv圖象裁剪分屏顯示示例)文章只能為提供參考,不一定能成為您想要的結果。以下是完成opencv圖象裁剪分屏顯示示例正文
應用OPENCV圖象處置庫,將圖片裁剪分屏顯示
//#include "stdafx.h"
#include <opencv2/opencv.hpp>
//#include <opencv2/imgproc/imgproc.hpp>
//#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <vector>
using namespace std;
using namespace cv;
//剪切圖片為m * n 塊
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,tmp_img;
Point p1,p2;
for(int i = 0;i<m;i++)
for(int j = 0;j<n;j++){
//p1 =
Rect rect(i+j*ceil_width,j+i*ceil_height,ceil_width,ceil_height);
src_img(rect).copyTo(roi_img);
ceil_img.push_back(roi_img);
imshow("roi_img",roi_img);
//rectangle(i+j*ceil_width,j+i*ceil_height,);
}
waitKey(0);
}
void show_images(Vector<Mat> imgs,int n){
//do something
}
int main()
{
Mat img = imread("airplane.jpg",1);
imshow("src img",img);
int m = 3;
int n = 3;
Vector<Mat> ceil_img = m*n;
Cut_img(img,m,n,ceil_img);
waitKey();
return 0;
}
編譯敕令: g++ -ggdb `pkg-config --cflags opencv` -o ImageTake ImageTake.cpp `pkg-config --libs opencv`;