Skip to content

Commit

Permalink
Merge pull request OpenThermal#62 from Bostwickenator/auto_exposure_lock
Browse files Browse the repository at this point in the history
Auto exposure lock
  • Loading branch information
Bostwickenator authored Jan 3, 2021
2 parents 7b1915c + 8c5e1c1 commit c9e09dc
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions examples/seek_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,52 @@ const std::string WINDOW_NAME = "SeekThermal";
// Setup sig handling
static volatile sig_atomic_t sigflag = 0;


bool auto_exposure_lock = false;

void handle_sig(int sig) {
(void)sig;
sigflag = 1;
}


// Normalize the image so that it uses the full color space available for display.
void normalize(Mat &inframe) {
static double min =-1, max = -1;
static float multiplier = -1;

if (auto_exposure_lock) {
if (min == -1) {
cv::minMaxLoc(inframe, &min, &max);
multiplier = 65535 / (max - min);
}
for (int y = 0; y < inframe.rows; y++) {
for (int x = 0; x < inframe.cols; x++) {
uint16_t val = inframe.at<uint16_t>(y, x);
if (val > max) {
val = 65535;
} else if (val < min) {
val = 0;
} else {
val = (val - min) * multiplier;
}
inframe.at<uint16_t>(y, x) = val;
}
}
} else {
normalize(inframe, inframe, 0, 65535, NORM_MINMAX);
min = -1;
}
}

// Function to process a raw (corrected) seek frame
void process_frame(Mat &inframe, Mat &outframe, float scale, int colormap, int rotate) {
Mat frame_g8, frame_g16; // Transient Mat containers for processing
Mat frame_g8; // Transient Mat containers for processing

normalize(inframe, frame_g16, 0, 65535, NORM_MINMAX);
normalize(inframe);

// Convert seek CV_16UC1 to CV_8UC1
frame_g16.convertTo(frame_g8, CV_8UC1, 1.0/256.0 );
inframe.convertTo(frame_g8, CV_8UC1, 1.0/256.0 );

// Rotate image
if (rotate == 90) {
Expand Down Expand Up @@ -77,6 +110,14 @@ void key_handler(char scancode) {
waitKey(0);
break;
}
case 'a': {
auto_exposure_lock = !auto_exposure_lock;
std::cout << "AEL:" << auto_exposure_lock << std::endl;
break;
}
case 'q': {
sigflag = SIGINT;
}
}
}

Expand Down

0 comments on commit c9e09dc

Please sign in to comment.