tylerhutcherson/synthetic-images

annotations wrong

bachmid-adib opened this issue · 1 comments

Hello brother, thank you for this script. But I found an error in the object annotation, where the box labels don't match their proper position. I think the algorithm for determining annotation coordinates is incorrect. Can you help me?

Hi the annotations are correct, but perhaps not in the format you expect them. The annotations gives x,y, width and height, where x,y are the center points of the object. If you want to draw a bounding box around it you need the top left and bottom right point. You can calculate that from the center points and width, height. Here is an example:

pt1 = (int(x-(width/2)),int(y-(height/2)))
pt2 = (int(x+(width/2)),int(y+(height/2)))

cv2.circle(image, pt1, 15, (0, 255, 0), -1)
cv2.circle(image, pt1, 15, (0, 255, 0), -1)
cv2.circle(image, pt2, 15, (0, 255, 0), -1)
cv2.rectangle(image, pt1, pt2, (0, 255, 0), 1)

The code above will make a circle at the top left, top right and center. It will also draw the bounding box.