估算距离初始化时,先调用一次模型,解决第一次推理时模型加载太费时间问题
11
logs/app_20250114_175524.log
Normal file
@ -0,0 +1,11 @@
|
||||
2025-01-14 17:55:24,753 - __main__ - INFO - 启动服务...
|
||||
2025-01-14 17:55:24,755 - __main__ - INFO - 配置加载成功
|
||||
2025-01-14 17:55:24,756 - __main__ - INFO - 正在初始化相机...
|
||||
2025-01-14 17:55:24,756 - __main__ - INFO - 正在初始化人物检测器...
|
||||
2025-01-14 17:55:24,800 - __main__ - INFO - 正在初始化距离估计器...
|
||||
2025-01-14 17:55:34,848 - __main__ - INFO - 服务启动在 http://0.0.0.0:5000
|
||||
2025-01-14 17:55:34,853 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on all addresses (0.0.0.0)
|
||||
* Running on http://127.0.0.1:5000
|
||||
* Running on http://10.0.0.202:5000
|
||||
2025-01-14 17:55:34,853 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||
11
logs/app_20250114_175625.log
Normal file
@ -0,0 +1,11 @@
|
||||
2025-01-14 17:56:25,022 - __main__ - INFO - 启动服务...
|
||||
2025-01-14 17:56:25,025 - __main__ - INFO - 配置加载成功
|
||||
2025-01-14 17:56:25,025 - __main__ - INFO - 正在初始化相机...
|
||||
2025-01-14 17:56:25,025 - __main__ - INFO - 正在初始化人物检测器...
|
||||
2025-01-14 17:56:25,069 - __main__ - INFO - 正在初始化距离估计器...
|
||||
2025-01-14 17:56:35,119 - __main__ - INFO - 服务启动在 http://0.0.0.0:5000
|
||||
2025-01-14 17:56:35,124 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on all addresses (0.0.0.0)
|
||||
* Running on http://127.0.0.1:5000
|
||||
* Running on http://10.0.0.202:5000
|
||||
2025-01-14 17:56:35,124 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||
15
logs/app_20250114_175657.log
Normal file
@ -0,0 +1,15 @@
|
||||
2025-01-14 17:56:57,905 - __main__ - INFO - 启动服务...
|
||||
2025-01-14 17:56:57,907 - __main__ - INFO - 配置加载成功
|
||||
2025-01-14 17:56:57,908 - __main__ - INFO - 正在初始化相机...
|
||||
2025-01-14 17:56:57,908 - __main__ - INFO - 正在初始化人物检测器...
|
||||
2025-01-14 17:56:57,952 - __main__ - INFO - 正在初始化距离估计器...
|
||||
2025-01-14 17:57:08,009 - __main__ - INFO - 服务启动在 http://0.0.0.0:5000
|
||||
2025-01-14 17:57:08,014 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on all addresses (0.0.0.0)
|
||||
* Running on http://127.0.0.1:5000
|
||||
* Running on http://10.0.0.202:5000
|
||||
2025-01-14 17:57:08,014 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||
2025-01-14 17:57:18,020 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:57:18] "GET /health HTTP/1.1" 200 -
|
||||
2025-01-14 17:57:31,390 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:57:31] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
2025-01-14 17:57:35,250 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:57:35] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
2025-01-14 17:57:45,954 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:57:45] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
14
logs/app_20250114_175849.log
Normal file
@ -0,0 +1,14 @@
|
||||
2025-01-14 17:58:49,091 - __main__ - INFO - 启动服务...
|
||||
2025-01-14 17:58:49,094 - __main__ - INFO - 配置加载成功
|
||||
2025-01-14 17:58:49,094 - __main__ - INFO - 正在初始化相机...
|
||||
2025-01-14 17:58:49,094 - __main__ - INFO - 正在初始化人物检测器...
|
||||
2025-01-14 17:58:49,139 - __main__ - INFO - 正在初始化距离估计器...
|
||||
2025-01-14 17:58:59,196 - __main__ - INFO - 服务启动在 http://0.0.0.0:5000
|
||||
2025-01-14 17:58:59,201 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on all addresses (0.0.0.0)
|
||||
* Running on http://127.0.0.1:5000
|
||||
* Running on http://10.0.0.202:5000
|
||||
2025-01-14 17:58:59,201 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||
2025-01-14 17:59:12,674 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:59:12] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
2025-01-14 17:59:35,368 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 17:59:35] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
2025-01-14 18:00:08,056 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 18:00:08] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
12
logs/app_20250114_180452.log
Normal file
@ -0,0 +1,12 @@
|
||||
2025-01-14 18:04:52,907 - __main__ - INFO - 启动服务...
|
||||
2025-01-14 18:04:52,910 - __main__ - INFO - 配置加载成功
|
||||
2025-01-14 18:04:52,910 - __main__ - INFO - 正在初始化相机...
|
||||
2025-01-14 18:04:52,910 - __main__ - INFO - 正在初始化人物检测器...
|
||||
2025-01-14 18:04:55,164 - __main__ - INFO - 正在初始化距离估计器...
|
||||
2025-01-14 18:05:05,216 - __main__ - INFO - 服务启动在 http://0.0.0.0:5000
|
||||
2025-01-14 18:05:05,220 - werkzeug - INFO - [31m[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.[0m
|
||||
* Running on all addresses (0.0.0.0)
|
||||
* Running on http://127.0.0.1:5000
|
||||
* Running on http://10.0.0.202:5000
|
||||
2025-01-14 18:05:05,220 - werkzeug - INFO - [33mPress CTRL+C to quit[0m
|
||||
2025-01-14 18:05:25,184 - werkzeug - INFO - 127.0.0.1 - - [14/Jan/2025 18:05:25] "GET /distances?save_visualization=true HTTP/1.1" 200 -
|
||||
1
main.py
@ -55,6 +55,7 @@ def init_detector(config, logger):
|
||||
model_path=detector_config['model_path'],
|
||||
conf_threshold=detector_config.get('conf_threshold', 0.5)
|
||||
)
|
||||
detector.detect(None)
|
||||
return detector
|
||||
|
||||
def init_estimator(config, logger):
|
||||
|
||||
|
Before Width: | Height: | Size: 103 KiB |
|
Before Width: | Height: | Size: 85 KiB |
|
Before Width: | Height: | Size: 82 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 72 KiB |
BIN
output/detection_20250114_175935_366296.jpg
Normal file
|
After Width: | Height: | Size: 81 KiB |
BIN
output/detection_20250114_180008_054797.jpg
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
output/detection_20250114_180525_182364.jpg
Normal file
|
After Width: | Height: | Size: 79 KiB |
@ -142,7 +142,8 @@ class DistanceAPI:
|
||||
|
||||
# 只要连上后 get_frame()就有帧, 计算突然断开RTSP流, 还是会返回最后一帧的结果.
|
||||
camera_ok = self.camera.get_frame() is not None
|
||||
self.save_visualization(self.camera.get_frame())
|
||||
if self.camera.get_frame() is not None:
|
||||
self.save_visualization(self.camera.get_frame())
|
||||
|
||||
# print(self.camera.get_frame())
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ class RTSPCamera:
|
||||
time.sleep(2)
|
||||
cap = self.connect_to_rtsp_stream(self.rtsp_url)
|
||||
else:
|
||||
print("RTSP流连接成功", end='')
|
||||
# print("RTSP流连接成功", end='\r')
|
||||
ret, frame = cap.read()
|
||||
if ret:
|
||||
self.frame = frame
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import mediapipe as mp
|
||||
from datetime import datetime
|
||||
|
||||
class DistanceEstimator:
|
||||
def __init__(self,
|
||||
@ -170,8 +171,8 @@ class DistanceEstimator:
|
||||
cv2.rectangle(vis_frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
||||
|
||||
# 添加距离和置信度信息
|
||||
text = f"Distance: {distance_mm/1000:.2f}m Conf: {confidence:.2f}"
|
||||
text = f"Distance: {distance_mm/1000:.2f}m Conf: {confidence:.2f} time: {datetime.now().strftime('%Y%m%d_%H%M%S_%f')}"
|
||||
cv2.putText(vis_frame, text, (x1, y1-10),
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
||||
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
|
||||
|
||||
return vis_frame
|
||||