简体   繁体   English

在 Python Gphoto2 中设置自动对焦区域

[英]Setting AutoFocus Area in Python Gphoto2

I am trying to set the autofocus area for my Nikon D7200我正在尝试为尼康 D7200 设置自动对焦区域

I retrieved the config object and saw this entry in it:我检索了配置 object 并在其中看到了以下条目:

{
          "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()我不太确定将哪些参数传递给gp_camera_set_single_config()

According to thecodebase I need to pass in gp_camera_set_single_config, ($self, name, widget, context)根据代码库我需要传入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.为了将自动对焦的中心更改为像素 100x100 (WIDTH x HEIGHT),我尝试了以下命令,但没有真正到达任何地方。 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:更新#1:
In order to set a config you have to first get the config with gp.gp_camera_get_single_config(camera, 'changefarea') .为了设置配置,您必须首先使用gp.gp_camera_get_single_config(camera, 'changefarea')获取配置。 Still unsure of what params to pass though.仍然不确定要传递哪些参数。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM