I’m trying to write each point of each contour to an image, this probably isn’t the most optimal way but I have this:
####### DRAW CONTOURS
for count, cntr in enumerate(contours):
print(f"Processing contour {str(count)} of {str(len(contours))}...", end="r")
if len(cntr) < 5:
continue
x,y = sort_xy(cntr[:,0,0], cntr[:,0,1])
for i in range(0, len(x)):
image_path = f"./video_output/{str(i).zfill(10)}.jpg"
if count > 0: # This doesn't update
updated_image = cv2.imread(image_path)
cv2.circle(updated_image, (x[i],y[i]), 2, (0, 255, 0), thickness=1)
else: # This works
updated_image = cv2.circle(original_image, (x[i],y[i]), 2, (0, 255, 0), thickness=1)
if not cv2.imwrite(image_path, updated_image):
raise Exception("Could not write image")
I have no problem detecting the contours.
The original image is updated fine, however when I start reading the image in the count > 0
section, it doesn’t seem up load previously drawn points, apart from the first contour when it is using the original image.
When visualizing this it just seems to write the current point to the file, but doesn’t display any of the others.
Not sure if this makes any sense what so ever?
I’ve tried outputting the results, and the first contour works fine. The second just isn’t saving or loading the extra points. Instead its just showing the current point of the contour and not the previous ones.
DrJonoG is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.