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

a 夏天 提交于 2019-12-03 08:41:49
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 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!