Idk
This commit is contained in:
@@ -5,10 +5,12 @@ from helper import compute_distance
|
||||
from hud import find_hud_placement
|
||||
import math
|
||||
|
||||
from config import CAMERA_INDICES, FRAME_WIDTH, FRAME_HEIGHT, PIXELS_PER_INCH, CIRCLE_TOUCH_THRESHOLD
|
||||
from config import PIXELS_PER_INCH, CIRCLE_TOUCH_THRESHOLD
|
||||
from config import FRAME_INTERVAL, TARGET_FPS
|
||||
from config import DEBUG
|
||||
|
||||
from hud import draw_hud_box, draw_pdf_page
|
||||
from setup import InitCameras
|
||||
#from hud import draw_hud_box, draw_pdf_page
|
||||
import time
|
||||
|
||||
# ----- Global State -----
|
||||
measuring = False # measurement in progress
|
||||
@@ -22,7 +24,7 @@ hud_rot = None
|
||||
register_hud = False
|
||||
|
||||
# ----- Per-camera Processing -----
|
||||
def process_frame(frame):
|
||||
def process_frame(frame, camera_id: int = 0):
|
||||
global measuring, start_pt, calibrating
|
||||
global object_calibrating
|
||||
global fingertip_idx_global
|
||||
@@ -53,8 +55,6 @@ def process_frame(frame):
|
||||
else:
|
||||
res = hud_pos, hud_rot
|
||||
|
||||
|
||||
|
||||
# create proj output
|
||||
projection_out = np.zeros_like(frame)
|
||||
|
||||
@@ -76,8 +76,8 @@ def process_frame(frame):
|
||||
|
||||
dx, dy = dir_vec
|
||||
arrow_angle = math.atan2(dy, dx) # result in radians
|
||||
quad = draw_hud_box(projection_out, arrow_tip, arrow_angle, size=(400,400))
|
||||
draw_pdf_page(projection_out, page_index=0, dst_quad=quad)
|
||||
#quad = draw_hud_box(projection_out, arrow_tip, arrow_angle, size=(400,400))
|
||||
#draw_pdf_page(projection_out, page_index=0, dst_quad=quad)
|
||||
|
||||
if register_hud:
|
||||
hud_pos = arrow_tip
|
||||
@@ -92,31 +92,30 @@ def process_frame(frame):
|
||||
|
||||
# ----- Main ----- -------------------------------------------------------------------------------------
|
||||
def main():
|
||||
all_captures = []
|
||||
for idx in CAMERA_INDICES:
|
||||
capture = cv2.VideoCapture(idx)
|
||||
capture.set(cv2.CAP_PROP_FRAME_WIDTH, FRAME_WIDTH)
|
||||
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, FRAME_HEIGHT)
|
||||
all_captures.append(capture)
|
||||
if not all(capture.isOpened() for capture in all_captures):
|
||||
print("Error: could not open all cameras")
|
||||
return
|
||||
|
||||
all_captures = InitCameras()
|
||||
|
||||
print(f"Running at up to {TARGET_FPS} FPS (interval={FRAME_INTERVAL:.3f}s)")
|
||||
print("Press 'o' for circle calib, 'q' to quit.")
|
||||
while True:
|
||||
frames = [capture.read()[1] for capture in all_captures]
|
||||
frame = next((f for f in frames if f is not None), None)
|
||||
|
||||
if frame is None:
|
||||
last_time = time.time()
|
||||
while True:
|
||||
processed_frames = []
|
||||
|
||||
for camera_id, capture in enumerate(all_captures):
|
||||
ok, frame = capture.read()
|
||||
if not ok or frame is None:
|
||||
continue
|
||||
|
||||
projection, debug = process_frame(frame, camera_id)
|
||||
processed_frames.append((camera_id, projection, debug))
|
||||
|
||||
if not processed_frames:
|
||||
break
|
||||
|
||||
# process
|
||||
projection, debug = process_frame(frame)
|
||||
|
||||
# show windows
|
||||
if DEBUG:
|
||||
cv2.imshow('Debug Output', debug)
|
||||
cv2.imshow('Projector Output', projection)
|
||||
for camera_id, projection, debug in processed_frames:
|
||||
if DEBUG:
|
||||
cv2.imshow(f'Debug Output (cam {camera_id})', debug)
|
||||
cv2.imshow(f'Projector Output (cam {camera_id})', projection)
|
||||
|
||||
key = cv2.waitKey(1) & 0xFF
|
||||
|
||||
@@ -131,10 +130,18 @@ def main():
|
||||
register_hud = True
|
||||
hud_pos = None
|
||||
|
||||
# ——— frame‐rate limiting ———
|
||||
now = time.time()
|
||||
elapsed = now - last_time
|
||||
to_wait = FRAME_INTERVAL - elapsed
|
||||
if to_wait > 0:
|
||||
time.sleep(to_wait)
|
||||
last_time = time.time()
|
||||
|
||||
for capture in all_captures:
|
||||
capture.release()
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user