Bottom Page

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
Quote
#2
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.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)