鱼眼图片效果(桶形失真)算法(使用 Java)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4978039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:54:36  来源:igfitidea点击:

FishEye Picture Effect (Barrel Distortion) Algorithm (with Java)?

javaimage-processingfisheyedistortion

提问by tsong99

I'm looking for the algorithm (bitmap pixel manipulation) to simulate the fisheye lens (Barrel Distortion) from normal pictures. So far I've found implementation involving external libraries like OpenCV, OpenGL or jhlabs. Since I'm taking a class in Digital Image Processing and I'm making a course assessment project, I'm not sure whether using any external lib will earn me a good grade. So would anyone give me the reference to such algorithm?

我正在寻找算法(位图像素操作)来模拟普通图片中的鱼眼镜头(桶形失真)。到目前为止,我已经找到了涉及 OpenCV、OpenGL 或 jhlab 等外部库的实现。由于我正在上数字图像处理课程并且正在制作课程评估项目,因此我不确定使用任何外部库是否会让我获得好成绩。那么有人会给我参考这种算法吗?

Ps. I'm asked to implement it in Java, but example from any language would do.

附言。我被要求用 Java 实现它,但任何语言的例子都可以。

回答by mpenkov

It's good that you've been able to find examples that do what you want. It's helpful to include them in your question -- it makes sure that people that read it are on the same page as you are. So here's a link.

很高兴您能够找到满足您要求的示例。将它们包含在您的问题中很有帮助——它可以确保阅读它的人与您在同一页面上。所以这是一个链接

It's also good that you want to do things by yourself, without relying on some library to do the hard work for you. But that doesn't mean you have to ignoresuch solutions. Here's why.

你想自己做事情也很好,而不是依靠一些图书馆来为你做艰苦的工作。但这并不意味着您必须忽略此类解决方案。这是为什么。

Look at what OpenCV is actually being used for in that link. These are functions that start with cv:

查看该链接中实际使用 OpenCV 的用途。这些函数以 开头cv

$ grep -o "cv\w*" barrel.cpp | sort | uniq
cv
cvCreateImage
cvGet2D
cvGetSize
cvLoadImage
cvNamedWindow
cvSaveImage
cvSet2D
cvShowImage
cvWaitKey

If you look at the OpenCV API, all of these functions just handle mundane tasks like image creation, deletion, display, setting of pixels, etc. None of these tasks are particular to barrel distortion. As far as barrel distortion goes, that solution is not OpenCV specific.

如果您查看OpenCV API,所有这些函数都只是处理普通任务,例如图像创建、删除、显示、像素设置等。这些任务都不是针对桶形失真的。就桶形失真而言,该解决方案不是 OpenCV 特定的

Indeed, the heart of the program is here:

事实上,该计划的核心在这里:

float getRadialX(float x,float y,float cx,float cy,float k){
  x = (x*xscale+xshift);
  y = (y*yscale+yshift);
  float res = x+((x-cx)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
  return res;
}

float getRadialY(float x,float y,float cx,float cy,float k){
  x = (x*xscale+xshift);
  y = (y*yscale+yshift);
  float res = y+((y-cy)*k*((x-cx)*(x-cx)+(y-cy)*(y-cy)));
  return res;
}

Which is just the radial transform formula -- this is the bit that you need to understand. As you can see, there's no OpenCV calls in there.

这只是径向变换公式——这是您需要了解的一点。如您所见,那里没有 OpenCV 调用。