im = cv.imread('test.jpg') imgray = cv.cvtColor(im, cv.COLOR_BGR2GRAY) ret, thresh = cv.threshold(imgray, 127, 255, 0) contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE) cv.drawContours(img, [CONTOURS], 0, (0,255,0), 3)
Here is what the above code is Doing:
1. Read the image.
2. Convert it to grayscale.
3. Apply thresholding.
4. Find contours.
5. Draw the contours.