Export Co-ords to CSV file - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Export Co-ords to CSV file (/thread-21224.html) |
Export Co-ords to CSV file - gtbiyb - Sep-19-2019 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 RE: Export Co-ords to CSV file - j.crater - Sep-19-2019 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. |