Skip to content
Snippets Groups Projects
Commit 16a54f38 authored by Aymeric Chaumont's avatar Aymeric Chaumont
Browse files

allow for multiple cameras

parent 42bf4bfa
No related branches found
No related tags found
1 merge request!37rtsp video capture setup
...@@ -10,20 +10,34 @@ from db.database import SessionLocal ...@@ -10,20 +10,34 @@ from db.database import SessionLocal
db = SessionLocal() db = SessionLocal()
model = keras.models.load_model('assets') model = keras.models.load_model('assets')
cap = cv2.VideoCapture("rtsp://viarezocam:superponey@10.148.38.9/stream1")
count = 0
frame_gap = 450 frame_gap = 450
while(cap.isOpened()): cameras = [{
ret, frame = cap.read() "place": "local",
if ret and count % frame_gap == 0: "IP": "10.148.38.9",
"user": "viarezocam",
"password": "superponey",
"stream": "stream1",
"framegap": 900, # 60 * camera frequency
"count": 0, # mandatory
"cap": None
}]
for camera in cameras:
camera.cap = cv2.VideoCapture(f"rtsp://{camera.user}:{camera.password}@{camera.ip}/{camera.stream}")
while True:
for camera in cameras:
if camera.cap.isOpened():
ret, frame = camera.cap.read()
if ret and camera.count % camera.frame_gap == 0:
current_time = datetime.now() current_time = datetime.now()
treated_img = fix_singular_shape(frame, 16) treated_img = fix_singular_shape(frame, 16)
input_image = np.expand_dims(np.squeeze(norm_by_imagenet(np.array([treated_img]))), axis=0) input_image = np.expand_dims(np.squeeze(norm_by_imagenet(np.array([treated_img]))), axis=0)
pred_map = np.squeeze(model.predict(input_image)) pred_map = np.squeeze(model.predict(input_image))
count_prediction = np.sum(pred_map) count_prediction = np.sum(pred_map)
waiting_time = timedelta(seconds=120 + count_prediction * 30) waiting_time = timedelta(seconds=120 + count_prediction * 30)
record = {"place": "local", record = {"place": camera.place,
"date": current_time, "date": current_time,
"density": count_prediction, "density": count_prediction,
"waiting_time": waiting_time} "waiting_time": waiting_time}
...@@ -31,6 +45,6 @@ while(cap.isOpened()): ...@@ -31,6 +45,6 @@ while(cap.isOpened()):
db.add(db_record) db.add(db_record)
db.commit() db.commit()
db.refresh(db_record) db.refresh(db_record)
count += 1 camera.count += 1
cap.release() else:
cv2.destroyAllWindows() camera.cap.release()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment