如何在python中使用opencv复制图像区域? [英] How to copy a image region using opencv in python?

查看:432
本文介绍了如何在python中使用opencv复制图像区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 http://iamabhik.wordpress的想法来实现车牌识别软件.com/category/opencv/.

我使用"import cv2"在python中使用opencv实现了板位置.一切正常,现在我需要将印版区域复制到另一个图像中,以对字符进行分割,然后对OCR进行分割(也许使用神经网络).

I implemented the plate location using opencv in python, using "import cv2". It works okay and now I need to copy the plate region to another image to do the segmentation of the characters and then the OCR part (maybe using a neural network).

我发现GetSubRect()函数可以复制或隔离部分图像,但是在python中似乎不可用.有其他选择吗? ROI功能似乎也未实现.

I found the GetSubRect() function to copy or isolate part of the image but it does not appear to be available in python. Is there an alternative? The ROI functions do not seem to be implemented either.

是否有关于opencv的python接口的最新文档?

Is there an up-to-date documentation of the python interface to opencv?

我在Debian Wheezy/sid环境中从svn仓库(修订版7239)编译了opencv.

I compiled opencv from svn repository (revision 7239) on a Debian wheezy/sid environment.

可以随意提出解决此问题的替代方法/想法.

Fell free to suggest alternative methods/ideas to solve this problem.

谢谢.

推荐答案

cv.GetSubRect和ROI函数在Python中均可用,但在旧的import cv模式或import cv2.cv中可用.也就是说,如果您熟悉它们,请使用cv2.cv.GetSubRect()cv2.cv.SetImageROI.

Both cv.GetSubRect and ROI functions are available in Python, but in old import cv mode or import cv2.cv. ie use cv2.cv.GetSubRect() or cv2.cv.SetImageROI if you are familier with them.

另一方面,由于新cv2中的numpy集成,无需这些功能即可轻松设置ROI.

On the other hand, it is simple to set ROI without these functions due to numpy integration in new cv2.

如果(x1,y1)和(x2,y2)是您获得的板的两个相对顶点,则只需使用函数:

If (x1,y1) and (x2,y2) are the two opposite vertices of plate you obtained, then simply use function:

roi = gray[y1:y2, x1:x2]

这就是您的图片投资回报率.

that is your image ROI.

所以选择适合自己的东西.

So choose whatever suit you.

这篇关于如何在python中使用opencv复制图像区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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