vector<vector<cv::Point2f>> GenerateSingleMappingTable(cv::Mat mHomography , cv::Size iImageSize , cv::Mat mK , cv::Mat mD , cv::Mat mP){
vector<vector<cv::Point2f>> gMappingTable;
gMappingTable.reserve(iImageSize.height);
for (int y=0;y<iImageSize.height;y++){
//Generate the table of this line.
vector<cv::Point2f> gSubMappingTable;
gSubMappingTable.reserve(iImageSize.width);
for (int x=0;x<iImageSize.width;x++){
cv::Mat mPoint = (cv::Mat_<double>(3 , 1) << x , y , 1);
mPoint = mHomography * mPoint;
mPoint = mK.inv() * mPoint;
cv::Point2f iPoint(mPoint.at<double>(0 , 0)/mPoint.at<double>(2 , 0) , mPoint.at<double>(1 , 0)/mPoint.at<double>(2 , 0));
if (mPoint.at<double>(2 , 0) == 0){
iPoint = cv::Point2f(0 , 0);
}
gSubMappingTable.push_back(iPoint);
}
cv::fisheye::distortPoints(gSubMappingTable, gSubMappingTable, mK, mD);
for (auto & item : gSubMappingTable){
if (item.x <= 0.0){
item.x = 0.0;
}else if (item.x >= (float)(iCameraImageSize.width-1)){
item.x = (float)(iCameraImageSize.width-1);
}
if (item.y <=0.0){
item.y = 0.0;
}else if (item.y >= (float)(iCameraImageSize.height-1)){
item.y = (float)(iCameraImageSize.height-1);
}
}
gMappingTable.push_back(gSubMappingTable);
}
return gMappingTable;
}
void GenerateSingleMappingTable(Mat& map1, Mat& map2, cv::Mat mHomography,cv::Size image_size, cv::Size camera_size, cv::Mat mK, cv::Mat mD)
{
if (map1.total() == 0 || map1.cols != image_size.width || map1.rows != image_size.height)
{
map1.create(image_size, CV_32FC1);
map2.create(image_size, CV_32FC1);
}
for (int y = 0; y < image_size.height; y++) {
//Generate the table of this line.
vector<cv::Point2f> gSubMappingTable;
gSubMappingTable.reserve(image_size.width);
for (int x = 0; x < image_size.width; x++) {
cv::Mat mPoint = (cv::Mat_<double>(3, 1) << x, y, 1);
mPoint = mHomography * mPoint;
mPoint = mK.inv() * mPoint;
cv::Point2f iPoint(mPoint.at<double>(0, 0) / mPoint.at<double>(2, 0), mPoint.at<double>(1, 0) / mPoint.at<double>(2, 0));
if (mPoint.at<double>(2, 0) == 0) {
iPoint = cv::Point2f(0, 0);
}
gSubMappingTable.push_back(iPoint);
}
cv::fisheye::distortPoints(gSubMappingTable, gSubMappingTable, mK, mD);
for (int x = 0; x < image_size.width; ++x)
{
map1.at<float>(y, x) = gSubMappingTable[x].x;
map2.at<float>(y, x) = gSubMappingTable[x].y;
}
}
return;
}