Opencv在python中裁剪出平行四边形图像 [英] Opencv crop a parallelogram image in python

查看:3085
本文介绍了Opencv在python中裁剪出平行四边形图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Python和Opencv。我现在正在进行车牌识别项目。我现在可以识别这样的盘子:

I am using Python and Opencv. I am now doing a license-plate recognition project. I can now recognize the plate like this:

我得到一个像这样的数组:

And I got an "array" like this :

[[[542 796]]

 [[965 883]]

 [[547 884]]

 [[966 795]]]

问题是:如何用这些坐标裁剪出边界区域?

The problem is: How can I crop out the bound region with these coordinates?

因为四个corrdinates是置换,它不是一个矩形,所以我不知道如何裁剪出来。

As the four corrdinates are permuted and it is not a rectangle, so I dont know how I can crop this out.

推荐答案

你可以裁剪内部矩形或外边界矩形。让四个坐标为: -

You can crop the inner rectangle or outer bounding rectangle. Let the four co-ordinates be:-

(x1,y1),(x2,y2)

(x1,y1), (x2,y2)

(x3,y3),(x4,y4)

(x3,y3), (x4,y4)

假设您对外边界矩形感兴趣,因此没有字母被分割,您可以使用下面的方法进行简单裁剪投资回报率。

Assuming, you are interested in outer bounding rectangle, so that no letter is segmented, you can do simple cropping using below ROI.

int topLeftX = min(x1,x3);
int topLeftY = min(y1, y2);
int width = max(x2, x4) - topLeftX;
int height = max(y3, y4) - topLeftY;
cv::Rect outerRoi(topLeftX, topLeftY, width, height);
cv::Mat roiImage = image(outerRoi); //Note that this will not create a deep copy

如果对最适合梯形的矩形感兴趣在里面,你应该用最大值交换min,反之亦然。

If interested in largest rectangle which fits the trapezium from inside, you should swap min with max and vice-versa.

如果你想要像roi这样的梯形,你应该创建一个蒙版图像。有关更多说明,请参阅复制非矩形roi opencv

If you want a trapezium like roi, you should create a mask image. For further directions,, see copying non-rectangular roi opencv

这篇关于Opencv在python中裁剪出平行四边形图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆