Currently, the code is as follows:
while ascended_height < target_height:
t0 = time.time()
try:
cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
for _ in range(3):
cap.read()
ok, frame = cap.read()
cap.release()
if not ok:
print("[WARN] Frame grab failed during ascent")
time.sleep(0.1)
continue
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"capture_{timestamp}.jpg"
cv2.imwrite(filename, frame)
print(f"[SAVE] {filename}")
depth_m, fpx = infer_depth_meters(model, transform, frame)
if depth_m is None:
print("[ERROR] Depth estimation failed during ascent")
time.sleep(0.1)
continue
d_min = robust_min_depth(depth_m)
print(f"[ASCENT] d_min={d_min:.2f} m, ascended={ascended_height:.2f}m/{target_height}m")
Using this code, the camera captures and processes frames for depth estimation.
However, during experiments, communication issues often cause frequent errors, and frames fail to be transmitted.
Is there a way to lighten or optimize this frame processing to make it more reliable?
while ascended_height < target_height:
t0 = time.time()
try:
cap = cv2.VideoCapture(RTSP_URL, cv2.CAP_FFMPEG)
cap.set(cv2.CAP_PROP_BUFFERSIZE, 1)
for _ in range(3):
cap.read()
ok, frame = cap.read()
cap.release()
if not ok:
print("[WARN] Frame grab failed during ascent")
time.sleep(0.1)
continue
timestamp = time.strftime("%Y%m%d_%H%M%S")
filename = f"capture_{timestamp}.jpg"
cv2.imwrite(filename, frame)
print(f"[SAVE] {filename}")
depth_m, fpx = infer_depth_meters(model, transform, frame)
if depth_m is None:
print("[ERROR] Depth estimation failed during ascent")
time.sleep(0.1)
continue
d_min = robust_min_depth(depth_m)
print(f"[ASCENT] d_min={d_min:.2f} m, ascended={ascended_height:.2f}m/{target_height}m")
Using this code, the camera captures and processes frames for depth estimation.
However, during experiments, communication issues often cause frequent errors, and frames fail to be transmitted.
Is there a way to lighten or optimize this frame processing to make it more reliable?