简体   繁体   中英

Segmentation fault in recognize_ndarray OpenALPR

I'm trying to detect plates using openalpr + python with an IP cam, but I'm getting the following error:

The openalpr version is the Open Source.

I've alrealdy tryied before recognize_file function, unscessufully

Fatal Python error: Segmentation fault

Current thread 0x00007fa8c2fee740 <python> (most recent call first):
  File "/usr/lib/python2.7/dist-packages/openalpr/openalpr.py", line 184 in recognize_ndarray
  File "main9.py", line 45 in main
  File "main9.py", line 59 in <module>

Bellow the code:

import numpy as np
import cv2
from openalpr import Alpr
import sys
import faulthandler; faulthandler.enable()


RTSP_SOURCE  = 'rtsp://user:pass@ip:port/cam/realmonitor?channel=1&subtype=0'
WINDOW_NAME  = 'openalpr'
FRAME_SKIP   = 15

def main():
    alpr= Alpr("us", "/etc/openalpr/openalpr.conf", "/home/alan/openalpr/runtime_data")
    if not alpr.is_loaded():
        print('Error loading OpenALPR')
        sys.exit(1)
    alpr.set_top_n(3)
    alpr.set_default_region('pa')

    cap = cv2.VideoCapture(RTSP_SOURCE)
    cv2.namedWindow('op', cv2.WINDOW_NORMAL)
    if not cap.isOpened():
        alpr.unload()
        sys.exit('Failed to open video file!')
    cv2.namedWindow(WINDOW_NAME, cv2.WINDOW_AUTOSIZE)
    cv2.setWindowTitle(WINDOW_NAME, 'OpenALPR video test')

    _frame_number = 0
    while True:
        ret_val, frame = cap.read()
        if not ret_val:
            print('VidepCapture.read() failed. Exiting...')
            break

        _frame_number += 1
        if _frame_number % FRAME_SKIP != 0:
            continue
        cv2.imshow(WINDOW_NAME, frame)

        results = alpr.recognize_ndarray(frame)
        for i, plate in enumerate(results['results']):
            best_candidate = plate['candidates'][0]
            print('Plate #{}: {:7s} ({:.2f}%)'.format(i, best_candidate['plate'].upper(), best_candidate['confidence']))

        if cv2.waitKey(1) == 27:
            break

    cv2.destroyAllWindows()
    cap.release()
    alpr.unload()


if __name__ == "__main__":
    main()

Does anybody faced this error before?

I know this is a very old post but I've currently been working on a very similar project and came across this very same issue. experimenting around with the code led me to discover that if you include the following lines of code in a function python will throw a segmentation error:

alpr =Alpr("eu","/etc/openalpr/openalpr.conf","/usr/share/openalpr/runtime_data")
alpr.unload()

Luckily however you only need to run these lines once in a python script to be able to use openalpr so run the first line just at the start of your code before the function is called and run the second line only after you've finished using the function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM