I am trying to implement contours using the following code..
im = cv2.imread(\'C:\\Users\\Prashant\\Desktop\\T.jpg\')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2
This should help:
image, contours, hierarchy = cv2.findContours(thresh.copy(),
cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
Depending on the OpenCV version, cv2.findContours()
has varying return signatures. In OpenCV 3.4.X, cv2.findContours() returns 3 items. In OpenCV 2.X and 4.1.X, cv2.findContours() returns 2 items
You can easily obtain the contours regardless of the version like this:
cnts = cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
As per the Current Opencv Versions cv2.findContours returns 2 Values and that is Contours and heirachy. Contours can be explained simply as a curve joining all the continuous points (along the boundary), having same color or intensity. The contours are a useful tool for shape analysis and object detection and recognition.