CHDKPTP remotshoot focus - page 2 - General Discussion and Assistance - CHDK Forum

CHDKPTP remotshoot focus

  • 28 Replies
  • 5881 Views
Re: CHDKPTP remotshoot focus
« Reply #10 on: 04 / February / 2021, 00:00:51 »
Advertisements
Quote
Not sure if it's a mispaste, but the above still has -sdmode=MF (which we appear to have verified as broken), not -sdmode=AFL

No, that wasn't a mispaste, I think MF is working and I was using it.

I think I've figured it out.

I've been test shooting with this command:

Code: [Select]
remoteshoot "c:\\users\\dave\\Desktop\\test2147483647mm" -u=96 -av=288 -tv=480 -sv=384 -sdmode=MF -sd=2147483647mm
The problem, I think, is that CHDK PTP doesn't like "sd=2147483647mm".  (That value is sys.maxint in 32 bit Python - it's 2^31-1)

When I shoot using -sdmode=MF and -sd=2147483647mm, it appears that the camera leaves focus wherever it was on the previous shot.

If the previous shot used -sd=1mm, the next shot using -sd=2147483647mm is ALSO focused at 1mm.

If the previous shot was focused at infinity, the next shot using -sd=2147483647mm is ALSO focused at infinity.

I didn't expect that and it confused me.

I'm not sure exactly why it does that (other than a general suspicion about handing 32 bit integers), but below I'm pasting in the output from exiftool (exceprts; this board won't let me post > 7500 characters), from two shots using the identical command line:

Code: [Select]
remoteshoot "c:\\users\\dave\\Desktop\\test2147483647mm" -u=96 -av=288 -tv=480 -sv=384 -sdmode=MF -sd=2147483647mm
(the 2nd shot added a "b" on the end of the filename - otherwise identical).

The photos are focused completely differently - the first is way out of focus, which fits with exiftool reporting Focus Distance Upper            : 0.06 m", and the second is much better, consistent with "Focus Distance Upper            : 65.53 m".

So - there does appear to be a bug in handling -sd=<millimeters>mm for some larger values of millimeters (I suspect anything over 65535, but haven't tested enough to be sure).

If you want I can post the .JPGs, but I don't think that'll be necessary.

Here are the exiftool outputs - first image:

Code: [Select]
ExifTool Version Number         : 12.15
File Name                       : test2147483647mm.jpg
Directory                       : C:/Users/Dave/Desktop
File Size                       : 1589 KiB
File Modification Date/Time     : 2021:02:03 23:36:45-05:00
File Access Date/Time           : 2021:02:03 23:52:56-05:00
File Creation Date/Time         : 2021:02:03 23:36:45-05:00
File Permissions                : rw-rw-rw-
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Canon
Camera Model Name               : Canon PowerShot A640
...
Focus Distance Upper            : 0.06 m
Focus Distance Lower            : 0 m


And 2nd image (identical command line except for "b" at the end of the filename):

Code: [Select]
ExifTool Version Number         : 12.15
File Name                       : test2147483647mmb.jpg
Directory                       : C:/Users/Dave/Desktop
File Size                       : 1660 KiB
File Modification Date/Time     : 2021:02:03 23:38:33-05:00
File Access Date/Time           : 2021:02:03 23:43:22-05:00
File Creation Date/Time         : 2021:02:03 23:38:33-05:00
...
Focus Distance Upper            : 65.53 m
Focus Distance Lower            : 0 m

I *think* that's what's going on.

I think I'm just going to use "65535mm" for "infinity" from now on.
« Last Edit: 04 / February / 2021, 00:03:04 by Dave92F1 »

*

Offline reyalp

  • ******
  • 14079
Re: CHDKPTP remotshoot focus
« Reply #11 on: 04 / February / 2021, 00:29:54 »
No, that wasn't a mispaste, I think MF is working and I was using it.
If set_mf() doesn't work, then -sdmode=MF cannot work, because it uses set_mf() under the hood. If it works, set_mf() should behave the same as the test you did with set_aflock(). If it doesn't, it's broken. It is of course possible there are multiple problems...

Quote
I think I'm just going to use "65535mm" for "infinity" from now on.
On old cameras like A640, the firmware actually uses a short for focus distance, so this should be OK (edit: -1 should also get you "infinity").

I assumed the larger value wouldn't be a problem since the CHDK code is supposed to ensure that any values larger than the camera specific max focus distance get clamped, but looking at it, there may indeed be problems with values close to maxint.
« Last Edit: 04 / February / 2021, 00:37:18 by reyalp »
Don't forget what the H stands for.

Re: CHDKPTP remotshoot focus
« Reply #12 on: 04 / February / 2021, 12:57:23 »
If set_mf() doesn't work, then -sdmode=MF cannot work, because it uses set_mf() under the hood. If it works, set_mf() should behave the same as the test you did with set_aflock().

I think set_mf() DOES work. My confusion came from the behavior when using sys.maxint as the focus parameter - that made it seem that set_mf() didn't work. But it does work OK with smaller values.

*

Offline reyalp

  • ******
  • 14079
Re: CHDKPTP remotshoot focus
« Reply #13 on: 04 / February / 2021, 17:32:41 »
I think set_mf() DOES work. My confusion came from the behavior when using sys.maxint as the focus parameter - that made it seem that set_mf() didn't work. But it does work OK with smaller values.
So when you wrote earlier
Quote
OK, can you try the same thing with set_aflock(1) instead of set_mf? If that works, should be able to use -sdmode=AFL instead of -sdmode=MF

Yes! That seems to work. In fact if I run the GUI and do set_aflock(1), then calls to set_focus() immediately change the focus on the live view.

That didn't seem to happen with set_mf(1).

Yet...today I tried it again and set_mf(1) seems to work. If I watch the liveview in the GUI, set_focus(1) and set_focus(10000) have obvious effect. I tried with both A640s I have here - same on both.
You meant that you re-did the set_mf test, and saw the same focus behavior in live view as with set_aflock()?

Sorry if this is beating a dead horse, just trying to understand what's going on.

set_focus very close to maxint is likely to be buggy (it adds the focal plane width without checking for overflow, which would result in a large negative value, which would then be passed to the firmware, and in your case probably truncated to 16 bits), but I don't immediately see how it would explain the symptoms you described.

Just for the record, -1 is treated as a special case to signal infinity, so that's probably the most portable choice for focus at max distance. However, this is not necessarily best actual infinity on a given camera.
Don't forget what the H stands for.


Re: CHDKPTP remotshoot focus
« Reply #14 on: 04 / February / 2021, 18:18:07 »
Quote
You meant that you re-did the set_mf test, and saw the same focus behavior in live view as with set_aflock()?

Yes, exactly. That's why I used past tense, because by the time I sent that post I'd started to suspect I'd misinterpreted what I was seeing.

Quote
Just for the record, -1 is treated as a special case to signal infinity, so that's probably the most portable choice for focus at max distance. However, this is not necessarily best actual infinity on a given camera.

That's good to know - I don't think it's documented. Are you sure it's true for all ports? If so I'll mention it on the wiki.

What exactly do you mean "not necessarily best actual infinity"? Do you mean the camera might focus past infinity with -1? In that case, is there a method for finding out the correct best actual infinity setting? (Or, might it be best to let autofocus do its thing?)

*

Offline reyalp

  • ******
  • 14079
Re: CHDKPTP remotshoot focus
« Reply #15 on: 04 / February / 2021, 21:55:51 »
Yes, exactly. That's why I used past tense, because by the time I sent that post I'd started to suspect I'd misinterpreted what I was seeing.
Thanks, that clears it up. :)

Quote
That's good to know - I don't think it's documented. Are you sure it's true for all ports? If so I'll mention it on the wiki.
Yes, the logic is the same for all ports.

Quote
What exactly do you mean "not necessarily best actual infinity"? Do you mean the camera might focus past infinity with -1?
Yes. The distance values used in the Canon firmware don't seem well calibrated, and this includes where it thinks "infinity" is. This is more likely to be a noticeable issue on cameras with larger sensors or much longer zoom than your A640 though. So, if the pictures look fine using -1 or 65535, I wouldn't worry about it.

My G7X consistently focuses beyond infinity when SD goes to -1. I believe there's variability due to temperature or other factors too.
Quote
In that case, is there a method for finding out the correct best actual infinity setting? (Or, might it be best to let autofocus do its thing?)
If the majority of your scene is static and the distance you want to focus, you can compare jpeg sizes. The best focus will have most detail, resulting in larger size if everything else is equal.

I would generally avoid using Canon AF for unattended shooting if possible. It can be very wrong, especially in poor lighting conditions. So if you can get acceptable focus with "infinity" or some other set distance, I'd recommend that.

Some cameras have an infinity mode (usually a mountain icon in the Canon focus UI), which is still autofocus, but biased toward far distance. This is somewhat better than regular AF, but still goes wildly wrong sometimes in my experience.

One other thing to note is that there are only a limited number of focus positions, and set_focus just sets to the nearest value.  So if you set_focus(1000), get_focus() might return, say 600 or 1500. See the bottom of this post for an example https://chdk.setepontos.com/index.php?topic=11927.msg144622#msg144622
Don't forget what the H stands for.

Re: CHDKPTP remotshoot focus
« Reply #16 on: 12 / February / 2021, 17:37:09 »
FWIW, I've discovered a few more things:

  • -sdmode=AF doesn't seem to work:

Code: [Select]
connected: Canon PowerShot A640, max packet size 512
con> remoteshoot /home/pi/Desktop/t -sdmode=AF
ERROR: sdmode requires sd
con>

  • -sdmode=MF -sd=-1mm and -sdmode=MF -sd=-1m produce COMPLETELY different focus results

-1mm focuses very close to the camera (I get nothing but blur).

-1m focuses far from the camera, but NOT at infinity. Or maybe past it.

65535mm focuses similarly to -1m. (Hard to tell if it's identical to -1m or not.)

Because if I focus using AF, I get obviously sharper focus at infinity than with either -1m or with 65535mm.

To make it odder - that's all at set_zoom(0).  If I do set_zoom(1) (which zooms as expected), then -sd=-1mm works as expected - sharp at infinity.

I'm still trying to figure out how to reliably get sharp focus (at infinity) when using set_zoom(0), other than using AF (because I don't trust that AF will work every time).

*

Offline reyalp

  • ******
  • 14079
Re: CHDKPTP remotshoot focus
« Reply #17 on: 12 / February / 2021, 18:34:19 »

  • -sdmode=AF doesn't seem to work:
As the error message says, -sdmode requires -sd. sdmode specifies which mode use when attempting SD override, so it makes no sense without also specifying a distance. If you want the camera to autofocus, just make sure the camera is in AF mode (the power on default) and shoot.

-sdmode=AF might seem nonsensical, but what it means is CHDK attempts to change the focus while the camera is in AF mode, after the camera finishes doing autofocus.

Quote
  • -sdmode=MF -sd=-1mm and -sdmode=MF -sd=-1m produce COMPLETELY different focus results

-1mm focuses very close to the camera (I get nothing but blur).

-1m focuses far from the camera, but NOT at infinity. Or maybe past it.

65535mm focuses similarly to -1m. (Hard to tell if it's identical to -1m or not.)

Because if I focus using AF, I get obviously sharper focus at infinity than with either -1m or with 65535mm.
[/quote]
If you are using the last released version of chdkptp (r964), -1 in chdkptp shoot commands is broken. It's fixed in SVN, you can update the Lua files from https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk if you want.

Quote
To make it odder - that's all at set_zoom(0).  If I do set_zoom(1) (which zooms as expected), then -sd=-1mm works as expected - sharp at infinity.

I'm still trying to figure out how to reliably get sharp focus (at infinity) when using set_zoom(0), other than using AF (because I don't trust that AF will work every time).
If AF usually works on your scene, you can see what distance AF gets using
Code: [Select]
=press'shoot_half' repeat sleep(10) until get_shooting() return get_focus()
and then use that -sd=...mm in your shoot command. Unless it comes back as -1.
Don't forget what the H stands for.


Re: CHDKPTP remotshoot focus
« Reply #18 on: 12 / February / 2021, 20:22:19 »
As the error message says, -sdmode requires -sd. sdmode specifies which mode use when attempting SD override, so it makes no sense without also specifying a distance. If you want the camera to autofocus, just make sure the camera is in AF mode (the power on default) and shoot.

I was able to get autofocus with set_mf(0) no problem, but what happens if you do set_mf(1) and then -sdmode=AF? I was trying -sdmode=AF just in case I'd forgotten to do set_mf(0).

Quote
-sdmode=AF might seem nonsensical, but what it means is CHDK attempts to change the focus while the camera is in AF mode, after the camera finishes doing autofocus.

So if I'm going to use -sdmode=AF, what value would go in the -sd=?

(I'll try to update the wiki with this info - it's not obvious that -sd= should be needed with AF.)

Quote
If you are using the last released version of chdkptp (r964), -1 in chdkptp shoot commands is broken. It's fixed in SVN, you can update the Lua files from https://app.assembla.com/spaces/chdkptp/subversion/source/HEAD/trunk if you want.

Aha! I'll try that; thanks.

Quote
If AF usually works on your scene, you can see what distance AF gets using
Code: [Select]
=press'shoot_half' repeat sleep(10) until get_shooting() return get_focus()and then use that -sd=...mm in your shoot command. Unless it comes back as -1.

OK, sounds good. What units does get_focus() return? Millimeters? Meters?

Note that get_focus() is not listed as a possible command at https://chdk.fandom.com/wiki/Script_commands (but I'll try it anyway).

Any idea why things work with set_zoom(1) but not with set_zoom(0)? That seems strange.
« Last Edit: 12 / February / 2021, 20:27:35 by Dave92F1 »

*

Offline reyalp

  • ******
  • 14079
Re: CHDKPTP remotshoot focus
« Reply #19 on: 12 / February / 2021, 21:22:27 »
I was able to get autofocus with set_mf(0) no problem, but what happens if you do set_mf(1) and then -sdmode=AF? I was trying -sdmode=AF just in case I'd forgotten to do set_mf(0).
-sdmode is an option to the chdkptp shooting commands. It tells chdkptp which focus mode to put the camera in before attempting SD override.

set_focus, set_mf etc are CHDK functions. If you just want to turn off mf mode, you just use =set_mf(0)

Quote
So if I'm going to use -sdmode=AF, what value would go in the -sd=?
Whatever distance you want the camera to focus at. -sdmode is a modifier for -sd, not a way of setting the focus mode generally.

The background for this is that SD overrides only work in some modes on some cameras. Some only work in AF, some only work in MF, some have quirks that make one or the other preferable in some situations. By default, -sd will try to pick one defined as working in the port. -sdmode lets you pick instead.

Quote
(I'll try to update the wiki with this info - it's not obvious that -sd= should be needed with AF.)
Note this is purely specific to the chdkptp shooting commands (shoot, rs and rsint). It does not belong in the parts of the wiki that describe CHDK scripting functions.

Quote
OK, sounds good. What units does get_focus() return? Millimeters? Meters?
millimeters

Quote
Note that get_focus() is not listed as a possible command at https://chdk.fandom.com/wiki/Script_commands (but I'll try it anyway).
https://chdk.fandom.com/wiki/CHDK_Scripting_Cross_Reference_Page is the most comprehensive list.

Quote
Any idea why things work with set_zoom(1) but not with set_zoom(0)? That seems strange.
It's not too surprising. The possible focus distances are different at different zoom levels, and the optical configuration is different.

At wide angle, the camera usually switches to infinity (get_focus returning -1) at a quite close value.
Don't forget what the H stands for.

 

Related Topics