Improving tethering live view zoom and focus

Hello I am an avid user of Darktable and I am so grateful for its existence and all the hard work that goes into building and maintaining free and open source software! :clap:

I am currently using Darktable to digitize negatives, using a camera on a copy stand + Darktable tethering + the negadoctor module. It works great! I am curious about improving some aspects of the process, and looking for pointers from Darktable developers for where to start. I am generally comfortable finding my way around code, and would like to contribute back to the project if I am able to.

There are two things in particular that I am interested in improving:

1. Live view zoom

I would like to be able to zoom in more. I come from a background in traditional darkroom printing, and I miss the precision of grain focusers. I understand that the maximum precision of software like Darktable will depend on the camera and lens employed, so there are some limitations inherent in the physical sensor/glass. But it seems that the software zoom could go farther, and I’m curious to experiment with that and find out where the useful limits are for my purposes. Darktable currently provides 50% zoom and 100% zoom (as I understand it).

What would it take to allow zooming beyond 100%? Furthermore, what would it take to allow zooming at variable levels using the mouse scroll wheel, like you can do in Darkroom mode?

2. Live view focus detection

In Darkroom mode, there is an option to “toggle focus-peaking mode” to highlight areas of the image that are in focus. Reference: darktable 4.9 user manual - focus peaking

What would it take to make this available in tethering live-view? I found this old GitHub issue that was marked as “trivial”, but closed automatically due to a lack of activity: tethering live view: detect focus and highlight it · Issue #3976 · darktable-org/darktable · GitHub

To give a little more context as to why I am interested in this… I am using an old high quality macro lens with bellows attached to a digital camera via adapter. The lens is manually focused by making slight adjustments to the focal length via the bellows. It would be immensely helpful to leverage software focus detection to aid in the focusing process.

I would greatly appreciate any advice, ideas, or pointers that others in the community provide! Thanks again for this great piece of software!

Or alternatively, is anyone aware of other open source software that provides camera tethering with live view and focus peaking? This would at least allow me to achieve focus outside of Darktable, and then take the picture in Darktable.

I tried Entangle, but it does not provide focus peaking (as far as I can tell).

Does gphoto provide focus peaking?

1 Like

I don’t see anything specifically about focus peaking in gphoto2 CLI options.

I found this which uses OpenCV that might be worth testing: GitHub - GreenpantsDeveloper/focus-peaking: A Python implementation of focus peaking, using the video stream of an attached camera

Hi, yep darktable is great.
Can’t speak to tethering with dt cos it don’t work on windoze but -

  1. Control & scroll to extend zoom. Just be aware much over 200% will pixalate so diminishing returns.
  2. If you shoot canon you could load magic lantern onto the card. Among much else it will give you live view focus peaking
1 Like

This works great in Darkroom mode, but unfortunately ctrl + scroll does not zoom in Tethering mode. I wish it did! And would love to understand what it would require (in the code) to implement it.

Thanks for the reminder about Magic Lantern! I heard about it a while ago but I’ve never tried it.

I would love to understand what is necessary to implement focus peaking directly in Darktable Tethering mode, because then I can do it on a big screen. :slight_smile:

Update: This library seems promising! You simply run the Python script from the command line, and a UI window appears with a live video feed of the default video device (my laptop’s webcam), with red lines to indicate focus peaking.

After some experimentation, I figured out how to wire it up to use my digital camera connected via USB instead of the default laptop webcam. I made one small change to line 47, so that it passes the cv2.CAP_GPHOTO2 flag to cv2.VideoCapture(). This tells OpenCV to use gphoto2, which automatically finds the digital camera! :rocket:

However, there is still one issue to iron out. Rather than showing a live video feed from the digital camera’s sensor, it is triggering the camera’s shutter and taking a series of photographs every second or so, and displaying the still images where the live video feed would be. So I need to figure out how to make it use the live view video feed rather than taking still images.

Feels like I’m getting closer… !

1 Like

Update: I found a way to accomplish this, with a slightly different approach.

Using gphoto2 from the command line with the --capture-movie and --stdout flags, it’s possible to pipe the live view camera sensor output into ffmpeg and stream it to /dev/video2. Then, focus-peaking.py can be edited to capture video from there via cv2.VideoCapture("/dev/video2"), without the need for the cv2.CAP_GPHOTO2 flag.

It works perfectly! I’m able to get a live-view from my camera’s sensor, with configurable focus peaking, and the ability to zoom in beyond 100%. So everything I wanted to accomplish directly in Darktable can be achieved, albeit outside of Darktable. It just means that I can use this gphoto2 + ffmpeg + focus-peaking.py to fine tune my manual focusing, and then use Darktable to capture the final RAW image.

It would be great if Darktable itself offered focus peaking in tethering live view and the ability to zoom beyond 100%, but for now this gets me what I need.

For reference, here is the exact command I used to stream my camera’s live view to /dev/video2:

gphoto2 --capture-movie --stdout | ffmpeg -i pipe:0 -vf format=yuv420p -f v4l2 /dev/video2