Segmentation fault in recognize_ndarray


#1

Hi, I’m trying to detect plates from an IP cam but I’m getting the following error:

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>

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()