采用opencv对图像进行分割

来源:互联网 发布:天津毕业生就业数据 编辑:程序博客网 时间:2024/05/21 17:32

imread()函数在highgui.cpp里面,Rect()函数在core.hpp,所以必须包含这两个头文件。

这里采用Rect()函数对原图像进行截图:


#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>

using namespace cv;

int main(int argc, char** argv)

{
Mat src_img = imread("./face_2.jpg");
imshow("src_IMG", src_img);
int m = src_img.cols;//宽
int n = src_img.rows;//高


Mat dst_Img1, dst_Img2, dst_Img3;
dst_Img1 = src_img(Rect(0, 0, n, n/3));
dst_Img2 = src_img(Rect(0, n/3, m, n/3));
dst_Img3 = src_img(Rect(0, n*2 / 3, m, n/3));

imshow("dst_1", dst_Img1);
imshow("dst_2", dst_Img2);
imshow("dst_3", dst_Img3);
waitKey(0);
return 0;
}
1 0