Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect camera rotation on Microsoft Surface?

Is there a reliable way to determine if a camera is rotated on the Microsoft Surface?

Basically, I want to know if a specific camera is built into the device (as it will then rotate with the device), is there a way to query this?

My problem is that when the user rotates the device, my camera view is flipped, I cannot however assume that I should just rotate the read frames as the active camera may be an external USB camera.

I'm reading the cameras using the Media Foundation APIs.

like image 431
monoceres Avatar asked Jan 16 '17 10:01

monoceres


1 Answers

Basically, I want to know if a specific camera is built into the device [...] is there a way to query this?

With UWP, you can check the camera's DeviceInformation's enclosureLocation.panel property, which is either:

  • front/back/etc for an integrated camera or
  • unknown for an external camera

An full example is available in the CameraStarterKit sample.


However, if you can't use UWP, it should still be possible to find the underlying information. With MF, you should be able to access MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK.

This will be something like

\\?\usb#vid_046d&pid_0843&mi_00#6&2314864d&0&0000#{e5323777-f976-4f5b-9b55-b94699c46e44}\global

A built-in camera is supposed to register its physical location in

HKLM\SYSTEM\CurrentControlSet\Control\InternalDeviceModification\{GUID}

Where the value of the PLD_Panel key should be a DWORD with values very similar to the Panel enum referenced above.

Here, 6 means unknown. So you should be able to check for the presence of this registry key and, if present check its value. I suspect this is similar to what UWP does under the hood.

Failing that, you can also hack in support by hardcoding some values for camera vendor and product ID's or MF_DEVSOURCE_ATTRIBUTE_FRIENDLY_NAME's.

like image 106
Grisha Levit Avatar answered Sep 19 '22 16:09

Grisha Levit