使用openCV裁剪图像的区域(java) [英] Crop image's area with openCV (java)
本文介绍了使用openCV裁剪图像的区域(java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用openCv在我的图像中检测到了一个区域(矩形),并且我已经用它们的坐标存储了4个矩形点。
I have detected a area (rectangle) in my image with openCv and i have stored the 4 points of rectangle with their coordinates.
我想裁剪原始图像此区域中的图片。
I would to crop the original image in this area.
我有:
Mat image_original;
Point p1,p2,p3,p4;
Mat image_output;
我是怎么做到的?
谢谢!
How i do this? Thanks!
推荐答案
Mat image_original;
Point p1,p2,p3,p4;
Rect rectCrop = new Rect(p1.x, p1.y , (p4.x-p1.x+1), (p4.y-p1.y+1));
Mat image_output= image_original.submat(rectCrop);
这是根据您的要求裁剪图片的代码。我假设点p1
是裁剪矩形的左上角,点p4
是裁剪矩形的右下角,因为你没有提到关于他们职位的任何事情。
This is the code for croping image as per your requirement.I assumed that Point p1
is the top-left corner of the crop rectangle and Point p4
is the bottom-right corner of the crop rectangle as you have not mentioned anything about their positions.
这篇关于使用openCV裁剪图像的区域(java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文