Python Forum
Export Co-ords to CSV file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Export Co-ords to CSV file
#1
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
Reply


Messages In This Thread
Export Co-ords to CSV file - by gtbiyb - Sep-19-2019, 05:10 PM
RE: Export Co-ords to CSV file - by j.crater - Sep-19-2019, 07:59 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  export dataframe to file.txt dramauh 5 1,928 Apr-21-2022, 01:23 AM
Last Post: sarahroxon7
  Export dataframe to xlsx - Error "zipfile.BadZipFile: File is not a zip file" Baggio 10 62,118 Mar-12-2021, 01:02 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020