Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

How to copy a image region using opencv in python?

I am trying to implement a license plate recognition software using the ideas from http://iamabhik.wordpress.com/category/opencv/.

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).

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.

Is there an up-to-date documentation of the python interface to 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.

Thanks in advance.

question from:https://stackoverflow.com/questions/9084609/how-to-copy-a-image-region-using-opencv-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...