Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change webcam resolution using v4l2 #221

Open
rekumar opened this issue Feb 24, 2024 · 1 comment
Open

Change webcam resolution using v4l2 #221

rekumar opened this issue Feb 24, 2024 · 1 comment

Comments

@rekumar
Copy link

rekumar commented Feb 24, 2024

I have mounted a USB endoscope to the gantry and am able to capture images using the following command:

ffmpeg -y -f video4linux2 -i /dev/video2 --ss 0:0:1 -frames 1 /data/user_storage/image.jpg

Despite being a 5 megapixel camera that registers properly on my other machines, the images I'm capturing with this command are at a 160x120 resolution. I believe I need to change the format using v4l2-ctl --set-fmt-video={width}x{height}, but it looks like v4l2 is not found in this version of Linux. Adding the -s 1024x768 command in ffmpeg as per the Opentrons docs stretches the image without changing the capture resolution.

Is there a way, v4l2 or otherwise, to change the format of the webcam stream within the opentrons version of linux?

PS -- I found a group from BNL that reported using v4l2 to control the format of a Logitech webcam mounted to their OT-2. Could this be a recent change to opentrons' buildroot? For context we just received our robot in early Jan 2024.

Thank you and let me know if any more info could help!

@sfoster1
Copy link
Member

Huh. We haven't really touched anything about the webcam stuff in quite a while, and I don't think we've ever had v4l2-ctl built and installed.

You could try using this python library: https://pypi.org/project/v4l2py . Since v4l2 is fundamentally a kernel driver API, you interact with it through ioctls, and python has a really good story for that, so this library should be installable on an OT-2 and doesn't actually contain any C code and in fact should be callable from a protocol.

This will be a little more annoying to use, but it looks like what you'd do (and unfortunately this is just from the docs for me - v4l2 devices are different enough that you'll have to see what your endoscope reports) is something like this, in a python shell (including a Jupyter notebook shell on the OT-2):

>>> from v4l2py.device import Device, BufferType
>>> cam = Device.from_id(2)  # This should be the same number as /dev/videoN
>>> cam.open()
>>> print(cam.info.card)  # this should probably print the model to confirm it's the right one
>>> cam.set_format(BufferType.VIDEO_CAPTURE, width=1024, height=768)

And that should do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants