40 lines
2.1 KiB
C++
40 lines
2.1 KiB
C++
|
|
#include "static_station_config.hpp"
|
||
|
|
#include <algorithm>
|
||
|
|
#include <cmath>
|
||
|
|
#include <iomanip>
|
||
|
|
#include <iostream>
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
using namespace target_exposure;
|
||
|
|
ExposureControl control;
|
||
|
|
const auto config = staticStationExampleConfig();
|
||
|
|
double actual_exposure_us = config.empirical_exposure_us;
|
||
|
|
std::cout << "SIMULATED brightness only; no camera/field validation. Exposure unit: us\n";
|
||
|
|
for (int index = 0; index < 12; ++index) {
|
||
|
|
const TimestampUs now = (static_cast<TimestampUs>(index) + 1) * 1'000'000;
|
||
|
|
const auto before = control.preCapture(now, config);
|
||
|
|
if (!before.accepted) return 1;
|
||
|
|
// The caller applies the requested exposure BEFORE acquisition.
|
||
|
|
if (before.initialization_required) actual_exposure_us = *before.suggested_exposure_us;
|
||
|
|
const double response = 0.11 - 0.002 * index;
|
||
|
|
const auto gray = static_cast<int>(std::clamp(std::round(response * actual_exposure_us), 0.0, 255.0));
|
||
|
|
FrameInput frame;
|
||
|
|
frame.image = cv::Mat(32, 32, CV_8UC1, cv::Scalar(gray));
|
||
|
|
frame.roi.rectangles.emplace_back(8, 8, 16, 16);
|
||
|
|
frame.has_usable_target = true; // real callers supply their own recognition result
|
||
|
|
frame.timestamp_us = now;
|
||
|
|
frame.actual_exposure_us = actual_exposure_us;
|
||
|
|
frame.next_capture_timestamp_us = now + 1'000'000;
|
||
|
|
const auto result = control.processFrame(frame);
|
||
|
|
if (!result.accepted || !result.metering.target.valid()) return 2;
|
||
|
|
std::cout << std::fixed << std::setprecision(2) << "frame=" << index
|
||
|
|
<< " state=" << toString(result.state) << " gray=" << *result.metering.target.gray
|
||
|
|
<< " actual_us=" << actual_exposure_us
|
||
|
|
<< " next_us=" << *result.suggested_exposure_us
|
||
|
|
<< " prediction_used=" << result.prediction.adopted
|
||
|
|
<< " reason=" << toString(result.reason) << '\n';
|
||
|
|
// The application applies this to frame N+1, then supplies the actual applied value.
|
||
|
|
if (result.adjustment_suggested) actual_exposure_us = *result.suggested_exposure_us;
|
||
|
|
}
|
||
|
|
}
|