gpt4 book ai didi

image - OpenCV2 使用变换图变换图像

转载 作者:太空宇宙 更新时间:2023-11-03 22:34:59 25 4
gpt4 key购买 nike

给定两个将源图像中的每个像素映射到目标图像中的像素(R2 到 R2)的 cv::Mat 矩阵,我想将源图像转换为目标图像。我已经成功地使用 for 循环完成了,但是它太慢了:

cv::Mat srcImg(100,100,CV_8U);

//fill...

cv::Mat dstImg(100,100,CV_8U);

//dst2src ->backprojection

//these matrices indicates for each pixel in the destination image, where to map it from the source image

cv::Mat x_dst2src(100,100,CV_64F);

cv::Mat y_dst2src(100,100,CV_64F);

//fill...

for(int ydst=0; ydst!=100;++ydst)

{

for(int xdst=0; xdst!=100;++xdst)
{
double xsrc = x_dst2src.at<double>(ydst,xdst);
double ysrc = y_dst2src.at<double>(ydst,xdst);
double val = getBicubic(srcImg,xsrc,ysrc);
dstImg.at<double>(ydst,xdst) = val;

}

}

此基本代码有效,但非常慢(我的图像大于 100x100,我必须使用双三次)。谢谢,

-O-

最佳答案

有一个很好的 OpenCV 函数叫做 remap()。令人惊讶的是,它确实实现了这种转变。

要加快速度,您应该寻找另一个函数,该函数以比简单的位置图对处理器更友好的格式准备 map 。 (它类似于 mapTransform(),请在 remap() 文档的 另请参阅 部分中查找它)

重新映射愉快!

关于image - OpenCV2 使用变换图变换图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9180600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com