python - opencv connectedComponentsWithStats -


first post here!

i installed python-opencv. according python version is:

>>> import cv2 >>> cv2.__version__ '2.4.8' 

my ubuntu version 14.04.

i started python-opencv tutorial suggested code:

img = cv2.imread('opencv_chessboard.png') gray = cv2.cvtcolor(img, cv2.color_bgr2gray)  # find harris corners gray        = np.float32(gray) dst         = cv2.cornerharris(gray, 2, 3, 0.04) dst         = cv2.dilate(dst,none) ret, dst    = cv2.threshold(dst,0.01*dst.max(),255,0) dst         = np.uint8(dst)  # find centroids ret, labels, stats, centroids = cv2.connectedcomponentswithstats(dst)  # define criteria stop , refine corners criteria = (cv2.term_criteria_eps + cv2.term_criteria_max_iter, 100, 0.001) corners = cv2.cornersubpix(gray,np.float32(centroids),(5,5),(-1,-1),criteria)  # draw them res = np.hstack((centroids,corners)) res = np.int0(res) img[res[:,1],res[:,0]]=[0,0,255] img[res[:,3],res[:,2]] = [0,255,0]  cv2.imwrite('subpixel5.png',img) 

when trying execute unaltered code got this:

file "pyopencv_test.py", line 21, in <module>     ret, labels, stats, centroids = cv2.connectedcomponentswithstats(dst) attributeerror: 'module' object has no attribute 'connectedcomponentswithstats' 

a quick search suggests need python-opencv 3 instead of current version 2.4.8. don't know how update opencv version opencv 3 python automatically access it. help? step step instructions appreciated!

'connectedcomponentswithstats' method usable on opencv3.x.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -