Skip to content

Commit

Permalink
core: Add flicker correction control
Browse files Browse the repository at this point in the history
Allow user to set the flicker period through the --flicker-period
command line argument.

Signed-off-by: Naushir Patuck <[email protected]>
  • Loading branch information
naushir committed Jul 25, 2023
1 parent 9e17265 commit 09a3ffa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions core/libcamera_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,14 @@ void LibcameraApp::StartCamera()
controls_.set(controls::LensPosition, f);
}

if (options_->flicker_period && !controls_.get(controls::AeFlickerMode) &&
camera_->controls().find(&controls::AeFlickerMode) != camera_->controls().end() &&
camera_->controls().find(&controls::AeFlickerPeriod) != camera_->controls().end())
{
controls_.set(controls::AeFlickerMode, controls::FlickerManual);
controls_.set(controls::AeFlickerPeriod, options_->flicker_period.get<std::chrono::microseconds>());
}

if (camera_->start(&controls_))
throw std::runtime_error("failed to start camera");
controls_.clear();
Expand Down
3 changes: 3 additions & 0 deletions core/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ bool Options::Parse(int argc, char *argv[])
// Convert time strings to durations
timeout.set(timeout_);
shutter.set(shutter_);
flicker_period.set(flicker_period_);

// HDR control. Set this before opening or listing any cameras.
// Currently this does not exist in libcamera, so go directly to V4L2
Expand Down Expand Up @@ -440,6 +441,8 @@ void Options::Print() const
std::cerr << " gain: " << gain << std::endl;
std::cerr << " metering: " << metering << std::endl;
std::cerr << " exposure: " << exposure << std::endl;
if (flicker_period)
std::cerr << " flicker period: " << flicker_period.get() << "us" << std::endl;
std::cerr << " ev: " << ev << std::endl;
std::cerr << " awb: " << awb << std::endl;
if (awb_gain_r && awb_gain_b)
Expand Down
6 changes: 6 additions & 0 deletions core/options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ struct Options
"Save captured image metadata to a file or \"-\" for stdout")
("metadata-format", value<std::string>(&metadata_format)->default_value("json"),
"Format to save the metadata in, either txt or json (requires --metadata)")
("flicker-period", value<std::string>(&flicker_period_)->default_value("0s"),
"Manual flicker correction period"
"\nSet to 10000us to cancel 50Hz flicker."
"\nSet to 8333us to cancel 60Hz flicker.\n")
;
// clang-format on
}
Expand Down Expand Up @@ -277,6 +281,7 @@ struct Options
std::string metadata;
std::string metadata_format;
bool hdr;
TimeVal<std::chrono::microseconds> flicker_period;

virtual bool Parse(int argc, char *argv[]);
virtual void Print() const;
Expand All @@ -292,4 +297,5 @@ struct Options
std::string lens_position_;
std::string timeout_;
std::string shutter_;
std::string flicker_period_;
};

0 comments on commit 09a3ffa

Please sign in to comment.