作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用带有 IP 摄像头的 openalpr + python 检测车牌,但出现以下错误:
openalpr 版本是开源的。
我已经尝试过 recognize_file 函数,没有成功
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>
代码如下:
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()
以前有人遇到过这个错误吗?
最佳答案
我知道这是一篇非常古老的帖子,但我目前一直在从事一个非常相似的项目并且遇到了同样的问题。对代码进行试验使我发现,如果您在函数中包含以下代码行,python 将引发段错误:
alpr =Alpr("eu","/etc/openalpr/openalpr.conf","/usr/share/openalpr/runtime_data")
alpr.unload()
幸运的是,您只需要在 python 脚本中运行这些行一次就可以使用 openalpr,因此在调用函数之前在代码的开头运行第一行,仅在调用函数之后运行第二行函数使用完毕。
关于python - recognize_ndarray OpenALPR 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56093820/
我正在尝试使用带有 IP 摄像头的 openalpr + python 检测车牌,但出现以下错误: openalpr 版本是开源的。 我已经尝试过 recognize_file 函数,没有成功 Fat
我是一名优秀的程序员,十分优秀!