PaddleOCR
PaddleOCR copied to clipboard
paddleOCR在Linux下自动中断程序
🔎 Search before asking
- [X] I have searched the PaddleOCR Docs and found no similar bug report.
- [X] I have searched the PaddleOCR Issues and found no similar bug report.
- [X] I have searched the PaddleOCR Discussions and found no similar bug report.
🐛 Bug (问题描述)
碰到了一个问题:代码在本地Windows环境下运行的时候可以正常运行,并且在测试了一个视频后可以继续测试下一个,不会自动中断。
但是当我把代码放到Linux环境中,测试完一个视频后会自动中断,需要我通过手动启动代码的方式才能继续测试下一个视频
这个问题是当我将LPRNet识别车牌模型换成PaddleOCR模型之后才出现的,之前我用LPRNet来进行车牌识别没有这个问题,但是由于LPRNet识别车牌效果很差,所以换成效果更好的PaddleOCR。
Windows环境下的cuda为11.8,Linux为11.3
🏃♂️ Environment (运行环境)
OS Ubuntu 18 Python 3.8 PaddleOCR 2.8.1 CUDA 11.3
🌰 Minimal Reproducible Example (最小可复现问题的Demo)
def recognize_plate_single_image(plate_img): ocr = get_ocr() result = ocr.ocr(plate_img, det=False, cls=True) if result: text = result[0][0][0] confidence = result[0][0][1] return text, confidence else: return "未检测到", 0
@app.route('/car/recognize', methods=['POST']) def recognize_car():
model = get_model()
data = request.get_json()
video_url = data.get('videoUrl')
final_results = []
for track_id, data in vehicle_detections.items():
carType = Counter(data["carTypes"]).most_common(1)[0][0]
license_plate_groups = {}
for idx, (num, conf) in enumerate(zip(data["carNums"], data["carNumConfs"])):
if num not in license_plate_groups:
license_plate_groups[num] = {'confs': [conf], 'indices': [idx]}
else:
license_plate_groups[num]['confs'].append(conf)
license_plate_groups[num]['indices'].append(idx)
valid_license_plates = []
for num, info in license_plate_groups.items():
confs = info['confs']
min_conf = min(confs)
max_conf = max(confs)
# 判断置信度差异是否小于 0.1
if max_conf >= 0.95:
valid_license_plates.append((num, len(confs), info['indices']))
if valid_license_plates:
# 选择出现次数最多的车牌号
valid_license_plates.sort(key=lambda x: x[1], reverse=True)
carNum = valid_license_plates[0][0]
selected_indices = valid_license_plates[0][2]
# 根据选定的车牌号,获取对应的车牌颜色
carNumColors_filtered = [data["carNumColors"][i] for i in selected_indices]
if carNumColors_filtered:
carNumColor = Counter(carNumColors_filtered).most_common(1)[0][0]
else:
carNumColor = "unknown"
else:
carNum = "未检测到"
carNumColor = "unknown"
# 车辆颜色直接统计出现次数最多的
carColor = Counter(data["carColors"]).most_common(1)[0][0]
result = {
"carType": carType,
"carNum": carNum,
"carColor": carColor,
"carNumColor": carNumColor,
}
final_results.append(result)
vehicle_frames.clear()
vehicle_positions.clear()
return jsonify(final_results)