I tried to build a GUI app with PyQt and openalpr, but there are an issue with my code. A simple example:
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()
Above code works like a charm, but if GUI is involved, strange behavior occurs.
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_())
It's a basic example, but error is still here. Tried to implement openalpr
code directly to Window
class with no luck. So basicly, if there is no gui, code works. Using openALPR version 2.2.4
and PyQT4
. Also, checked the image, it's there. The same apply when recognize_array()
is used instead of recognize file
. Error I got is:
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)
apt-get
and it comes with opencv support (version 2.4.9.1). So, installation from source resolved my issue without any code modification. But, the question is, why there is conflict in opencv 2.4.9 and pyqt?