Radu Cotescu's professional blog

g33k w17h pa45510n

Resolving Vertically Flipped Images From Webcams in Ubuntu

UPDATE 2: I strongly recommend against using this patch any more and relaying on the solution provided by UPDATE 1.

UPDATE 1: Please check the solution from here as it represents the correct approach for fixing this problem in Ubuntu (all releases). Also, the patch from this post doesn’t work for the kernel included in Ubuntu 9.10.

Usually I do not use my laptop’s webcam. Not that I use another webcam. But when I made the radical switch from Windows to Ubuntu, I was disappointed to see that the images from my webcam were vertically flipped and I had no option of turning them 180°. The almost mythical explanation is that somehow some of the webcams mounted on laptops were mounted flipped and the producers have corrected this by pushing the repairs into the Windows drivers. Today luck seemed to be on my side as I have found a patch that now fixes my problem. To correctly apply it in Ubuntu 9.04 you have to browse that topic until the 12th page and check this post.

Because some of you might not correctly apply the patch, I have built a script that will help you patch the uvcvideo module in order to get the right images from your webcam. There are two patches available (I have chosen only the patches that provide a non-mirrored image) so pick the one that gives you the best image. To be able to compare them you must apply both patches, testing your webcam after each of them and then, for the third time, apply the patch that suites your needs.

To test your webcam, you can use VLC.

Here’s the short how to:

  1. install VLC if you do not have it:

     sudo apt-get install vlc
  2. download my script from here (right click, Save link as…) and make it executable:

     chmod +x flip_webcam
  3. make sure you have the build-essential package:

     sudo apt-get install build-essential
  4. run the script with super-user privileges from where you have downloaded it, providing the right options:

     This script must be run with super-user privileges.
     Usage: ./flip_webcam {OPTION}
          1      this applies patch1 file
          2      this applies patch2 file
         -h, --help  displays this beautiful help section

The script will automatically download the needed files, will apply the patch and then it will push the module into your kernel. Do the tests by opening VLC and then following these steps:

  1. go to Media
  2. then go to Open capture device…
  3. in the pop-up window that opens, in the “Video device name” text field, insert /dev/video0
  4. click on Play

Remember to run the script whenever your kernel changes. If everything worked okay, drop a Kudos line to me in the comments. :)

Code, How To, Linux, Ubuntu

« Lazy programmers do... VirtualBox USB support »