jim-easterbrook / python-gphoto2

Python interface to libgphoto2
GNU Lesser General Public License v3.0
362 stars 59 forks source link

Canon focus control? #13

Closed HazenBabcock closed 8 years ago

HazenBabcock commented 8 years ago

I'd like to be able to remotely adjust the focus of my Canon T5i. The best that I can currently do is to use the setting "Drive Canon DSLR Manual Focus" (with "Continuous AF" set to "Off") and set it to something like "Far 3" or "Near 3", which I can see changes the focus. Then I can make it oscillate back and forth using "Far 3", "Near 3", "Far 3", etc.. However I can't figure out how to make it "walk" in one direction, i.e. "Far 3" followed by "Far 3" doesn't do anything. This only seems to work if I exit my program and restart it, but hopefully there is a better way.

jim-easterbrook commented 8 years ago

I don't have any helpful advice I'm afraid - I've not tried using libgphoto2 to focus a camera. I know from discussions on the gphoto-user mailing list (see https://lists.sourceforge.net/lists/listinfo/gphoto-user) that focusing is often a problem. I suggest asking on that list as there may be a T5i user who can help.

HazenBabcock commented 8 years ago

Ok, thank you for the feedback (and for this project). I will ask on the list and search some more to see if I can find an answer. I'll close this for now, but add a solution later if I find one.

HazenBabcock commented 8 years ago

It looks like the trick to getting the focus to walk in one direction with this camera is to set "Drive Canon DSLR Manual Focus" to "Far 3" (or whatever step you want), then set it to "None", then back to "Far 3", etc.. repeating the desired step, then "None" as many time as desired to get to where you want to go. You also need to wait a half a second or so after entering preview mode, and you need to set the switch on your lens to manual focus (MF) or the camera will refocus before taking the picture.

benoitguigal commented 7 years ago

Hello I am trying to focus my CANON 1200D manually. How do you enter preview mode and then drive manual focus ? I tried using camera_file = gp.check_result(gp.gp_camera_capture_preview(camera, context)) but it is a blocking operation so I can't make any subsequent call before leaving the preview. Any help would be appreciated.

jim-easterbrook commented 7 years ago

Are you able to do it by putting the camera into preview mode manually? I think gp_camera_capture_preview is just an operation to capture a preview image (it also works on cameras without a preview mode such as the 350d). Is it possible to set preview mode via the camera config?

HazenBabcock commented 7 years ago

On my camera the config option to enter preview mode is "Canon EOS Viewfinder".

benoitguigal commented 7 years ago

I indeed have a config option called Canon EOS Viewfinder. It is working, below the code I used:

param = 'viewfinder'
widget = gp.check_result(gp.gp_widget_get_child_by_name(config, param))
gp.gp_widget_set_value(widget, 1)

time.sleep(0.5)

for i in range(0, 100):
    param = 'manualfocusdrive'
    choice = 6
    widget = gp.check_result(gp.gp_widget_get_child_by_name(config, param))
    value = gp.check_result(gp.gp_widget_get_choice(widget, choice))
    gp.gp_widget_set_value(widget, value)
    gp.gp_camera_set_config(camera, config, context)
    choice = 3
    widget = gp.check_result(gp.gp_widget_get_child_by_name(config, param))
    value = gp.check_result(gp.gp_widget_get_choice(widget, choice))
    gp.gp_widget_set_value(widget, value)
    gp.gp_camera_set_config(camera, config, context)
jim-easterbrook commented 7 years ago

I'm glad you got it working. Shouldn't you have a gp_camera_set_config call just after you set the viewfinder param though?

I think you should have error checking on every libgphoto call, not just the ones that return a result. The easiest way to do this is with the "object oriented" interface. For example, replace gp.check_result(gp.gp_widget_get_child_by_name(config, param)) with config.get_child_by_name(param) and replace gp.gp_camera_set_config(camera, config, context) with camera.set_config(config, context).

benoitguigal commented 7 years ago

ok great I will do. Thank you for your help !

alperenkilic commented 2 years ago

Hi guys, time to wake up this issue :) I am using Canon2000d, need to change AF/MF mode remotely. Is there a way ?

For example when MF is selected, I want to select AF mode by software.

jim-easterbrook commented 2 years ago

On my cameras AF/MF is a switch on the side of the lens! I don't think I'll be able to help.