camera gain strategy

This commit is contained in:
wanpiqiu123
2019-07-22 09:23:48 +08:00
parent d7fd85ff15
commit e9df99447e
2 changed files with 61 additions and 42 deletions

View File

@@ -33,6 +33,6 @@
//#define GIMBAL_FLIP_MODE (-1)
//#define CHASSIS_FLIP_MODE (-1)
//#define WITH_TIME_BASED_CAMERA_GAIN
#endif /* SETCONFIG_H */

View File

@@ -77,7 +77,26 @@ bool CameraWrapper::init() {
#elif defined(Linux)
CameraSetAeState(h_camera, false);
CameraSetExposureTime(h_camera, CAMERA_EXPOSURE * 1000);
#ifndef WITH_TIME_BASED_CAMERA_GAIN
CameraSetAnalogGain(h_camera, ARMOR_CAMERA_GAIN);
#else
#include <sys/time.h>
timeval tv;
int gain;
gettimeofday(&tv, nullptr);
float hour = tv.tv_sec / 3600.0;
if (6 <= hour && hour < 10) {
gain = 20;
} else if (10 <= hour && hour < 16) {
gain = 10;
} else if (16 <= hour && hour < 17) {
gain = 20;
} else if (17 <= hour && hour < 18) {
gain = 40;
} else {
gain = 50;
}
#endif
if (mode == 0) {
CameraSetGain(h_camera, CAMERA_BLUE_GAIN, CAMERA_GREEN_GAIN, CAMERA_RED_GAIN);
CameraSetLutMode(h_camera, LUTMODE_PRESET);
@@ -145,7 +164,8 @@ bool CameraWrapper::readRaw(cv::Mat &src) {
bool CameraWrapper::readProcessed(cv::Mat &src) {
// cerr << "Get-1" << endl;
if (CameraGetImageBuffer(h_camera, &frame_info, &pby_buffer, 1000) == CAMERA_STATUS_SUCCESS) {
CameraImageProcess(h_camera, pby_buffer, rgb_buffer, &frame_info); // this function is super slow, better not to use it.
CameraImageProcess(h_camera, pby_buffer, rgb_buffer,
&frame_info); // this function is super slow, better not to use it.
if (iplImage) {
cvReleaseImageHeader(&iplImage);
}
@@ -162,8 +182,7 @@ bool CameraWrapper::readProcessed(cv::Mat &src) {
}
}
CameraWrapper::~CameraWrapper()
{
CameraWrapper::~CameraWrapper() {
CameraUnInit(h_camera);
//注意先反初始化后再free
if (rgb_buffer != nullptr)