Photogrammetry using Canon super zooms - Feature Requests - CHDK Forum

Photogrammetry using Canon super zooms

  • 20 Replies
  • 11444 Views
Photogrammetry using Canon super zooms
« on: 06 / June / 2014, 22:18:02 »
Advertisements
Photogrammetry is the practice of taking measurements from photos.  Photogrammetry is highly developed for aerial photography but can also be performed using conventional cameras.  Projects such as visualSFM (Surface from Movement) are pioneering terrestrial photogrammetry.  However, what I am looking for is somewhat simpler.  I want to be able to measure the size of animals that I have photographed using just the lens focal length and subject distance as inputs.  The algorithm is the reverse of measuring distance using a dummy level.  With a dumpy level which is like a fixed telephoto lens, there is an upper and lower cross hairs.  One focuses on a surveyors staff, reads measurements for the upper and lower crosshairs and calculates the distance between the upper and lower cross hairs on the staff.  Say the result is 63 cm.  One then multiplies this by a constant which is usually 100 to get a distance of 63 m between the dummy level and the staff.  With a camera, we can know the focal length of the lens, and possibly we also know the distance to the focal plane to within a few mm when using a superzoom on an animal such as a dragonfly which may be a few metres from the camera.  Using the subject distance and the focal length and the pixel density of the camera, it should be possible to calculate a conversion factor that allows a distance to be measured in pixels and converted to real world units.  This conversion factor could be written into exif for access with a photo editor.  Such an app would be useful in architecture and many other fields.


Cheers,

Syllia.

Re: Photogrammetry using Canon super zooms
« Reply #1 on: 06 / June / 2014, 22:46:11 »
Using the subject distance and the focal length and the pixel density of the camera, it should be possible to calculate a conversion factor that allows a distance to be measured in pixels and converted to real world units. 
Clever idea !

I suspect this will all come down to the accuracy you hope to achieve.  The subject distance reading of a Canon P&S camera is not exactly a precision measurement.  It tends to go up in steps, which get larger as you focus out past about 1/3 meter or so. The depth of field on the little lenses in these cameras makes this acceptable for sharp photography.  Using it to estimate sizes at any distance is probably a risky prospect.
Ported :   A1200    SD940   G10    Powershot N    G16

Re: Photogrammetry using Canon super zooms
« Reply #2 on: 07 / June / 2014, 17:33:12 »
I had considered that limitation and thought that one could overcome it by using a super zoom camera which can be zoomed in to 50x in the case of the SX50.  This creates a narrow depth of field at a distance.  Additionally from experience, I know that objects that are a few centimetres in front of the focal plane are out of focus as are objects behind the focal plane.  The camera is also able to focus precisely on the object in the focal plane, so it does now the distance or at least how to set the lens clusters.  The first part of the photogrammetry process would be to create a focus based rangefinder, and this would have value in its own right.  As for accuracy, commercial rangefinders such as leica distos are hard to use in natural environments so there is a need for another approach.  The theory is sound and the only barrier is knowing how to write the script.

An example of one the creatures that I would like to measure is at http://mangrovecreatures.blogspot.com.au/2014/06/granddaddy-of-fiddler-crabs.html

Re: Photogrammetry using Canon super zooms
« Reply #3 on: 07 / June / 2014, 17:44:04 »
The first part of the photogrammetry process would be to create a focus based rangefinder, and this would have value in its own right.  As for accuracy, commercial rangefinders such as leica distos are hard to use in natural environments so there is a need for another approach.
You don't even need a script for the first step as you describe it.  You can have the CHDK OSD display the "subject distance" directly on the camera LCD. That will tell you where the camera thinks it has set the focus.

Quote
The theory is sound and the only barrier is knowing how to write the script.
The theory may very well be sound but, as I tried to say before, it does not appear that the cameras have continuously variable focus. The focus controller moves the focus in small discrete steps.  Whether this is accurate enough will take some analysis.  Writing a Lua script to do all this is probably the easiest part once you know what you want to do - I'll do it for you if necessary.  Sounds like it's a simple formula that combines the measured subject distance with the current zoom focal length and a ratio that calibrates an onscreen set of hash marks to the pixel pitch on the sensor ?
« Last Edit: 07 / June / 2014, 17:46:35 by waterwingz »
Ported :   A1200    SD940   G10    Powershot N    G16


Re: Photogrammetry using Canon super zooms
« Reply #4 on: 07 / June / 2014, 18:34:47 »
It would take me a few days to learn the skills required to write the script so I appreciate your offer.  The first step would be to confirm that a superzoom camera can be used as a rangefinder.  The way to do this would be for me to use a 30 m tape measure to place post-it notes on the ground with distance written on them.  I would then photograph the post-it notes.  Perhaps the return from the lua get_dofinfo() could be written out to the comment field in the EXIF data as I retrieve this with a photo editor and compare the values to the value written into the image.  As post-it notes are fixed width, I could then attempt to measure the width of the post-it note.  There is a standard formula for this but it requires the size of the post-it note as it is projected on the image sensor.  I would have to calculate a scaling factor based on the number of pixels covered by the post-it note, which should not be too hard.  I would be willing to make a $20 contribution to the site for the script.

Cheers,

Syllia

*

Offline reyalp

  • ******
  • 14118
Re: Photogrammetry using Canon super zooms
« Reply #5 on: 07 / June / 2014, 20:08:43 »
Perhaps the return from the lua get_dofinfo() could be written out to the comment field in the EXIF dat
We don't currently have an easy way to modify jpeg exif. You can do it after the shot with Lua file IO, it is fairly complicated. However, it is easy to make an external log with images numbers that you can match up later.

Quote
There is a standard formula for this but it requires the size of the post-it note as it is projected on the image sensor.
As waterwingz says, the real question is how accurately you can get the distance. Most of these cameras have a large depth of field, but maybe the SX50 at high zoom might be good enough for your needs.

Another thing to watch out for is distortion in the optics, the apparent size of an object at a given distance may vary across the FOV. Furthermore, the Canon firmware attempts to correct for this in software, so the raw and jpeg may be very different. I would expect this to be more of an issue at wide angles though.

A somewhat related note, it is possible to build a depth map from a series of images at different focus distances. Google e.g. depth from defocus. These sorts of techniques would likely give you better estimate than the subject distance, and a simple focus bracket could give you the input data.
Don't forget what the H stands for.

Re: Photogrammetry using Canon super zooms
« Reply #6 on: 07 / June / 2014, 20:21:23 »
The first step would be to confirm that a superzoom camera can be used as a rangefinder.  The way to do this would be for me to use a 30 m tape measure to place post-it notes on the ground with distance written on them.  I would then photograph the post-it notes.   Perhaps the return from the lua get_dofinfo() could be written out to the comment field in the EXIF data as I retrieve this with a photo editor and compare the values to the value written into the image. 
Writing dof info to the exif comment field is certainly possible. However, before going to even that much effort,  you should be able to setup your test (camera on a tripod or other mount), focus on each post-it note, and simply check the displayed Subject Distance value (see my previous comment).  If it's not close enough for your project, you've learned something with minimal effort.

Writing it down with pencil and paper should be enough to take you through the next steps.

Once you've answered the question about camera SD resolution vs the needs of your project, rolling together a script is 10 minutes of writing and (normally) an hour or so of debugging and testing.


Quote
As post-it notes are fixed width, I could then attempt to measure the width of the post-it note.  There is a standard formula for this but it requires the size of the post-it note as it is projected on the image sensor.  I would have to calculate a scaling factor based on the number of pixels covered by the post-it note, which should not be too hard. 
Makes sense.

Quote
I would be willing to make a $20 contribution to the site for the script.
I'm not sure that there is any way to do that, and it is really not necessary.  But if things work out, you could contact acseven via PM - he "hosts" this forum
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Photogrammetry using Canon super zooms
« Reply #7 on: 07 / June / 2014, 20:49:39 »
Perhaps the return from the lua get_dofinfo() could be written out to the comment field in the EXIF dat
We don't currently have an easy way to modify jpeg exif. You can do it after the shot with Lua file IO, it is fairly complicated. However, it is easy to make an external log with images numbers that you can match up later.

I'm testing a mod to add the 'SubjectDistance' tag to the DNG EXIF data, so at least it would be available in CHDK DNG files. For close focus distances it's fairly accurate.

Canon write a custom tag called FocusDistanceUpper to the Canon 'Maker' section of the JPEG files; but from what I can see this is the subject distance value truncated down to the nearest centimeter.

Phil.
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)


Re: Photogrammetry using Canon super zooms
« Reply #8 on: 07 / June / 2014, 21:03:18 »
We don't currently have an easy way to modify jpeg exif. You can do it after the shot with Lua file IO, it is fairly complicated.

I'm testing a mod to add the 'SubjectDistance' tag to the DNG EXIF data, so at least it would be available in CHDK DNG files. For close focus distances it's fairly accurate.

I was thinking that this would cover it : http://chdk.wikia.com/wiki/Lua#TagMe.2C_the_Lua_EXIF_tagger
Ported :   A1200    SD940   G10    Powershot N    G16

*

Offline philmoz

  • *****
  • 3450
    • Photos
Re: Photogrammetry using Canon super zooms
« Reply #9 on: 07 / June / 2014, 21:19:51 »
We don't currently have an easy way to modify jpeg exif. You can do it after the shot with Lua file IO, it is fairly complicated.

I'm testing a mod to add the 'SubjectDistance' tag to the DNG EXIF data, so at least it would be available in CHDK DNG files. For close focus distances it's fairly accurate.

I was thinking that this would cover it : http://chdk.wikia.com/wiki/Lua#TagMe.2C_the_Lua_EXIF_tagger

Wouldn't you need to be shooting with a script for that to work, in order for the script to get the subject distance value?

Writing the SD value to the DNG EXIF means it's available for calculating values at any time (either on the camera, or on a PC).

Phil.
 
CHDK ports:
  sx30is (1.00c, 1.00h, 1.00l, 1.00n & 1.00p)
  g12 (1.00c, 1.00e, 1.00f & 1.00g)
  sx130is (1.01d & 1.01f)
  ixus310hs (1.00a & 1.01a)
  sx40hs (1.00d, 1.00g & 1.00i)
  g1x (1.00e, 1.00f & 1.00g)
  g5x (1.00c, 1.01a, 1.01b)
  g7x2 (1.01a, 1.01b, 1.10b)

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal