дописал логику в чтение потока
This commit is contained in:
parent
7e55e72e35
commit
594074a0f2
4
.env
4
.env
@ -4,9 +4,9 @@ DB_PASSWORD=qwerty12Q!
|
||||
DB_HOST=localhost
|
||||
DB_PORT=5432
|
||||
|
||||
RTSP_URL=C:/kpp/app/ml/video.mkv
|
||||
RTSP_URL=rtsp://192.168.31.56:8554/cam
|
||||
|
||||
YOLO_MODEL=C:/kpp/app/ml/models/kpp/yolo11s 10epochs/myyolo11s.pt
|
||||
YOLO_MODEL=C:\project\kpp\app\ml\models\kpp\yolo11n 10 epochs\yolo11n_10epochs.pt
|
||||
|
||||
token=MyToken
|
||||
ip_addr_web=MyIpAddr
|
||||
|
||||
@ -10,6 +10,7 @@ from dotenv import load_dotenv
|
||||
import requests
|
||||
from Car import Car
|
||||
from Plate import Plate
|
||||
import time
|
||||
load_dotenv()
|
||||
|
||||
rstp_url= os.getenv('RTSP_URL')
|
||||
@ -157,22 +158,37 @@ def send_car_data(pts, car: Car, plate: Plate ):
|
||||
"error": error_msg
|
||||
}
|
||||
|
||||
|
||||
container = av.open(rstp_url)
|
||||
|
||||
video_stream = next(s for s in container.streams if s.type == 'video')
|
||||
plate_text = ""
|
||||
plate = Plate("", 0, 0, 0, 0)
|
||||
car = Car(0,0,0,0)
|
||||
|
||||
container = av.open(
|
||||
rstp_url, 'r',
|
||||
options={
|
||||
'rtsp_transport': 'tcp', # при udp теряются пакеты
|
||||
'fflags': 'nobuffer', # отключаем буферизацию
|
||||
'flags': 'low_delay', # оставшиеся настройки для снижения задержки
|
||||
'stimeout': '100000',
|
||||
'max_delay': '100000',
|
||||
}
|
||||
)
|
||||
video = container.demux(video=0)
|
||||
|
||||
video_stream = next(s for s in container.streams if s.type == 'video')
|
||||
for packet in container.demux(video_stream):
|
||||
for frame in packet.decode():
|
||||
|
||||
|
||||
if 'start_time' not in locals():
|
||||
start_time = time.time()
|
||||
start_read = frame.time
|
||||
|
||||
if (time.time()-start_time)-(frame.time-start_read)>.3:
|
||||
continue # пропуск кадров при отставании от real time
|
||||
|
||||
pts = frame.pts # PTS в тактах (time_base)
|
||||
img = frame.to_ndarray(format='bgr24')
|
||||
results = model.predict(img)
|
||||
|
||||
pts = frame.pts # PTS в тактах (time_base)
|
||||
|
||||
|
||||
|
||||
for result in results:
|
||||
|
||||
for box in result.boxes:
|
||||
@ -194,7 +210,7 @@ for packet in container.demux(video_stream):
|
||||
|
||||
cv2.rectangle(img, (int(x1), int(y1)), (int(x2), int(y2)), (0, 255, 0), 2)
|
||||
|
||||
print(send_car_data(pts, car, plate))
|
||||
# print(send_car_data(pts, car, plate))
|
||||
|
||||
cv2.imshow('frame', img)
|
||||
if cv2.waitKey(1) & 0xFF == ord('q'):
|
||||
|
||||
@ -2,8 +2,9 @@ fastapi==0.104.1
|
||||
uvicorn==0.24.0
|
||||
opencv-python==4.8.1.78
|
||||
numpy==1.26.2
|
||||
ultralytics==8.0.208
|
||||
ultralytics==8.3.111
|
||||
paddlepaddle==2.5.2
|
||||
paddleocr==2.7.0.3
|
||||
psycopg2-binary==2.9.9
|
||||
python-dotenv==1.0.0
|
||||
pyav==14.2.1
|
||||
Loading…
x
Reference in New Issue
Block a user