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!