User Tools

Site Tools


script-hdr-xiaomi-yi4k

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:

  1. Connect the script to a camera.
  2. Set the camera mode to photo.
  3. Set the exposure compensation.
  4. Capture image.
// 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");
script-hdr-xiaomi-yi4k.txt · Last modified: 2018/03/30 17:07 by teq