如何用openCV模拟鱼眼镜头效果?
我正在寻找创建鱼眼镜头效果的方法,查看了 openCV 的文档,它看起来包含用于像鱼眼这样的径向畸变的相机校准功能。 openCV可以模拟鱼眼畸变吗?
如果可以用openCV来做,与openGL相比,哪一个会产生更好的结果?谢谢。
I am looking for ways to create fisheye lens effect, looked at documentations for openCV, it looks like it contains Camera Calibration functions for radial distortions like fisheye. Is it possible to simulate fisheye distortion by openCV?
If it is possible to do it by openCV, comparing to openGL, which one will generate better results? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我使用 opencv 创建了这个应用程序。这就是你说的效果吗?
我基本上编写了维基百科“失真(光学)”上显示的公式,如果需要,我可以显示代码
更新:
好的,下面是使用 opencv 用 c++ 编写的实际代码(未记录,因此请随时寻求解释):
该程序接收以下参数作为输入:|输入图像| |输出图像| |控制失真量的 K(通常尝试 0.001 左右的值)| |变形中心的 x 坐标| |变形中心的 y 坐标|
因此,程序的关键是双 for 循环,它在结果图像上逐像素迭代,并使用径向畸变公式在输入图像中查找匹配像素(这是图像扭曲的方式)通常是这样做的 - 也许通过从输出到输入的反投影来直观地反驳)。有一些微妙之处与输出图像的比例有关(在这个程序中,生成的图像与输入的大小相同),除非您想了解更多细节,否则我不会讨论它。享受。
I created this app using opencv. Is this the effect you are referring to?
I basically coded the formula shown on wikipedia's "Distortion(optics)" I can show the code if needed
Update:
OK, so below is the actual code written in c++ using opencv (not documented so feel free to ask for explanations):
The program recieves as input the following parameter: |input image| |output image| |K which controlls amount of distortion (typically try values around 0.001)| |x coordinate of center of distortion| |y coordinate of center of distortion|
So the crux of the program is the double for loop which iterates pixel by pixel on the result image and looks for the matching pixel in the input image using the formula for radial distortion (this is the way image warping is generally done - perhaps counter intuitively by back-projection from output to input). There are some subtleties which have to do with the scale of the output image (in this program the resulting image is the same size as the input), and I won't get into it unless you want to get into more details.enjoy.
感谢以上2位提供的这段代码。我修改了上面的 Java 转录代码以使用位图而不是 BufferedImage。这使得代码能够在Android(不支持AWT)上运行。我还制作了仅操纵圆形像素而不是整个位图的效果,这给出了鱼眼“镜头”效果。希望这对任何 Android 开发者有所帮助。
。
@And_Dev 正如所承诺的,
下面是让用户触摸坐标然后在选定区域上调用过滤器的视图。所选区域是绳索,例如圆心加上半径(圆)。该代码执行此操作的次数是隆胸应用程序的两倍:)只需注释掉 HorizontalSlider 代码,因为您不需要它。
。
调用活动。
如果您需要任何帮助,请询问。希望这有帮助
Thanks to the above 2 for this code. I've modified the above transcribed code in Java to use Bitmaps instead of BufferedImage. This enables the code to run on Android(which doesn't support AWT). I've also made the effect just manipulate the pixels in a circle rather than the whole Bitmap, this gives a fisheye "lens" effect. Hopes this helps any Android developers.
.
@And_Dev as promised
Below is the view that gets the users touch co-ords and then calls the filter on a selected area. the selected area is the cord eg center of circle plus a radius(a circle). the code does this twice as its for a breast augmentation app:) Just comment out the HorizontalSlider code as you don't need this.
.
The calling activity.
If you need any help mate just ask. hope this helps
感谢您提供该代码。这对我有很大帮助。我将其转加密为 Java。也许有人有类似的功能来模拟切向畸变?
Thanks to you for that code. It helps me a lot. I transcrypted it for Java. Maybe someone has a similar function for symulating tangencial distorsion?
我调试了java文件,它在我的手机上运行良好(高于4.0)。它由3个java文件和1个xml文件组成。您必须将 checkerboardback.jpg 文件放在可绘制目录下。正如有人所说,缺少 alpha 值,我给它“0x0ff”。另外,一些Looping的上限是错误的。
//1. MultiRuntimeProcessorFilter.java
// 2. Filters.java:
以及
//3 MainActivity.java,顶级类。
这
是 XML 文件
//4活动_main.xml
I debugged the java files and it works fine on my phones(higher than 4.0). It consists of 3 java files and 1 xml file. You have to place checkerboardback.jpg file under drawaable directory. As someone said, alpha value was missing and I gave it "0x0ff". In addition, upperbound of some Looping were wrong.
//1. MultiRuntimeProcessorFilter.java
// 2. Filters.java:
And
//3 MainActivity.java, toplevel class.
}
Here is XML file
//4 activity_main.xml
您想在合成图像上使用这种失真,还是想应用于摄像机或其他东西?
在 OpenCv 中,您应该能够进行相机校准(使用内置函数,张算法)..
在 OpenGL 看到这个。
问候
Do you want to use this distortion on sintetic images, or do you want to apply to a video camera or something ?
In OpenCv you should be able to do camera calibration (using the built-in functions, Zhang's algorithm) ..
In OpenGL see this.
Regards