OpenCV for Python Learning (a drawing function)

Source: Internet
Author: User

My study notes are mainly recorded in the study opencv-python-tutorials the book of the Notes

This evening learn how OpenCV for Python plots, mainly using these functions (these functions can be in: http://docs.opencv.org/modules/core/doc/drawing_functions.html Found):

Start by copying the code from the book, the code is as follows:

Import NumPy as NP Import  = Np.zeros (512,512,3= Cv2.line (IMG, (), (510,510), (255,0,0), 5= Cv2.rectangle (IMG, ( 200,100), (100,200), (0,255,0), 3= Cv2.circle (img, (100,100),, (0,0,255),-1= Cv2.ellipse (IMG, 256 (100,50), 0, 0, 255, 1) cv2.imshow ('hello', img) cv2.waitkey ( 0) cv2.destroyallwindows ()

Always running to Cv2.imshow () This error, error code:

Error: ( -215) size.width>0 && size.height>0 in function imshow

The general meaning is that the size of the IMG must be greater than 0, but that's what the book says?

Recall in C with OpenCV drawing, directly call the drawing function, seemingly do not need to add return value, so I try to remove the return value, each time is directly on the IMG drawing, no return value

Cv2.line (IMG, (), (510,510), (255,0,0), 5)Cv2.rectangle (IMG, (200,100), (100,200), (0,255,0), 3) Cv2.circle (IMG, (100,100), (0,0,255), 1)cv2.ellipse (IMG, (256,256), (100,50), 0, 0, 180, 255,-1)

Yes, sure.

Think about it, if the return value is assigned to IMG, then IMG should indicate whether the drawing is a successful flag, not the IMG itself.

Internet search, in: Http://docs.opencv.org/modules/core/doc/drawing_functions.html found the official website comment, said the return value of these functions is none (no wonder can't imshow)

This solves the problem and starts drawing the polygon

Add the following code:

pts = Np.array ([[10,5], [34,23],[231,54], [76,98= Pts.reshape (( -1,1,2)) Cv2.polylines (IMG, [pts], True, (0 ,255,255))

Error again.

Error: ( -215) P.checkvector (2, cv_32s) >= 0 in function polylines

Google's, http://stackoverflow.com/questions/11270250/ The What-does-the-python-interface-to-opencv2-fillpoly-want-as-input workaround is as follows:

Change the last line to the following form:

Cv2.polylines (IMG, Np.array ([pts], Np.int32), True, (0,255,255))

Convert [pts] to the Numpy.array type of 32int, just fine.

As for the problem here, we understand it, I can't say it clearly.

On the first day of today, there are not many hard goods. Come on!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.