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

allow for multiple cameras

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