0

I am trying to set the autofocus area for my Nikon D7200

I retrieved the config object and saw this entry in it:

{
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "0x0"
 },

I'm not quite sure what parameters to pass into gp_camera_set_single_config()

According to the codebase I need to pass in gp_camera_set_single_config, ($self, name, widget, context)

In order to change the center of the autofocus to pixel 100x100 (WIDTH x HEIGHT), I've tried the following commands, but not really getting anywhere. Didn't know if anyone happened to know how to pass this param?

import gphoto2 as gp

# setup
camera = gp.check_result(gp.gp_camera_new())
context = None
gp.check_result(gp.gp_camera_init(camera, self.context))

# Method 1
gp.gp_camera_set_single_config(camera, 'changefarea', '100x100')

# Method 2
gp.gp_camera_set_single_config(camera, '--changefarea', '100x100')

# Method 3
gp.gp_camera_set_single_config(camera, 'changefarea', {
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "100x100"
 })

# Method 4
gp.gp_camera_set_single_config(camera, '--changefarea', {
          "idx": "6,6,0,0",
          "ro": 0,
          "name": "changeafarea",
          "label": "Set Nikon Autofocus area",
          "type": 2,
          "typestr": "GP_WIDGET_TEXT",
          "value": "100x100"
 })

UPDATE #1:
In order to set a config you have to first get the config with gp.gp_camera_get_single_config(camera, 'changefarea'). Still unsure of what params to pass though.

Jacob Dallas
  • 47
  • 1
  • 8

1 Answers1

0

Here's what ended up working for me, not sure about what values to pass through yet, will update when I find out:

import gphoto2 as gp

camera = gp.check_result(gp.gp_camera_new())
context = None
gp.check_result(gp.gp_camera_init(camera, self.context))

config_name =  "changeafarea"
value = "100x100"  # in my code I have it linked up to PyQt5 window where I am clicking around the live-view and the pixel value of where I clicked is being passed back and formatted into this string format

while True:
          # wait for config widget
          config_widget = gp.gp_camera_get_single_config(self.camera, config_name)
          if config_widget[1] is not None:
              break
config_widget = config_widget[1]
config_set_response = gp.gp_widget_set_value(config_widget, value)
print('set response:', gp.gp_widget_get_value(config_widget))
gp.gp_camera_set_single_config(camera, config_name, config_widget)
Jacob Dallas
  • 47
  • 1
  • 8