Determining focus distance ... - DSLR Hack development - CHDK Forum supplierdeeply

Determining focus distance ...

  • 12 Replies
  • 7427 Views
Determining focus distance ...
« on: 30 / November / 2011, 03:58:22 »
Advertisements
I am new to the CHDK and looking for some information. Is it possible using the CHDK hacks for Canon DSLRs and/or magic lantern?, it is possible to implement the following function (in line view mode):

1. Move the focus box to all allowed positions one-by-one
2. At each position, perform autofocus and then read the distance information from the lens (assuming the lens supports it)
3. At the end dump this list of distances

I can dive into the hacks to implement the functionality, but first want to understand if we have enough control to implement something of this nature
« Last Edit: 30 / November / 2011, 04:00:58 by rhameed »

Re: Determining focus distance ...
« Reply #1 on: 30 / November / 2011, 10:11:54 »
Reporting from the 400D hack (I have absolutely no idea about other cameras, by the way): our camera has no live-view or focus-by-contrast (only phase-detection), so you would be limited to the 9 focusing points using your technique; I guess this is not useful at all...

On a side note, if I wanted to create a depth map, I would try the following:

* Use a ML-enabled camera.
* Create a focus-stack, for all possible focusing distances.
* Use "enfuse" to determine which pixels are in-focus on each image, and guess its depth from there.

Just my two cents.

Re: Determining focus distance ...
« Reply #2 on: 01 / December / 2011, 00:56:19 »
Thanks for your input!. The method that you have described would be my first choice but I didn't know that there is enough support to do that.

I assume when you say ML-enabled, you are referring to cameras supported by Magic Lantern (excuse my ignorance :)). And in this case something like a T2i should do the job, right?

Re: Determining focus distance ...
« Reply #3 on: 01 / December / 2011, 01:45:05 »
Thanks for your input!. The method that you have described would be my first choice but I didn't know that there is enough support to do that.

I assume when you say ML-enabled, you are referring to cameras supported by Magic Lantern (excuse my ignorance :)). And in this case something like a T2i should do the job, right?

Well, I do not know about anybody else that has done this before, so I would not call it "supported"... after all, you will be using something that was designed for macro photography to do something completely different; but I do not see why it wouldn't work.

And yes, with ML-enabled I was referring to any camera with Magic Lantern installed; in principle, a T2i should do, all you need is the "Stack Focus" functionality. I would be more concerned about the lens, however: first, because you will want to have the smallest depth of field possible; but also because not all lenses send the focusing distance to the camera (I think you could still make a "relative depth map", but not an "absolute depth map").

Then comes the software part: enfuse can merge stacks, and can export the masks it uses internally; in theory, with the masks and the focusing distance of each file (it can be obtained from the EXIF information) you have all you need to do a depth field.

Give me a couple of days, and I will try to make a quick test at home.


Re: Determining focus distance ...
« Reply #4 on: 01 / December / 2011, 04:36:49 »
Yes the lens part is important - based on the research that I did most lenses report distance at a fairly coarse resolution (the whole focus range might be divided into as low as 7-10 'distance bins'). And the resolution is specially worse at longer distances. The higher-end lenses seem to be able to report at a finer scale. Someone at exiftool forum was able to give me the exact focus distances steps for the EF-S 17-55mm lenses which seems to have a good enough resolution for my purposes. And yes I don't need an exact depth map, a sort of relative one with coarse distance information is fine.

I looked up a bit on focus stacking using magic lantern and it is not clear to me that what is granularity of a focus step during focus stacking . In theory it may not even be required to use the distance information from the lens. The focus step count is in itself a measure of the distance if calibrated properly.

Re: Determining focus distance ...
« Reply #5 on: 01 / December / 2011, 05:07:09 »
Yes the lens part is important - based on the research that I did most lenses report distance at a fairly coarse resolution (the whole focus range might be divided into as low as 7-10 'distance bins'). And the resolution is specially worse at longer distances. The higher-end lenses seem to be able to report at a finer scale. Someone at exiftool forum was able to give me the exact focus distances steps for the EF-S 17-55mm lenses which seems to have a good enough resolution for my purposes. And yes I don't need an exact depth map, a sort of relative one with coarse distance information is fine.

I looked up a bit on focus stacking using magic lantern and it is not clear to me that what is granularity of a focus step during focus stacking . In theory it may not even be required to use the distance information from the lens. The focus step count is in itself a measure of the distance if calibrated properly.

The 17-55 is a 2.8 lens, and I guess you will be using it on the long end of the zoom. Have you considered the 50mm f/1.8 instead? Much cheaper, almost the same focal length, and a much wider aperture; the depth of field is very narrow with this lens (I plan to do my tests with this it, by the way).

Re: Determining focus distance ...
« Reply #6 on: 01 / December / 2011, 05:51:14 »
While you are right about the narrower DOF of the 50mm 1.8 lens, the issue is that it is not likely to report the focus distance at a fine enough resolution. From what I have learnt the focus distance is determined by little sensors placed on various points on the focus ring and cheaper lenses tend to have fewer of these sensors and thus less precise distance info. Even though as you said the shallower DOF of the prime should make it easier to judge in-fcous versus out-of-focus areas at any given focus distance.

Re: Determining focus distance ...
« Reply #7 on: 01 / December / 2011, 06:31:07 »
Sorry, I misunderstood you where going to use the position in the stack to determine the distance.


*

Offline a1ex

  • *****
  • 671
  • ML dev
Re: Determining focus distance ...
« Reply #8 on: 01 / December / 2011, 07:05:20 »
You want to extract depth information from some static scene, right?

As suggested before, focus stacking from Magic Lantern may help. The smallest focus step is the lowest focus increment in EOS utility, in LiveView (this is very small, usually the focus change is barely noticeable, even with 50/1.8 lens).

You can also write down the focus distance (as reported by the lens) and interpolate it using raw focus steps, to get a better resolution. The relationship between raw focus steps and physical distance is nonlinear.

Re: Determining focus distance ...
« Reply #9 on: 01 / December / 2011, 14:44:22 »
Is the scene static ?

I am sure you will be aware of many of the papers published regarding depth maps from a single camera.

Here is one http://vision.ai.uiuc.edu/?p=320

 

Related Topics