Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't use `cv2.cv.BoxPoints` in OpenCV (Python)?

I am a beginner in OpenCV. I want to make bounding box around my detected marker.

Can you tell me how can I do it with OpenCV (Python)?

I'm using Python 3.6.3 with openCV

box =np.int0(cv2.cv.BoxPoints(marker))

Output:

Error showing cv2.cv2 has no module cv 
like image 782
Muhammad Awais Avatar asked Jan 02 '18 07:01

Muhammad Awais


People also ask

What does cv2 BoxPoints do?

BoxPoints Method. Finds the four vertices of a rotated rect. Useful to draw the rotated rectangle.

Is CV and cv2 same?

cv2 (old interface in old OpenCV versions was named as cv ) is the name that OpenCV developers chose when they created the binding generators. This is kept as the import name to be consistent with different kind of tutorials around the internet.

Is OpenCV-Python and cv2 same?

cv2 is the module import name for opencv-python, "Unofficial pre-built CPU-only OpenCV packages for Python". The traditional OpenCV has many complicated steps involving building the module from scratch, which is unnecessary. I would recommend remaining with the opencv-python library.


1 Answers

cv2.cv.BoxPoints was changed.

For OpenCV 3.x, use cv2.boxPoints instead.


For example:

>> import numpy as np
>> import cv2
>>> cv2.__version__
'3.3.0-dev'

>>> cnt = np.array([[0,0], [1,1], [2,0]])
>>> bbox = cv2.minAreaRect(cnt)
>>> pts = cv2.boxPoints(bbox)
>>> print(pts)
[[  9.99999940e-01   9.99999881e-01]
 [  5.96046448e-08   0.00000000e+00]
 [  9.99999940e-01  -9.99999881e-01]
 [  1.99999976e+00   0.00000000e+00]]
like image 169
Kinght 金 Avatar answered Oct 26 '22 01:10

Kinght 金