gphoto2 icon indicating copy to clipboard operation
gphoto2 copied to clipboard

Focused? Command to check the in-focus status. Nikon

Open tokiAi opened this issue 3 years ago • 7 comments

Is there a command to check the in-focus status?

With gphoto2 I can move the camera focus (with manual focus drive) to a certain point and then take a picture. For my application I would also need the information whether the image in the focus point is sharp or not.

If there is something like that in gphoto2? If not, is there a way to do this in libgphoto2? And what does it look like.

Name the camera Nikon z7

tokiAi avatar May 11 '21 11:05 tokiAi

the nikon dslr actually seem to return this during capture when liveview is running, but we currently do not decode and present that info via the API. which nikon?

msmeissn avatar May 16 '21 12:05 msmeissn

Nikon z7

If the API supports it, it would be a good feature, because you don't always need the image to automate calibration and to determine the sharpness on the pictures is more effort than reading out the value.

tokiAi avatar May 18 '21 10:05 tokiAi

Do I understand it right? gphoto2 --capture-preview: connects to the camera liveview and then 0x9203 or "GetLiveViewImage" (Nikon SDK Specifications) is sent to the camera and the camera replies with LiveView-information (such as focused or not) and the image, but the information is ignored and the image will be saved.

tokiAi avatar May 18 '21 14:05 tokiAi

basically yes. the camera sends back a blob of data on this command, and 1 big part is the JPEG of the liveview, and there is a structured datablob (in front) of it.

msmeissn avatar May 18 '21 15:05 msmeissn

Is it possible to read this information out of the --debug text?

From the Nikon SDK specification, I know that 0x9203 gives me the LiveViewObject (no version). But I don't quite understand what the debug text reads out after the command 0x9203. It reads 1024 bytes first, then 17920 bytes and then 501 bytes. This does not match the 376 bytes from the SDK.

Is it somehow possible to find the InFocus byte from the SDK in the debug text?

LiveViewObject (no version):

  • 48 bytes - some for me uninteresting information
  • 1 bytes - InFocus information (0: No information, 1: Not focused, 2: Focused)
  • 63 bytes - some for me uninteresting information
  • then the live view image follows

"The size of the display information is 376Byte." (Nikon SDK specification)

the debug text

[...]

0.332306 ptp_usb_sendreq             (2): Sending PTP_OC 0x9203 (GetLiveViewImg) request...
0.332364 gp_port_write               (3): Writing 12 = 0xc bytes to port...
0.333777 gp_port_write               (3): Wrote   12 = 0xc bytes to port: (hexdump of 12 bytes)

0000  0c 00 00 00 01 00 03 92-0c 00 00 00              ............   
 
0.333897 ptp_usb_getdata             (2): Reading PTP_OC 0x9203 (GetLiveViewImg) data...
0.333949 gp_port_read                (3): Reading 1024 = 0x400 bytes from port...
0.336250 gp_port_read                (3): Read    1024 = 0x400 bytes from port: (hexdump of 1024 bytes)

0000  f5 4b 00 00 02 00 03 92-0c 00 00 00 00 00 01 78  .K.............x
0010  00 00 4a 69 01 e0 01 e0-15 80 15 80 15 80 15 80  ..Ji............
0020 [...]
[...]

[...shortened for readability...]

0.338451 gp_port_read                (3): Reading 17920 = 0x4600 bytes from port...
0.343386 gp_port_read                (3): Read    17920 = 0x4600 bytes from port: (hexdump of 17920 bytes)
0000  c5 37 18 a0 05 07 14 f5-7c 54 74 50 04 b9 cd 25  .7......|TtP...%
0010  30 1a 70 34 80 08 a4 2b-4e 14 b4 01 1e 29 31 52  0.p4...+N....)1R
0020 [...]
[...]

[...shortened for readability...]

0.362152 gp_port_read                (3): Reading 501 = 0x1f5 bytes from port...
0.362402 gp_port_read                (3): Read    501 = 0x1f5 bytes from port: (hexdump of 501 bytes)

0000  b8 a0 53 b1 49 4b 40 ae-02 96 8a 28 01 68 cd 02  ..S.IK@....(.h..
0010  96 81 09 4a 0d 18 34 50-03 b3 46 69 b4 d2 c2 98  ...J..4P..Fi....
0020 [...]
[...]

[...shortened for readability...]

[...]

PS. the command "gphoto2 --capture-preview" seems to have a bug. There is always the same output image. I have opened a new issue for this.

tokiAi avatar May 19 '21 14:05 tokiAi

these 3 reads combine into 1 block of data.

the first 12 byte are the PTP Header, "f5 4b 00 00 02 00 03 92-0c 00 00 00" then the payload starts (with 00 00 01 78 ... the 0178 seems to be the 376 bytes ... so this will be the info block I think

msmeissn avatar May 19 '21 15:05 msmeissn

so you need likely either have to calculate starting at this 00 00 01 78 offset, or just after it

msmeissn avatar May 19 '21 16:05 msmeissn