Replace Image with cv2 and upload freeze_build for pyinstaller

This commit is contained in:
TzuTa Lin 2015-11-24 13:08:43 +08:00
parent 30cce26d22
commit 16de4a1a40
3 changed files with 32 additions and 3 deletions

4
.gitignore vendored
View File

@ -6,3 +6,7 @@ resources.py
*.pyc *.pyc
.*.swp .*.swp
build/
dist/
tags

23
freeze_build.py Executable file
View File

@ -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"])

View File

@ -1,7 +1,7 @@
import json import json
import os.path import os.path
import numpy import numpy
import Image import cv2
import sys import sys
from pascal_voc_writer import PascalVocWriter from pascal_voc_writer import PascalVocWriter
from base64 import b64encode, b64decode from base64 import b64encode, b64decode
@ -58,7 +58,9 @@ class LabelFile(object):
imgFolderName = os.path.split(imgFolderPath)[-1] imgFolderName = os.path.split(imgFolderPath)[-1]
imgFileName = os.path.basename(imagePath) imgFileName = os.path.basename(imagePath)
imgFileNameWithoutExt = os.path.splitext(imgFileName)[0] imgFileNameWithoutExt = os.path.splitext(imgFileName)[0]
imageShape = numpy.asarray(Image.open(imagePath)).shape
img = cv2.imread(imagePath)
imageShape = img.shape
writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,\ writer = PascalVocWriter(imgFolderName, imgFileNameWithoutExt,\
imageShape, localImgPath=imagePath) imageShape, localImgPath=imagePath)
bSave = False bSave = False