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

Implement informative error messages if the values in needed columns are missing or are unexpected #6

Open valentinitnelav opened 2 years ago

valentinitnelav commented 2 years ago

If any of these columns (windows_img_path, id_box, x, y, width & height) contain unexpected values, then one gets a cryptic error message at the moment.

Example of a current not-user-friendly error message when in the column windows_img_path one has a number instead of the expected absolute file path:

Selection_145

---------------------------
Error
---------------------------
Traceback (most recent call last):
  File "c:\python38\lib\site-packages\PIL\Image.py", line 3096, in open
    fp.seek(0)
AttributeError: 'numpy.float64' object has no attribute 'seek'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\...\field-img-taxa-annotation\vba_python_img_with_box\xlwings_test\xlwings_test_project.py", line 68, in main
    display_img()
  File "C:\...\field-img-taxa-annotation\vba_python_img_with_box\xlwings_test\xlwings_test_project.py", line 46, in display_img
    with Image.open(img_path) as im:
  File "c:\python38\lib\site-packages\PIL\Image.py", line 3098, in open
    fp = io.BytesIO(fp.read())
AttributeError: 'numpy.float64' object has no attribute 'read'

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------

When the absolute path has a typo, the error message is a bit more clear and can leave it as it is for now:

---------------------------
Error
---------------------------
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\...\field-img-taxa-annotation\vba_python_img_with_box\xlwings_test\xlwings_test_project.py", line 68, in main
    display_img()
  File "C:\...\field-img-taxa-annotation\vba_python_img_with_box\xlwings_test\xlwings_test_project.py", line 46, in display_img
    with Image.open(img_path) as im:
  File "c:\python38\lib\site-packages\PIL\Image.py", line 3092, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\...\\field-img\\2021-07-06\\Centaurea-scabiosa-01\\IMG_0377.JPG'

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK   
---------------------------