labelImg ZeroDivisionError: float division by zero solution

problem

Do object detection data sets, the need to use object detection tool marks. Currently using labelImg, the project Address:
https://github.com/tzutalin/labelImg
use in online search have a lot, do not make too much introduction.
Use page is shown below:
Here Insert Picture Description
After the use of the process, the relevant part of marquee, flash back the program, then the terminal an error message is as follows:

xcen = float((xmin + xmax)) / 2 / self.imgSize[1]
ZeroDivisionError: float division by zero

Online queries related issue, was asked the same question, below the corresponding answer.

Solution

Cause of the problem is the software to open some pictures when the background is transparent that, there will be size is 0, the solution is to open with opencv, and then re-save the file to overwrite the original code is as follows:

import sys
import cv2

input_file = sys.argv[1]  # 支持批量操作
with open(input_file, 'r') as f:
    for line in f:
        img_name = line.rstrip('\n')
        img = cv2.imread(img_name)
        save_path = img_name
        cv2.imwrite(save_path, img)  # 可以加quality参数

The code supports batch operations, direct the entire folder under the file name they can enter. Overwrite save, open the software to deal with these pictures again, I will not report an error

Published 82 original articles · won praise 82 · views 240 000 +

Guess you like

Origin blog.csdn.net/uncle_ll/article/details/103206157