With the following test input: test.png : and my code: import cv2 import numpy as np # import matplotlib.pyplot as plt import imutils print("Your OpenCV version: {}".format(cv2.__version__)) print("Are you using OpenCV 2.X? {}".format(imutils.is_cv2())) print("Are you using OpenCV 3.X? {}".format(imutils.is_cv3())) print("Are you using OpenCV 4.X? {}".format(imutils.is_cv4())) image_path = 'test.png' image = cv2.imread(image_path) cv2.imshow('input', image) cv2.waitKey(0) gray_image = cv2.cvtColor(image.copy(), cv2.COLOR_BGR2GRAY) gray_image = cv2.GaussianBlur(gray_image, (5, 5), 0) cv2.imshow('gray_image', gray_image) cv2.waitKey(0) image_edged = cv2.Canny(gray_image, 50, 100) cv2.imshow('image_edged', image_edged) cv2.waitKey(0) print('image_edged.shape : ', image_edged.shape) cnts = cv2.findContours(image_edged.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) cnts = cnts[1] if imutils.is_cv2() else cnts[0] #### #### STO USANDO CV4 --→ https://stackoverflow.com/questions/57980005/having-the-following-error-message-error-215assertion-failed-npoints-0 cntso = sorted(cnts, key=cv2.contourArea, reverse=True) for n,i in enumerate(cntso) : print(n, ' ---> ', cv2.contourArea(i),'...........', type(i), i.shape, i.ndim,) #from 6. Mask and Pixel Points https://docs.opencv.org/4.x/d1/d32/tutorial_py_contour_properties.html # mask = np.zeros(image_edged.shape,np.uint8) mask = np.zeros(gray_image.shape) cv2.drawContours(mask, , -1 , 255 , 1) # pixelpoints = np.transpose(np.nonzero(mask)) pixelpoints = cv2.findNonZero(mask) # print('pixelpoints : ', pixelpoints) # print('pixelpoints : ', type(pixelpoints), pixelpoints.shape,) # print('\n\n\n pixelpoints[:,0,0] : ', pixelpoints[: ,0,0]) # print('\n\n\n pixelpoints[:,0,1] : ', pixelpoints[: ,0,1]) coordinates = list(zip(pixelpoints[: ,0,0], pixelpoints[: ,0,1])) # print('coordinates : ', coordinates, '\n\nlenght : ', len(coordinates)) print('coordinates lenght : ', len(coordinates)) cv2.drawContours(mask, [pixelpoints] , -1, 255, 1) ## TypeError: contours is not a numpy array, neither a scalar cv2.imshow('mask', mask) cv2.waitKey(0) image_copy = image.copy() cv2.drawContours(image_copy, [pixelpoints] , -1, (0,0,255), 1) ##pixelpoints is not a contour is just a series of pixels cv2.imshow('image_copy', image_copy) cv2.waitKey(0) # print('\n\n\n i[:,0,0] : ', i[: ,0,0]) # print('\n\n\n i[:,0,1] : ', i[: ,0,1]) coordinates = list(zip(i[:,0,0], i [:,0,1])) # print('coordinates : ', coordinates, '\n\nlenght : ', len(coordinates)) print('coordinates lenght : ', len(coordinates)) print('---') if cv2.contourArea(i) > 400: # print(n, ' ---> ', cv2.contourArea(i) ) # cv2.drawContours(image, , -1, (0,255,255), cv2.FILLED) cv2.drawContours(image, , -1, (0,255,0), 3) cv2.putText(image, "{}".format(n), (int(i[0][0][0]), int(i[0][0][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2) else: cv2.drawContours(image, , -1, (0,0,255), cv2.FILLED) cv2.putText(image, "{}".format(n), (int(i[0][0][0]), int(i[0][0][1])), cv2.FONT_HERSHEY_SIMPLEX, 0.65, (255, 255, 255), 2) cv2.imshow('image', image) cv2.waitKey(0) cv2.destroyAllWindows() I am trying to retrieve the found contours points using the 6. Mask and Pixel Points approach or just the (cnt[: ,0,0] , cnt[: ,0,1]) approach . What I would try to get to accomplish is visually test the to ways, but what I am once again missing is how to build contours from points ? I know when I am feeding cv2.drawContours(image_copy, [pixelpoints] , -1, (0,0,255), 1) to my image that [pixelpoints] is not a contour but is just a list of pixels coordinates, but for some strange reason the command just draw the righ (??) contour on my picture only problem that is filling it to no matter what thickness keyword I use (here 1). What am I missing ? Any routine/code to recreate contour from a list of pixels coords ? intermediate result : in red the contour that appears feeding points to drawContours and final correct output: Continue reading...