實(shí)現(xiàn)opencv圖像裁剪分屏顯示示例
使用OPENCV圖像處理庫(kù),將圖片裁剪分屏顯示
//#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)動(dòng)態(tài)鏈表的示例代碼
本文主要介紹了C語言實(shí)現(xiàn)動(dòng)態(tài)鏈表的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-05-05
解析內(nèi)存對(duì)齊 Data alignment: Straighten up and fly right的詳解
對(duì)于所有直接操作內(nèi)存的程序員來說,數(shù)據(jù)對(duì)齊都是很重要的問題.數(shù)據(jù)對(duì)齊對(duì)你的程序的表現(xiàn)甚至能否正常運(yùn)行都會(huì)產(chǎn)生影響2013-05-05
C++實(shí)現(xiàn)LeetCode(162.求數(shù)組的局部峰值)
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode(162.求數(shù)組的局部峰值),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
C語言中通用工具庫(kù)stdlib.h的一些常用函數(shù)
這篇文章主要給大家介紹了關(guān)于C語言中通用工具庫(kù)stdlib.h的一些常用函數(shù),stdlib.h頭文件包含了許多C標(biāo)準(zhǔn)庫(kù)函數(shù)的原型聲明和宏定義,這些函數(shù)主要與動(dòng)態(tài)內(nèi)存分配、隨機(jī)數(shù)生成、進(jìn)程控制、字符串轉(zhuǎn)換等相關(guān),需要的朋友可以參考下2024-01-01

