實(shí)現(xiàn)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`;
相關(guān)文章
C語言實(shí)現(xiàn)動態(tài)鏈表的示例代碼
本文主要介紹了C語言實(shí)現(xiàn)動態(tài)鏈表的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05解析內(nèi)存對齊 Data alignment: Straighten up and fly right的詳解
對于所有直接操作內(nèi)存的程序員來說,數(shù)據(jù)對齊都是很重要的問題.數(shù)據(jù)對齊對你的程序的表現(xiàn)甚至能否正常運(yùn)行都會產(chǎn)生影響2013-05-05C++實(shí)現(xiàn)LeetCode(162.求數(shù)組的局部峰值)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(162.求數(shù)組的局部峰值),本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07