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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| Mat map1, map2, R; initUndistortRectifyMap(cameraMatrix, distCoeffs, R, newcameramatrix, imageSize, CV_32FC1, map1, map2);
Mat main_map, sub_map2, sub_map3, sub_map4, sub_map5; main_map = main_map.zeros(imageSize, CV_32S); sub_map2 = sub_map2.zeros(imageSize, CV_16U); sub_map3 = sub_map3.zeros(imageSize, CV_16U); sub_map4 = sub_map4.zeros(imageSize, CV_16U); sub_map5 = sub_map5.zeros(imageSize, CV_16U);
float x_value, y_value; float x_diff, y_diff; int x_temp, y_temp;
for (int row(0); row < imageSize.height; row++) { for (int col(0); col < imageSize.width; col++) { x_value = map1.at<float>(row, col); y_value = map2.at<float>(row, col);
x_temp = floor(x_value); y_temp = floor(y_value);
if (x_value < 0 or y_value < 0) { main_map.at<int32_t>(row, col) = 0; sub_map2.at<uint16_t>(row, col) = 0; sub_map3.at<uint16_t>(row, col) = 0; sub_map4.at<uint16_t>(row, col) = 0; sub_map5.at<uint16_t>(row, col) = 0; } else { x_diff = x_value - x_temp; y_diff = y_value - y_temp;
main_map.at<int32_t>(row, col) = y_temp * imageSize.width + x_temp; sub_map2.at<uint16_t>(row, col) = (1 - x_diff) * (1 - y_diff) * 65535; sub_map3.at<uint16_t>(row, col) = x_diff * (1 - y_diff) * 65535; sub_map4.at<uint16_t>(row, col) = (1 - x_diff) * y_diff * 65535; sub_map5.at<uint16_t>(row, col) = x_diff * y_diff * 65535; } } }
HalconCpp::HImage main_data, sub_map_data2, sub_map_data3, sub_map_data4, sub_map_data5; int height1 = main_map.rows, width1 = main_map.cols; int size = height1 * width1;
uchar *temp = new uchar[size * 4];
memcpy(temp, main_map.data, size * 4); HalconCpp::GenImage1(&main_data, "int4", imageSize.width, imageSize.height, (Hlong)(temp));
memcpy(temp, sub_map2.data, size * 2); HalconCpp::GenImage1(&sub_map_data2, "uint2", imageSize.width, imageSize.height, (Hlong)(temp));
memcpy(temp, sub_map3.data, size * 2); HalconCpp::GenImage1(&sub_map_data3, "uint2", imageSize.width, imageSize.height, (Hlong)(temp));
memcpy(temp, sub_map4.data, size * 2); HalconCpp::GenImage1(&sub_map_data4, "uint2", imageSize.width, imageSize.height, (Hlong)(temp));
memcpy(temp, sub_map5.data, size * 2); HalconCpp::GenImage1(&sub_map_data5, "uint2", imageSize.width, imageSize.height, (Hlong)(temp)); delete[] temp;
HalconCpp::HImage map_h, map_res_h; Compose5(main_data, sub_map_data2, sub_map_data3, sub_map_data4, sub_map_data5, &map_h);
MapImage(ImageGray, map_h, &map_res_h);
|