Sep-19-2019, 05:10 PM
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
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