HumanSignal / labelImg

LabelImg is now part of the Label Studio community. The popular image annotation tool created by Tzutalin is no longer actively being developed, but you can check out Label Studio, the open source data labeling tool for images, text, hypertext, audio, video and time-series data.
https://youtu.be/p0nR2YsCY_U
MIT License
22.51k stars 6.27k forks source link

ZeroDivisionError: float division by zero #386

Open Legolas-Li opened 5 years ago

Legolas-Li commented 5 years ago

Img: /home/legolas/darknet/VOCdevkit/VOC2007/JPEGImages/reliao_img_1540548508095.jpg -> Its txt: /home/legolas/darknet/VOCdevkit/VOC2007/JPEGImages/reliao_img_1540548508095.txt Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 1298, in saveFile else self.saveFileDialog()) File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 1320, in _saveFile if annotationFilePath and self.saveLabels(annotationFilePath): File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/labelImg/labelImg.py", line 808, in saveLabels self.lineColor.getRgb(), self.fillColor.getRgb()) File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/labelFile.py", line 83, in saveYoloFormat writer.save(targetFile=filename, classList=classList) File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/yolo_io.py", line 64, in save classIndex, xcen, ycen, w, h = self.BndBox2YoloLine(box, classList) File "/usr/local/lib/python2.7/dist-packages/labelImg-1.8.0-py2.7.egg/libs/yolo_io.py", line 36, in BndBox2YoloLine xcen = float((xmin + xmax)) / 2 / self.imgSize[1] ZeroDivisionError: float division by zero

vdalv commented 5 years ago

Please describe what you were trying to do when this error occurred.

Providing the image and label file would also be useful.

mbalfakeih commented 5 years ago

I am experiencing this same issue, all images after image 681 (there are about 2500 images) give me this exact error. I am trying to label these images, but when I try to save I recieve this error, with an Abort Trap: 6, at the end of it. I don't think it's anything wrong with the images, as some of these are the exact same pictures as previous ones.

mbalfakeih commented 5 years ago

I'm using python 3.6.6

mbalfakeih commented 5 years ago

000681 000682 000683 000684 Here are some of the images that weren't working

blackteanomilk commented 5 years ago

I had this problem too. In my case it was caused by something in the jpg-file that caused QImage to set dimensions of loaded file to 0,0,3. GIMP could not open the file either, even though some image viewers could. In my case the problem was solved by loading the problematic image into viewer that could open it and saving it again.

ldsyou92 commented 5 years ago

I have the same error, when I try to label images,the error is below: Traceback (most recent call last): File "<string>", line 1298, in saveFile File "<string>", line 1320, in _saveFile File "<string>", line 808, in saveLabels File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.labelFile", line 83, in saveYoloFormat File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.yolo_io", line 64, in save File "Z:\home\darrenl\tmp\labelImg\build-tools\build\labelImg\out00-PYZ.pyz\libs.yolo_io", line 36, in BndBox2YoloLine ZeroDivisionError: float division by zero

I cant figure out where the location Z is , and why this error happens.

ThanhLV97 commented 4 years ago

This problem was solved by changing to PNG image 👍in my case

DynamicCodes commented 4 years ago

i faced the same problem, this happens due to transparency in the some images, i dnt know what kind of transparency is this,......but it can be solved by opening the image with opencv and saving it again, it worked for me.

i wrote this python file :--

import cv2 import os

def loadImages(path = "."):

return [os.path.join(path, f) for f in os.listdir(path) if f.endswith('.jpg')]

filenames = loadImages() images = [] for file in filenames: images.append(cv2.imread(file, cv2.IMREAD_UNCHANGED))

num = 0 for image in images: cv2.imwrite(str(num)+".jpg",image) num += 1

it will open every file in the directory and save it again!!

ib124 commented 4 years ago

My issue was solved by converting the .jpg images to .png images, exactly what @thanh15dt2 mentioned. I did it by following this tutorial: https://www.youtube.com/watch?v=FGr3N3DLGEI

arun-rangarajan commented 3 years ago

Windows 10.

Versions:

C:\Users\arunr>conda -V
conda 4.8.5

C:\Users\arunr> python -V
Python 3.7.9

C:\Users\arunr> conda list | findstr qt
pyqt                      5.9.2            py37h6538335_2
pyqt5                     5.15.2                   pypi_0    pypi
pyqt5-sip                 12.8.1                   pypi_0    pypi
qt                        5.9.7            vc14h73c81de_0

C:\Users\arunr> pip list | findstr label
labelImg                 1.8.3

PNG gives ZeroDivisionError. JPG works!

In python, you can use this to convert PNG to JPG:

from PIL import Image

im1 = Image.open(r'path where the PNG is stored\file name.png')
im1.save(r'path where the JPG will be stored\new file name.jpg')