awacke1 commited on
Commit
c4e1a06
·
verified ·
1 Parent(s): 400ee5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -8
app.py CHANGED
@@ -333,11 +333,27 @@ def update_gallery():
333
 
334
  def get_available_video_devices():
335
  video_devices = []
 
336
  for i in range(10):
337
- cap = cv2.VideoCapture(i)
 
 
338
  if cap.isOpened():
339
  video_devices.append(f"Camera {i}")
 
340
  cap.release()
 
 
 
 
 
 
 
 
 
 
 
 
341
  return video_devices
342
 
343
  def mock_search(query: str) -> str:
@@ -536,18 +552,18 @@ with tab2:
536
  st.header("Camera Snap 📷 (Dual Capture!)")
537
  video_devices = get_available_video_devices()
538
  st.subheader("Camera Settings ⚙️")
539
- if not video_devices:
540
- st.warning("No video devices detected by OpenCV! 📷 Browser may still access cameras; ensure permissions are granted.")
541
  else:
542
  st.write(f"Detected Video Devices: {', '.join(video_devices)}")
543
 
544
  # Camera selection with defaults
545
- default_cam0_index = 0 if video_devices else -1
546
- default_cam1_index = 1 if len(video_devices) > 1 else (0 if video_devices else -1)
547
- selected_cam0 = st.selectbox("Select Camera 0", video_devices or ["Browser Default"], index=default_cam0_index if video_devices else 0, key="cam0_select")
548
- selected_cam1 = st.selectbox("Select Camera 1", video_devices or ["Browser Default"], index=default_cam1_index if video_devices else 0, key="cam1_select")
549
 
550
- st.info("Note: Camera selection is informational. Actual device used depends on browser settings.")
551
 
552
  slice_count = st.number_input("Image Slice Count 🎞️", min_value=1, max_value=20, value=10, help="How many snaps to dream of? (Automation’s on vacation! 😜)")
553
  video_length = st.number_input("Video Dream Length (seconds) 🎥", min_value=1, max_value=30, value=10, help="Imagine a vid this long—sadly, we’re stuck with pics for now! 😂")
 
333
 
334
  def get_available_video_devices():
335
  video_devices = []
336
+ # Try V4L2 explicitly, then fall back to default backend
337
  for i in range(10):
338
+ cap = cv2.VideoCapture(i, cv2.CAP_V4L2)
339
+ if not cap.isOpened():
340
+ cap = cv2.VideoCapture(i) # Try default backend
341
  if cap.isOpened():
342
  video_devices.append(f"Camera {i}")
343
+ logger.info(f"Detected camera at index {i}")
344
  cap.release()
345
+ else:
346
+ logger.debug(f"No camera detected at index {i}")
347
+ if not video_devices:
348
+ logger.warning("No cameras detected by OpenCV. Checking system devices...")
349
+ # Fallback: Check /dev/video* existence (Linux-specific)
350
+ video_nodes = glob.glob("/dev/video*")
351
+ if video_nodes:
352
+ video_devices = [f"Camera {i}" for i in range(len(video_nodes))]
353
+ logger.info(f"Found video nodes: {video_devices}")
354
+ else:
355
+ video_devices = ["Camera 0", "Camera 1"] # Default fallback for UI
356
+ logger.warning("No /dev/video* nodes found; using default Camera 0 and 1")
357
  return video_devices
358
 
359
  def mock_search(query: str) -> str:
 
552
  st.header("Camera Snap 📷 (Dual Capture!)")
553
  video_devices = get_available_video_devices()
554
  st.subheader("Camera Settings ⚙️")
555
+ if not any("Camera" in dev for dev in video_devices):
556
+ st.warning("No video devices detected by OpenCV! 📷 Browser capture still active. Check logs and permissions (e.g., 'sudo usermod -aG video $USER').")
557
  else:
558
  st.write(f"Detected Video Devices: {', '.join(video_devices)}")
559
 
560
  # Camera selection with defaults
561
+ default_cam0_index = 0 if video_devices else 0 # Default to Camera 0 or first fallback
562
+ default_cam1_index = 1 if len(video_devices) > 1 else 0 # Default to Camera 1 or same as Cam 0
563
+ selected_cam0 = st.selectbox("Select Camera 0", video_devices, index=default_cam0_index, key="cam0_select")
564
+ selected_cam1 = st.selectbox("Select Camera 1", video_devices, index=default_cam1_index, key="cam1_select")
565
 
566
+ st.info("Note: Camera selection is informational. Actual device used depends on browser settings. Configure in browser (e.g., Chrome > Settings > Privacy > Camera).")
567
 
568
  slice_count = st.number_input("Image Slice Count 🎞️", min_value=1, max_value=20, value=10, help="How many snaps to dream of? (Automation’s on vacation! 😜)")
569
  video_length = st.number_input("Video Dream Length (seconds) 🎥", min_value=1, max_value=30, value=10, help="Imagine a vid this long—sadly, we’re stuck with pics for now! 😂")