Reputation: 191
WHAT I WANT TO DO :
I want to detect rectangles in an image..
WHAT I HAVE DONE SO FAR:
import cv2
import numpy as np
img_path = cv2.imread('/XXX/XXX.TIF',0)
ret,thresh = cv2.threshold(img_path,127,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
x,y,w,h = cv2.boundingRect(cnt)
cv2.rectangle(img_path,(x,y),(x+w,y+h),(0,255,0),2)
rect = cv2.minAreaRect(cnt)
box = cv2.boxPoints(rect)
box = np.int0(box)
im = cv2.drawContours(im,[box],0,(0,0,255),2)
THE ERROR I AM GETTING :
AttributeError: 'module' object has no attribute 'boxPoints'
Concerning this line of code:
box = cv2.boxPoints(rect)
WHAT I THINK : I beleive that it is caused by the version of OpenCV I am using (2.4.9).
Knowing that it is not possible for me now to pass to OpenCV 3.0, how can I make it work using openCV 2.9 and Python 2.7 ?
EDIT & SOLUTION :
So as answered by Surabhi Valma, this could be a solution :
Just add cv2.cv.BoxPoints(rect) instead of cv2.boxPoints(rect)
Upvotes: 0
Views: 4081
Reputation: 108
Just add cv2.cv.BoxPoints(rect)
instead of cv2.boxPoints(rect)
Upvotes: 2
Reputation: 23012
The most recent OpenCV 2 release is 2.4.13.2; there is no 2.9. Anyways, this method was never included in the cv2
library with Python wrappers.
Your choices are to upgrade to OpenCV 3+ or fall back on the (deprecated) cv
module (which is included with older versions of Python OpenCV wrappers) to access the C method directly:
rect = cv2.minAreaRect(cnt)
box = np.int0(cv2.cv.BoxPoints(rect))
cv2.drawContours(im,[box],0,(0,0,255),2)
Upvotes: 1
Reputation: 1502
When I go thru releases could not find 2.9. May be your version is 2.4.9. If you try with 3.x, it may work.
There was an opencv-issue / feature already tracked to closure This function is for sure available in 3.0.0-dev or above, Please try to upgrade and check.
Upvotes: 1