欢迎来到入门教程网!

C语言

当前位置:主页 > 软件编程 > C语言 >

实现opencv图像裁剪分屏显示示例

来源:本站原创|时间:2020-01-10|栏目:C语言|点击:

使用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`;

上一篇:c语言定时器示例分享

栏    目:C语言

下一篇:c++中引用和指针的区别和联系

本文标题:实现opencv图像裁剪分屏显示示例

本文地址:https://www.xiuzhanwang.com/a1/Cyuyan/3683.html

网页制作CMS教程网络编程软件编程脚本语言数据库服务器

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:835971066 | 邮箱:835971066#qq.com(#换成@)

Copyright © 2002-2020 脚本教程网 版权所有