valentinitnelav / img-with-box-from-excel

boxcel: Integrate Excel with Python for visualizing images with their corresponding bounding boxes for object detection annotation workflows
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Error message - "ValueError: incorrect coordinate type" #19

Closed valentinitnelav closed 1 year ago

valentinitnelav commented 1 year ago

Not sure at the moment why this is happening.

File: dt_annotations_with_cor_plants_2023_04_20.xlsx Note that this doesn't happen at the moment with hymenoptera_Demetra.xlsm. Check why - is it the file type?

image

---------------------------
Error
---------------------------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "i:\artificial-intelligence\field-img-taxa-annotation\archive\dt_annotations_with_cor_plants_2023_04_20.py", line 82, in main
    display_img()
  File "i:\artificial-intelligence\field-img-taxa-annotation\archive\dt_annotations_with_cor_plants_2023_04_20.py", line 63, in display_img
    draw.rectangle(xy=coord, outline='Red', width=3)
  File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\ImageDraw.py", line 281, in rectangle
    self.draw.draw_rectangle(xy, ink, 0, width)
ValueError: incorrect coordinate type

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------
valentinitnelav commented 1 year ago

Saving the file as xlsm didn't solve the problem

valentinitnelav commented 1 year ago

I also changed how I defined coords from

coord = [x0, y0, x1, y1]

But didn't fix it to

 coord = [(x0, y0), (x1, y1)]
valentinitnelav commented 1 year ago

Ok, so the problem is that it can happen that the coordinates are read as text, to fix this, convert them to integer.

So, in https://github.com/valentinitnelav/img-with-box-from-excel/blob/main/src/boxcel/display_images.py, replace

x0 = df['x'][0]
y0 = df['y'][0]
x1 = df['x'][0] + df['width'][0]
y1 = df['y'][0] + df['height'][0]

with

x0 = int(df['x'][0])
y0 = int(df['y'][0])
x1 = x0 + int(df['width'][0])
y1 = y0 + int(df['height'][0])