Skip to content

Commit

Permalink
adding handling for autodiscover when no cameras are plugged in (#10)
Browse files Browse the repository at this point in the history
* adding handling for autodiscover when no cameras are plugged in

* Automatically reformatting code with black and isort

* fixing comment

* Bumping version to 0.3.2

---------

Co-authored-by: Auto-format Bot <[email protected]>
  • Loading branch information
timmarkhuff and Auto-format Bot authored Aug 10, 2023
1 parent bbad331 commit 7733c3f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ for grabber in grabbers.values():
```
### Configurations
The table below shows all available configurations and the cameras to which they apply.
| Configuration Name | Example | Webcam | RTSP | Basler | Realsense |
| Configuration Name | Example | Generic USB | RTSP | Basler | Realsense |
|----------------------------|-----------------|------------|-----------|-----------|-----------|
| name | On Robot Arm | optional | optional | optional | optional |
| input_type | generic_usb | required | required | required | required |
Expand Down Expand Up @@ -242,6 +242,6 @@ We welcome contributions to FrameGrab! If you would like to contribute, please f

## License

FrameGrab is released under the MIT License. For more information, please refer to the [LICENSE](LICENSE) file.
FrameGrab is released under the MIT License. For more information, please refer to the [LICENSE.txt](LICENSE.txt) file.


2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "framegrab"
version = "0.3.1"
version = "0.3.2"
description = "Easily grab frames from cameras or streams"
authors = ["Groundlight <[email protected]>"]
license = "MIT"
Expand Down
16 changes: 10 additions & 6 deletions src/framegrab/grabber.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,15 +468,19 @@ def _find_cameras() -> list:
command = "ls /dev/video*"
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, _ = process.communicate()
output = stdout.decode("utf-8")
devices = output.strip().split("\n")

if len(stdout) == 0: # len is zero when no cameras are plugged in
device_paths = []
else:
output = stdout.decode("utf-8")
device_paths = output.strip().split("\n")

found_cams = []
for devpath in devices:
for device_path in device_paths:
# ls -l /sys/class/video4linux/video0/device returns a path that points back into the /sys/bus/usb/devices/
# directory where can determine the serial number.
# directory where we can determine the serial number.
# e.g. /sys/bus/usb/devices/2-3.2:1.0 -> /sys/bus/usb/devices/<bus>-<port>.<subport>:<config>.<interface>
devname = devpath.split("/")[-1]
devname = device_path.split("/")[-1]
command = f"ls -l /sys/class/video4linux/{devname}/device"
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
stdout, _ = process.communicate()
Expand All @@ -496,7 +500,7 @@ def _find_cameras() -> list:
found_cams.append(
{
"serial_number": serial_number,
"devname": f"/dev/{devname}",
"device_path": device_path,
"idx": idx,
}
)
Expand Down

0 comments on commit 7733c3f

Please sign in to comment.