opencv重映射用法remap案例用法个人备份

Mat remapTrans(const Mat& img, const Mat A1, const Mat A2)
{
vector points_fitted_u, points_fitted_d;
vector ud_distance;
if (A1.at(1, 0) != 0 && A2.at(1, 0) != 0)
{
double y_up, y_down;
y_up = 0.0; y_down = 0.0;
//Mat img_cp;
//img.copyTo(img_cp);
for (int x = 0; x < img.cols; x++)
{
y_up = A1.at(0, 0) + A1.at(1, 0) * x +
A1.at(2, 0)*pow(x, 2);
y_down = A2.at(0, 0) + A2.at(1, 0) * x +
A2.at(2, 0)*pow(x, 2);
points_fitted_u.push_back(Point(x, y_up));
points_fitted_d.push_back(Point(x, y_down));
ud_distance.push_back(abs(y_down - y_up));
}
cv::Mat srcX(img.rows, img.cols, CV_32F);
cv::Mat srcY(img.rows, img.cols, CV_32F);
float scaleX = 0.05;
float scaleY = 0.05;
float scaldis = 0.0;
for (int j = 0; j < img.cols; j++)
{
for (int i = 0; i < img.rows; i++)
{
//注意:除法运算时候要有小数点,1/2=0,1/2.0=0.5,优先级和强制格式转换
srcX.at(i, j) = j;
srcY.at(i, j) = points_fitted_u[j].y + (ud_distance[j] / img.rows)*i;
}
}
Mat imageRemap=cv::Mat::zeros(img.size(),img.type());
cv::remap(img, imageRemap, srcX, srcY, cv::INTER_AREA); //INTER_AREA INTER_LINEAR
return imageRemap;
}
else
return img;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值