過程
最初環境 python 3.6 qt5.7
*遇到了一個bug
Cannot mix incompatible Qt library (version 0x50905) with this library (version 0x50a01)
*在網上搜索之後,發現ubuntu自帶qt4,就開始換python環境了
環境 python 2.7
- 安裝pyqt4的時候出了點小問題,pip安裝沒有成功
- 解決方案:參考
conda install --channel https://conda.anaconda.org/conda-forge pyqt
conda install -c anaconda pyqt=4.11.4
- bug,保存文件的時候出錯了
TypeError: cannot serialize PyQt4.QtCore.QString(u'dog') (type QString)
- 好吧,pyqt要4.8,參考
conda install -c terradue pyqt4
- 有出錯了
File "labelImg.py", line 26, in <module>
from PyQt4.QtGui import *
ImportError: libQtMultimedia.so.4: cannot open shared object file: No such file or directory
結果
- 安裝
#Python 2 + Qt4
sudo apt-get install pyqt4-dev-tools
sudo pip install lxml
make qt4py2
python2 labelImg.py
- bug
TypeError: cannot serialize PyQt4.QtCore.QString(u'dog') (type QString)
* 更改保存的代碼(個人需要的只是框的座標,保存成了txt格式)
#lib/pascal_voc_io.py
def appendObjects(self, top):
label = []
for each_object in self.boxlist:
label.append([each_object['xmin'],each_object['ymin'],each_object['xmax'],each_object['ymax']])
return label
def save(self, targetFile=None):
root = self.genXML()
labels = self.appendObjects(root)
out_file = None
if targetFile is None:
print '===================================='
else:
myfile = targetFile.split('.')[0] +'.txt'
print myfile
out_file = open(myfile,'w')
for label in labels:
out_file.write(str(label[0])+' '+str(label[1]) + ' '+ str(label[2]) + ' ' + str(label[3])+ '\n')
out_file.close()