kylemcdonald / ofxEdsdk

Interfacing with Canon cameras from openFrameworks for OSX. An alternative to ofxCanon and CanonCameraWrapper.
Other
111 stars 51 forks source link

Auto Focus #24

Open thiagohersan opened 9 years ago

thiagohersan commented 9 years ago

Not an issue, but I added some logic to your magic to make the camera try to focus before taking a picture (the equivalent of pressing the shutter button down halfway).

You can see the diff here.

If this is something you might want in the addon we can negotiate a PR (what I mean is: I might need to clean up the code, or make it more understandable, or merge my takePhotoAF() function into takePhoto() : )

Let me know.

kylemcdonald commented 9 years ago

cool! but when the camera is in autofocus mode, doesn't it do this every time you take a picture anyway?

is this so that you have control on every shot for whether to autofocus or not?

thiagohersan commented 9 years ago

Yes ! It's so you have control !

Right now if the camera is in AF mode and focus fails, you don't get a picture ...

This allows you to take pictures without trying to focus, or to take the picture despite AF failing.

Maybe it can be a flag on the takePicture function... and I'm not sure if it makes sense to expose whether focus failed or not...

kylemcdonald commented 9 years ago

great :)

  1. i'm interested in adding this
  2. it definitely needs to be a flag, let's call it attemptAutoFocus
  3. being able to know when AF failed is good, but not essential
  4. if focusFailed() and focusFrame() are not meant to be public they should be private or protected

if you can do these things i'd be happy to merge your work!

ofZach commented 9 years ago

@thiagohersan I'm not sure if the logic for focus is right -- I think it's better to look at justFocus != 0... also, I've found that to keep my camera out of an infinite focusing loop I basically either do:

a) justFocus != 0 send the shutter off command, focus = OK, needToCheck = false

b) justFocus == 0 focusFailed()

this keeps me from stalling out, some of the other logic about 17/16 etc I think is based on the fact that justFocus seems to give back the number of focus frames or some other info, but if you look at the docs, it looks like it should be interpreted more simply

  justFocus -- In focus: 1 Out of focus: 0

I'm still not super sure how to read this kEdsPropID_FocusInfo struct (the documentation is super thin), but at any rate, thought I should flag that for me, != 0 is a pretty good check and keeps me from getting stuck in a weird state, where I continually re-focus.

(I'm working on this because without auto focus, I get stuck taking continually a picture when the focus is not good)

thanks!

thiagohersan commented 9 years ago

Hi @ofZach .

I think you're right regarding the numbers for justFocus. I remember that depending on the condition and state of the camera I would get very different numbers, and the SDK doc was not very helpful. So, that makes sense.

What I needed was something that would try to focus, if it succeed, then take many pictures, if it didn't successfully focus, then just take one picture and try the whole thing again at a later time.

My code might be a bit specific to that situation, and I meant to clean it up and make more generic functions to enable taking pictures without trying to focus, or to take the picture despite AF failing.... but.... my camera got stolen and I haven't replaced it.

ofZach commented 9 years ago

oh sorry to hear that! I've found your code very helpful -- especially the take photo without focus (since the way the logic works with my camera, I'd get stuck in a pretty painful loop trying to take a picture when it can't focus). I will try to poke around more and see what I can find out about the API for focusing...

plural commented 8 years ago

I have been playing with this addon tonight and i think the fix for failed autofocus is much simpler than @thiagohersan's proposed patch. In the if(needToTakePhoto) { try { section, you can replace TakePicture with 2 kEdsCameraCommand_PressShutterButton calls. If the AF fails, the exposure won't even be attempted and for good measure you can depress the shutter in the catch.

I can try to get a patch out shortly for this.

ofZach commented 8 years ago

@plural I'd be interested in seeing this patch...