OpenCV2 使用变换图变换图像
给定两个 cv::Mat 矩阵,将源图像中的每个像素映射到目标图像中的像素(R2 到 R2),我想将源图像转换为目标图像。我已经使用 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-
Given two cv::Mat matrices that maps every pixel in the source image to a pixel in the destination image (R2 to R2), I would like to transform a source image to a destination image. I've sucessfuly done so using for loops but it is too slow:
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;
}
}
this basic code works, but VERY slow (my images are bigger than 100x100, and I must use bicubic).
Thanks,
-O-
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OpenCV 有一个很好的函数,称为 remap()。令人惊讶的是,它确实发生了这种转变。
为了加快速度,您应该寻找另一个函数来准备地图,其格式比简单的位置地图对处理器更友好。 (它类似于 mapTransform(),请在 remap() 文档的
另请参阅
部分中查找)快乐重新映射!
There's a nice OpenCV function that's called remap(). And it does, surprisingly, exactly this transform.
To speed it up, you should look for another function that prepares the maps in a format that's a bit more processor-friendly than a simple position map. (It's something like mapTransform(), look for it in the
see also
part of the remap() docs)Happy remapping!