fix: no cam detected on Arch Linux, use string path for camera capture instead#1783
Open
Vito-M wants to merge 1 commit intohacksider:mainfrom
Open
fix: no cam detected on Arch Linux, use string path for camera capture instead#1783Vito-M wants to merge 1 commit intohacksider:mainfrom
Vito-M wants to merge 1 commit intohacksider:mainfrom
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideThis PR fixes camera detection on Linux by switching OpenCV capture initialization to use explicit /dev/videoN string paths on Linux both when starting capture and when probing for available cameras, while preserving the existing auto-detection behavior on macOS and not affecting Windows logic. Sequence diagram for Linux camera detection in get_available_camerassequenceDiagram
actor User
participant UI as UI_layer
participant Cam as get_available_cameras
participant CV2 as cv2
User ->> UI: Open camera selection
UI ->> Cam: get_available_cameras()
Cam ->> Cam: Detect platform
Cam ->> Cam: platform != Windows and platform == Linux
loop Probe first 10 indices
Cam ->> CV2: VideoCapture(/dev/video{i})
CV2 -->> Cam: cap object
Cam ->> CV2: cap.isOpened()
CV2 -->> Cam: True/False
alt cap is opened
Cam ->> Cam: Append i to camera_indices
Cam ->> Cam: Append Camera i to camera_names
end
end
Cam -->> UI: camera_indices, camera_names
UI -->> User: Display list of detected cameras
Flow diagram for Linux camera start logic in video_capture.startflowchart TD
A[start] --> B[Check platform.system]
B --> C{platform == Windows}
C -->|Yes| D[Use DirectShow or existing Windows capture logic]
C -->|No| E{platform == Linux}
E -->|Yes| F[Create cv2.VideoCapture with path /dev/video{device_index}]
E -->|No| G[Create cv2.VideoCapture with device_index for macOS]
F --> H{cap exists and cap.isOpened}
G --> H
D --> H
H -->|No| I[Raise RuntimeError Failed to open camera]
H -->|Yes| J[Return True]
I --> K[end]
J --> K
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
elsebranch invideo_capture.startis labeled as macOS-specific but will also run on any other non-Windows, non-Linux Unix platforms; consider making the macOS check explicit (e.g.platform.system() == 'Darwin') or updating the comment to reflect the actual behavior. - For Linux, you now assume
/dev/video{index}exists both when opening and probing cameras; adding anos.path.existscheck (or similar) before constructing/using the device path would avoid unnecessaryVideoCaptureattempts on non-existent devices and make failures easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `else` branch in `video_capture.start` is labeled as macOS-specific but will also run on any other non-Windows, non-Linux Unix platforms; consider making the macOS check explicit (e.g. `platform.system() == 'Darwin'`) or updating the comment to reflect the actual behavior.
- For Linux, you now assume `/dev/video{index}` exists both when opening and probing cameras; adding an `os.path.exists` check (or similar) before constructing/using the device path would avoid unnecessary `VideoCapture` attempts on non-existent devices and make failures easier to reason about.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On the latest version of Arch Linux, the camera was no longer being detected at startup, causing the application to fail to list any available capture devices.
The fix passes the device path as a string (e.g.
/dev/video0) directly, which resolves the issue on Arch Linux while preserving the existing behavior on other platforms (Windows/macOS).Summary by Sourcery
Update Linux camera handling to open devices via their /dev/videoN path instead of numeric indices and keep existing behavior for other platforms.
Bug Fixes:
Enhancements: