13

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)

2
  • I cannot reproduce this error. You should try testing with the latest version of openalpr and its dependencies. FWIW, my setup is: openalpr-2.3.0, opencv-3.2.0, tesseract-3.0.5, python-2.7.10, pyqt-4.12. The openalpr readme claims that opencv-2.4.8 is the minimum requirement. Still, my hunch is that opencv is the most likely culprit, given that the version 2 series is now legacy code and you're not even using the latest release of it (2.4.13).
    – ekhumoro
    Commented Feb 21, 2017 at 20:09
  • After some work absent, i got back in this issue. @ekhumoro noticed opencv version, so did I, but i knew that i have OpenCV 3.1 installed. After investigating installed packages, I remembered that OpenALPR is installed via 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?
    – Aleksandar
    Commented Mar 2, 2017 at 2:38

3 Answers 3

1

It may be problem of DPI Awareness. you may need to have a look at High DPI support in Qt on http://doc.qt.io/qt-5/highdpi.html. Also if you are willing to update Qt to 5.6 this may help https://stackoverflow.com/a/36058813/2135548

1

I guess signature for new application app = QtGui.QApplication(sys.argv) is missing argc. Signature for new application is QApplication(int & argc, char ** argv) see here

1
  • This is completely wrong, and does not answer the question in any way.
    – ekhumoro
    Commented Feb 28, 2017 at 20:15
1

We found that with Python multiprocessing when process A launched process B, OpenCV would fail if it was imported in A and called from B, whether or not B imported it again. I'm not familiar with QT but if the window is running in a separate process the same thing may be happening (OpenCV being a dependency of OpenALPR).

If it is, then you'll probably find that leaving AnalizePlate[1] in a separate source file with the import openalpr at the top and referencing it from your window code with no import openalpr at the top will work fine.

[1] I think you mean Analyze(US)/Analyse(BR/AU). Analize means something else :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.