1 | initial version |
Well, the calc_shift seems to be a funny way of undoing the r_new = r_old + k*r_old^3 radial distortion. Not a very stable one.
I'm not sure what the xScale/yScale is supposed to be though. It looks to be checking the error caused by distortion in both directions from the center, adding them together and dividing by the width. So if everything's perfect, the scale is 1. I'm not sure why it's calculated the way it is. As the distortion goes up it drops way faster than I would think would be useful. Depends on what you're using it for, I guess.
It may be worth it to you to replace calc_shift with a better solving method, Newton's method should work fine. But if it's working as is, don't bother.