Python Forum

Full Version: Export Co-ords to CSV file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

Using Open CV I have successfully found the coordinates of centroids for contours and can print the values:

for c in contours:

M = cv2.moments©
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])

cv2.circle(frame, (cX, cY), 7, (255, 255, 255), -1)
cv2.putText(frame, "center", (cX - 20, cY - 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
print(cX, cY)

I also want to export to a CSV file but when i add np.savetxt('Coords.txt',(cX,cY)) the spreadsheet only contains the coords for one of the three shapes whilst the print function shows all 3 of the shapes for the image under analysis:

for c in contours:

M = cv2.moments©
cX = int(M["m10"] / M["m00"])
cY = int(M["m01"] / M["m00"])

cv2.circle(frame, (cX, cY), 7, (255, 255, 255), -1)
cv2.putText(frame, "center", (cX - 20, cY - 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 2)
np.savetxt('Coords.txt',(cX,cY))
print(cX, cY)

Any help is appreciated.

Matt
Hello and welcome to the forums.
Please put your code in Python code tags, you can find help here.
I would also advise you to to provide (preferably in output tags) the result you get, along with the desired result.