Search Unity

Shader to undistort webcam video

Discussion in 'Shaders' started by doktor3d, Aug 28, 2013.

  1. doktor3d

    doktor3d

    Joined:
    May 7, 2013
    Posts:
    9
    I have a plane in my scene that I am texturing with a live feed from a USB webcam using WebCamTexture. The plane has the same 1:1.78 aspect ratio as the webcam feed, so shows the whole video frame as it would look in Skype or whatever.

    However, simply projecting the webcam video onto this flat plane of course suffers from normal barrel distortion of cheap cameras. This distortion is particularly pronounced as the cameras have a wide (120 degree) field-of-view lens.

    I assume a shader would be the best way to correct for this distortion. The other possibility would perhaps be projecting the webcam video onto a mesh geometry that is the inverse of the webcam lens distortion. However, the shader approach seems to be the more general solution.

    Does anyone have any ideas to get started on this? I have calibrated my camera with OpenCV and so I have the camera's distortion coefficients.