Autofocus not working on new IMX219 cameras with fswebcam for OCR in Linux Mint 21

Hi all, hoping someone can point me in the right direction. We just bought 5 more IMX219 cameras and none of them will autofocus. Our existing lab setup uses 5 IMX219s and they’ve been running fine for months with no issues at all. The use case is OCR - we read a 4-digit PIN from a 16x12 LCD display from about 1.5 inches away. The camera sits in a custom 3D printed mount, and the only light source is the LCD itself. All 5 of the new cameras show the exact same problem (images attached below).

Thanks for the detailed report. To narrow this down, could you share a bit more about the environment? What OS and capture software are you using on the Linux side, and what device node does the camera come up as? Also, have you had a chance to test any of the five new cameras on Windows with Amcap to see how autofocus behaves there?

Sure. Platform is Linux Mint 21, camera is the IMX219, and I’m capturing with fswebcam on /dev/video0. I’ve also tested with amcap on Windows. Here’s the exact fswebcam command I’m using:

fswebcam -d /dev/video0 -r 640x480 --skip 200 --set sharpness=5 --set “Focus, Auto”=False --set “Focus (absolute)”=50 --no-banner testfocus.jpg

Got it. On the Amcap side, can you confirm specifically whether autofocus works with the five new cameras under Amcap.exe? The autofocus checkbox isn’t checked by default, so just make sure you’re observing the actual focus behavior. That will help us figure out whether this is a firmware difference or something on the software side.

Okay, so under Amcap.exe autofocus actually works - the checkbox isn’t checked by default but it still focuses. With exposure/focus adjustments I get a faint but workable image. On Linux with fswebcam it’s a different story. Things I’ve already tried: multiple fswebcam option combinations (same result), changed computers, swapped cameras, changed the USB cable. At this point I’m wondering if there was a firmware change on these newer units, or if there’s a way to change the autofocus behavior. Also open to another camera model, but it has to be the exact same physical size because our custom mounts are already made. Does Arducam support fswebcam at all, or is there better software I should be using? Images below for comparison - sample (working) vs one of the new cameras (all 5 look like this).

Sample: image002.png
NEW Camera x5: image003.png
Screenshot: image001.png

Thanks, that’s really useful. Since autofocus works under Amcap on the new units, the cameras themselves can focus - this points to a suspected firmware difference between your original working IMX219 and the five new units rather than a pure hardware fault. All five behaving identically makes that more likely.

What I’d suggest as a first trial: burn new firmware into one of the five cameras and see if that changes the Linux behavior. If that still fails, the second step is to extract the firmware from your known-working camera and burn that into one of the new ones.

I’ve sent the burn tool, the firmware file, and the guide video through private message - check your messages for the links. The guide folder also contains a video showing how to extract firmware from the old working camera and burn it to a new one.

For manual focus of an autofocus camera under OpenCV on Linux, this doc has demo code worth referencing: Access UVC Cameras using OpenCV, Python, and GStreamer on Linux - Arducam Wiki

Appreciate it. Just to be clear on the Linux side, this is the exact command I’ve been running:

fswebcam -d /dev/video0 -r 640x480 --skip 200 --set sharpness=5 --set “Focus, Auto”=False --set “Focus (absolute)”=50 --no-banner testfocus.jpg

Before I go down the firmware route, is fswebcam actually supported? If not, are there alternative commands/software you’d recommend trying first? And just to reiterate - any alternative camera model has to be the exact same physical size since we’ve already purchased custom mounts.

Quick recap of where we are: autofocus is confirmed working on the new units under Amcap.exe on Windows, so the hardware can focus. The problem shows up on Linux Mint 21 with fswebcam, and all five new cameras behave identically while the original unit works. That points to a firmware difference between the original and the newer batch.

Current plan:

  1. Burn the new firmware I sent via private message into one of the five cameras and test on Linux.
  2. If it still misbehaves, extract the firmware from your known-working camera (guide video is in the same PM) and burn that into one of the new cameras.
  3. For manual focus on Linux, check the OpenCV demo code at the link above - it covers controlling focus of an autofocus camera, which is a better path than fighting fswebcam’s set options.

On the fswebcam question: it’s not something we validate extensively, and its UVC control support is limited. If you can share the results after the firmware trial, we can figure out next steps from there. And yes, any alternative model would need to match the current dimensions for your existing mounts.