开发者

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

I'm looking for the algorithm (bitmap pixel manipulation) to simulate the fisheye lens (Barrel Distortion) from normal 开发者_如何学Cpictures. 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?

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


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 ignore such solutions. Here's why.

Look at what OpenCV is actually being used for in that link. These are functions that start with 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.

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.


I wrote an article about it in http://www.helviojunior.com.br/fotografia/barrel-and-pincushion-distortion/


https://android.googlesource.com/platform/frameworks/base/+/ac39c604d6df8631922c2295b3341cd561f172a5/media/mca/filterpacks/java/android/filterpacks/imageproc/FisheyeFilter.java

this should be what you want.

look at the shader mFishEyeShader and updateProgramParams()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜