Only manual focus / autofocus modes could be handled through initialControl
for now.
Here is the example how it works:
#include <csignal>
#include <cstdio>
#include <iostream>
// Includes common necessary includes for development using depthai library
#include "depthai/depthai.hpp"
// Keyboard interrupt (Ctrl + C) detected
static std::atomic<bool> alive{true};
static void sigintHandler(int signum) {
alive = false;
}
int main(int argc, char** argv) {
// Detect signal interrupts (Ctrl + C)
std::signal(SIGINT, &sigintHandler);
dai::Pipeline pipeline;
// Define a source - color camera
auto colorCam = pipeline.create<dai::node::ColorCamera>();
auto xout = pipeline.create<dai::node::XLinkOut>();
auto encoder = pipeline.create<dai::node::VideoEncoder>();
auto control = pipeline.create<dai::node::XLinkIn>();
control->setStreamName("ctrl");
xout->setStreamName("h264");
colorCam->setInterleaved(true);
colorCam->setImageOrientation(dai::CameraImageOrientation::ROTATE_180_DEG);
colorCam->setBoardSocket(dai::CameraBoardSocket::RGB);
colorCam->setResolution(dai::ColorCameraProperties::SensorResolution::THE_4_K);
//colorCam->initialControl.setAutoWhiteBalanceMode(dai::CameraControl::AutoWhiteBalanceMode::SHADE);
encoder->setDefaultProfilePreset(3840, 2160, 30, dai::VideoEncoderProperties::Profile::H264_MAIN);
// Create outputs
colorCam->video.link(encoder->input);
control->out.link(colorCam->inputControl);
encoder->bitstream.link(xout->input);
// Pipeline is defined, now we can connect to the device
dai::Device device(pipeline);
// Start pipeline
device.startPipeline();
// Output queue will be used to get the encoded data from the output defined above
auto camQueue = device.getOutputQueue("h264");
auto controlQueue = device.getInputQueue("ctrl");
// The .h264 file is a raw stream file (not playable yet)
auto videoFile = std::ofstream("video.h264", std::ios::binary);
std::cout << "Press Ctrl+C to stop encoding..." << std::endl;
while(alive) {
dai::CameraControl ctrl;
ctrl.setAutoWhiteBalanceMode(dai::CameraControl::AutoWhiteBalanceMode::TWILIGHT);
controlQueue->send(ctrl);
auto h265Packet = camQueue->get<dai::ImgFrame>();
videoFile.write((char*)(h265Packet->getData().data()), h265Packet->getData().size());
}
std::cout << "To view the encoded data, convert the stream file (.h264) into a video file (.mp4) using a command below:" << std::endl;
std::cout << "ffmpeg -framerate 30 -i video.h264 -c copy video.mp4" << std::endl;
return 0;
}
As you can see
colorCam->initialControl.setAutoWhiteBalanceMode(dai::CameraControl::AutoWhiteBalanceMode::SHADE);
is commented out and needs to be sent at runtime.