1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| void GenerateLut(const cv::Mat &control_points, const float &r2, const cv::Mat &W, const int width, const int height, cv::Mat &lut) { lut = cv::Mat::zeros(height, width, CV_32FC2); float x_distort, y_distort, x_cv, y_cv, x_tex, y_tex; for (int y = 0; y < height; y++) { y_cv = float(height) - y - 1; for (int x = 0; x < width; x++) { x_cv = x;
Distort(x_cv, y_cv, control_points, r2, W, x_distort, y_distort);
x_tex = (x_distort + 0.5f) / float(width); y_tex = 1.f - (y_distort + 0.5f) / float(height);
lut.at<cv::Vec2f>(y, x)[0] = x_tex; lut.at<cv::Vec2f>(y, x)[1] = y_tex; } } }
int main(int argc, char *argv[]) { cv::Mat lut; GenerateLut(control_points, r2, weights, screen_size.width, screen_size.height, lut);
std::string screen_calibration_lut_file = calibration_result_save_path + "/screen_calibration_lut.bin";
std::ofstream out(screen_calibration_lut_file, std::ios::out | std::ios::binary | std::ios::trunc); if (!lut.isContinuous()) {lut = lut.clone();} out.write((char *)lut.data, 2 * lut.cols * lut.rows * sizeof(float)); out.close(); }
|