Skip to content

Commit

Permalink
Added a way to use digital zoom while running video stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
Napalys committed Jan 11, 2024
1 parent 3fe90e5 commit 9e6ae7b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/lccv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class PiCamera {
bool getVideoFrame(cv::Mat &frame, unsigned int timeout);
void stopVideo();

//Applies new zoom options. Before invoking this func modify options->roi.
void ApplyZoomOptions();

protected:
void run();
protected:
Expand Down
2 changes: 2 additions & 0 deletions include/libcamera_app.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class LibcameraApp
void StartCamera();
void StopCamera();

void ApplyRoiSettings();

Msg Wait();
void PostMessage(MsgType &t, MsgPayload &p);

Expand Down
5 changes: 5 additions & 0 deletions src/lccv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,8 @@ void *PiCamera::videoThreadFunc(void *p)
}
return NULL;
}

void PiCamera::ApplyZoomOptions()
{
app->ApplyRoiSettings();
}
16 changes: 16 additions & 0 deletions src/libcamera_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ void LibcameraApp::StopCamera()
std::cerr << "Camera stopped!" << std::endl;
}

void LibcameraApp::ApplyRoiSettings(){
if (!controls_.get(controls::ScalerCrop) && options_->roi_width != 0 && options_->roi_height != 0)
{
Rectangle sensor_area = *camera_->properties().get(properties::ScalerCropMaximum);
int x = options_->roi_x * sensor_area.width;
int y = options_->roi_y * sensor_area.height;
int w = options_->roi_width * sensor_area.width;
int h = options_->roi_height * sensor_area.height;
Rectangle crop(x, y, w, h);
crop.translateBy(sensor_area.topLeft());
if (options_->verbose)
std::cerr << "Using crop " << crop.toString() << std::endl;
controls_.set(controls::ScalerCrop, crop);
}
}

LibcameraApp::Msg LibcameraApp::Wait()
{
return msg_queue_.Wait();
Expand Down

0 comments on commit 9e6ae7b

Please sign in to comment.