OpenALPR不能与PyQt一起工作
我试图用PyQt和openalpr构建一个GUI应用程序,但是我的代码存在问题。一个简单的例子:OpenALPR不能与PyQt一起工作
from openalpr import Alpr
from PyQt4 import QtCore, QtGui
class AnalizePlate(object):
def __init__(self):
self.alpr = None
try:
self.alpr = Alpr("eu", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data")
if not self.alpr.is_loaded():
print("Error loading OpenALPR")
except:
print "Error"
def proccess(self):
self.alpr.set_top_n(7)
self.alpr.set_default_region("md")
results = self.alpr.recognize_file("/tmp/1487428945.14.jpg")
print results
a = AnalizePlate()
a.proccess()
上面的代码工作就像一个魅力,但如果GUI参与,出现奇怪的行为。
from openalpr import Alpr
from PyQt4 import QtCore, QtGui
class AnalizePlate(object):
def __init__(self):
self.alpr = None
try:
self.alpr = Alpr("eu", "/etc/openalpr/openalpr.conf", "/usr/share/openalpr/runtime_data")
if not self.alpr.is_loaded():
print("Error loading OpenALPR")
except:
print "Error"
def proccess(self):
self.alpr.set_top_n(7)
self.alpr.set_default_region("md")
results = self.alpr.recognize_file("/tmp/1487428945.14.jpg")
print results
class Window(QtGui.QWidget):
def __init__(self):
super(Window, self).__init__()
self.resize(1198, 651)
self.analize = AnalizePlate()
self.analize.proccess()
QtCore.QMetaObject.connectSlotsByName(self)
if __name__ == "__main__":
import sys
import sip
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
这是一个基本的例子,但错误仍然存在。试图执行openalpr
代码直接到Window
类没有运气。基本上,如果没有gui,代码就可以工作。使用openALPR version 2.2.4
和PyQT4
。此外,检查图像,它在那里。使用recognize_array()
代替recognize file
时也是如此。我得到的错误是:
OpenCV Error: Assertion failed (scaleFactor > 1 && image.depth() == CV_8U) in detectMultiScale, file /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/objdetect/src/cascadedetect.cpp, line 1081 Caught exception in OpenALPR recognize: /build/opencv-SviWsf/opencv-2.4.9.1+dfsg/modules/objdetect/src/cascadedetect.cpp:1081: error: (-215) scaleFactor > 1 && image.depth() == CV_8U in function detectMultiScale
Traceback (most recent call last): File "analize.py", line 39, in window = Window() File "analize.py", line 31, in init self.analize.proccess() File "analize.py", line 22, in proccess results = self.alpr.recognize_file("/tmp/1487428945.14.jpg") File "/usr/lib/python2.7/dist-packages/openalpr/openalpr.py", line 132, in recognize_file response_obj = json.loads(json_data) File "/usr/lib/python2.7/json/init.py", line 339, in loads return _default_decoder.decode(s) File "/usr/lib/python2.7/json/decoder.py", line 364, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python2.7/json/decoder.py", line 380, in raw_decode obj, end = self.scan_once(s, idx) ValueError: Expecting property name: line 1 column 122 (char 121)
这可能是DPI意识的问题。你可能需要看看高DPI支持在Qt http://doc.qt.io/qt-5/highdpi.html。 此外,如果你愿意更新的Qt 5.6,这可能帮助https://stackoverflow.com/a/36058813/2135548
我无法重现此错误。您应该尝试使用最新版本的openalpr及其依赖项进行测试。 FWIW,我的设置是:openalpr-2.3.0,opencv-3.2.0,tesseract-3.0.5,python-2.7.10,pyqt-4.12。 openalpr自述声称opencv-2.4.8是最低要求。不过,我的直觉是,opencv是最有可能的罪魁祸首,因为第2版系列现在是遗留代码,你甚至没有使用它的最新版本(2.4.13)。 – ekhumoro
经过一番工作后,我回到了这个问题。 @ekhumoro注意到opencv版本,我也是,但我知道我已经安装了OpenCV 3.1。在调查安装的软件包之后,我记得OpenALPR是通过'apt-get'安装的,它带有opencv支持(版本2.4.9.1)。所以,从源代码安装解决了我的问题,没有任何代码修改。但是,问题是,为什么在opencv 2.4.9和pyqt中存在冲突? – Aleksandar