User Tools

Site Tools


script-hdr-xiaomi-yi4k

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

script-hdr-xiaomi-yi4k [2018/03/30 17:07] (current)
teq created
Line 1: Line 1:
 +====== HDR capturing with Xiaomi Yi cameras======
 +This example shows how to capture exposure series (e.g. for HDR) using exposure compensation using Xiaomi Yi 4k/4k+ cameras.
 +The following steps are executed:
 +  - Connect the script to a camera.
 +  - Set the camera mode to photo.
 +  - Set the exposure compensation.
 +  - Capture image.
  
 +
 +<code javascript>​
 +// Helper function for capturing an image with a specific exposure
 +function captureImage(cameraName,​ exposureCommand) {
 +    // Set exposure
 +    var result = sendCustomCameraCommand(cameraName,​ exposureCommand);​
 +    if (!result.ok) {
 +        logMessage("​Error setting exposure: " + result.message,​ true);
 +    }
 +
 +    // Give the camera some time for changing the mode
 +    waitMilliseconds(200);​
 +
 +    // Capture photo
 +    result = startRecording(cameraName);​
 +    if (!result.ok) {
 +        logMessage("​Error capturing photo: " + result.message,​ true);
 +    }
 +}
 +
 +// Use the currently connected camera:
 +var connectResult = connectToCamera();​
 +if (connectResult.ok) {
 +    var cameraName = connectResult.message;​
 +
 +    // Change the camera mode to 0 (which is photo mode for Xiaomi Yi cameras). The index
 +    // depends on the camera model.
 +    var result = changeCameraMode(cameraName,​ 0);
 +    if (!result.ok) {
 +        logMessage("​Error changing camera mode to photo: " + result.message,​ true);
 +    }
 +
 +    // Give the camera some time for changing the mode
 +    waitMilliseconds(500);​
 +
 +    // Log the current camera mode
 +    var cameraModeIndex = getCurrentCameraMode(cameraName);​
 +    logMessage("​The current camera mode is: " + cameraModeIndex);​
 +
 +    // Capture three images with different exposures
 +    captureImage(cameraName,​ "​iq_photo_ev:​-2.0"​);​ // 1
 +    waitMilliseconds(4000);​ // give the camera some time for capturing.
 +
 +    captureImage(cameraName,​ "​iq_photo_ev:​0"​);​ // 2
 +    waitMilliseconds(4000);​ // give the camera some time for capturing
 +
 +    captureImage(cameraName,​ "​iq_photo_ev:​+2.0"​);​ // 3
 +    logMessage("​Done"​);​
 +}
 +else logMessage("​No camera found"​);​
 +</​code>​
script-hdr-xiaomi-yi4k.txt ยท Last modified: 2018/03/30 17:07 by teq