From 16de4a1a40365441370404b5ee35aeb2d6dfdbf8 Mon Sep 17 00:00:00 2001 From: TzuTa Lin Date: Tue, 24 Nov 2015 13:08:43 +0800 Subject: [PATCH] Replace Image with cv2 and upload freeze_build for pyinstaller --- .gitignore | 4 ++++ freeze_build.py | 23 +++++++++++++++++++++++ libs/labelFile.py | 8 +++++--- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100755 freeze_build.py diff --git a/.gitignore b/.gitignore index 767aaf52..a730cb2d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,7 @@ resources.py *.pyc .*.swp +build/ +dist/ + +tags diff --git a/freeze_build.py b/freeze_build.py new file mode 100755 index 00000000..b078ab3e --- /dev/null +++ b/freeze_build.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +from subprocess import call +call(["pyinstaller", "--onefile", "--windowed", "labelImg.py"]) + +# Now it is a workaround. It should use hook file +def readlines(filename): + result = [] + with open(filename, "r") as ins: + for line in ins: + result.append(line) + return result + +lines = readlines('labelImg.spec') +for ind, line in enumerate(lines): + if 'hiddenimports' in line: + lines[ind] = "\t\t\t hiddenimports = ['cv2', 'json', 'lxml.etree', 'lxml', 'etree', 'xml.etree.ElementTree'],\n" + print lines[ind] + +FILE = open('labelImg.spec', "w") +FILE.writelines(lines) +FILE.close() + +call(["pyinstaller", "labelImg.spec"]) diff --git a/libs/labelFile.py b/libs/labelFile.py index 80108980..41fc7ce4 100644 --- a/libs/labelFile.py +++ b/libs/labelFile.py @@ -1,7 +1,7 @@ import json import os.path import numpy -import Image +import cv2 import sys from pascal_voc_writer import PascalVocWriter from base64 import b64encode, b64decode @@ -58,14 +58,16 @@ class LabelFile(object): imgFolderName = os.path.split(imgFolderPath)[-1] imgFileName = os.path.basename(imagePath) imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] - imageShape = numpy.asarray(Image.open(imagePath)).shape + + img = cv2.imread(imagePath) + imageShape = img.shape writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,\ imageShape, localImgPath=imagePath) bSave = False for shape in shapes: points = shape['points'] label = shape['label'] - bndbox = LabelFile.convertPoints2BndBox(points) + bndbox = LabelFile.convertPoints2BndBox(points) writer.addBndBox(bndbox[0], bndbox[1], bndbox[2], bndbox[3], label) bSave = True