ffmpeg - Setting/Installing up OpenCV 2.4.6.1+ on Ubuntu 12.04.02 -


i had used opencv 2.4.5 configs , packages on ubuntu 12.04.1 had issues upgrading opencv 2.4.6.1 on ubuntu 12.04.2

i share ideas (a compilation of noteworthy information gathered several sources including so, ubuntu.org, asklinux.org , many other; , of course trying several procedures)

below got me through.

note: ensure uninstall previous installation of opencv, ffmpeg , other dependencies installed.

step 1 (install ffmpeg , dependencies)


# goto http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/ # download latest stable opencv such 2.4.6.1 (http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.5/opencv-2.4.5.1.tar.gz/download) current directory (such home or ~/document) # cd /opt # tar -xvf <path-to-download-folder>/opencv-2.4.6.1.tar.gz # cd opencv-2.4.6.1 # create foler under current dir (following previous step, should <opencv-dir>), called prepare # cd prepare # copy following script gedit , save install.sh current dir, should <opencv-dir>/prepare # check corresponding url used in script latest versions of package , replace required # open terminal , navigate location used above # sudo chmod +x install.sh # ./install 

echo "removing pre-installed ffmpeg, x264, , other dependencies (not installed dependecies)" sudo apt-get remove ffmpeg x264 libx264-dev libvpx-dev librtmp0 librtmp-dev libopencv-dev sudo apt-get update  arch=$(uname -m) if [ "$arch" == "i686" -o "$arch" == "i386" -o "$arch" == "i486" -o "$arch" == "i586" ]; flag=0 else flag=1 fi  echo "installing dependenices" sudo apt-get install autoconf automake make g++ curl cmake bzip2 python unzip \   build-essential checkinstall git git-core libass-dev libgpac-dev \   libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libx11-dev \   libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev  echo "downloading yasm (assembler used x264 , ffmpeg)" # use git or tarball (not both) wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz tar xzvf yasm-1.2.0.tar.gz cd yasm-1.2.0  echo "installing yasm" ./configure make sudo make install cd ..  echo 'read note below extracted http://wiki.serviio.org/doku.php?id=build_ffmpeg_linux' echo 'new version of x264 contains default support of opencl. if not installed or without sense (example ubuntu 12.04lts on vmware) add configure additional option --disable-opencl. without option ffmpeg not configured (error: libx264 not found).'  echo "downloading x264 (h.264 video encoder)" # use git or tarball (not both) # git clone http://repo.or.cz/r/x264.git or git clone git://git.videolan.org/x264.git cd x264 # wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20130801-2245-stable.tar.bz2 # tar -xvjf x264-snapshot-20130801-2245-stable.tar.bz2 # cd x264-snapshot-20130801-2245-stable/  echo "installing x264" if [ $flag -eq 0 ]; ./configure --enable-static --disable-opencl else ./configure --enable-shared --enable-pic --disable-opencl fi make sudo make install cd ..  echo "downloading fdk-aac (aac audio encoder)" # use git or tarball (not both) git clone --depth 1 git://github.com/mstorsjo/fdk-aac.git cd fdk-aac  echo "installing fdk-aac" autoreconf -fiv ./configure --disable-shared make sudo make install cd ..  echo "installing libmp3lame-dev (mp3 audio encoder.)" sudo apt-get install libmp3lame-dev  echo "downloading libopus (opus audio decoder , encoder.)" wget http://downloads.xiph.org/releases/opus/opus-1.0.3.tar.gz tar xzvf opus-1.0.3.tar.gz cd opus-1.0.3  echo "installing libopus" ./configure --disable-shared make sudo make install cd ..  echo "downloading libvpx vp8/vp9 video encoder , decoder)" # use git or tarball (not both) git clone --depth 1 http://git.chromium.org/webm/libvpx.git cd libvpx # wget http://webm.googlecode.com/files/libvpx-v1.1.0.tar.bz2 (this seems not update, can still used if fedoraproject link below not available)) # wget http://pkgs.fedoraproject.org/repo/pkgs/libvpx/libvpx-v1.2.0.tar.bz2/400d7c940c5f9d394893d42ae5f463e6/libvpx-v1.2.0.tar.bz2 # tar xvjf libvpx-v1.2.0.tar.bz2 # cd libvpx-v1.2.0  echo "installing libvpx" ./configure --disable-examples make sudo make install cd ..  sudo ldconfig  echo "downloading ffmpeg" # git clone http://repo.or.cz/r/ffmpeg.git git clone git://source.ffmpeg.org/ffmpeg.git cd ffmpeg/ # wget http://ffmpeg.org/releases/ffmpeg-2.0.tar.bz2 # tar -xvjf ffmpeg-2.0.tar.bz2 # cd ffmpeg-2.0/  echo "installing ffmpeg"  if [ $flag -eq 0 ]; ./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx else ./configure --enable-gpl --enable-libass --enable-libfdk-aac --enable-libopus --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab --enable-libvpx --enable-shared fi  make sudo make install hash -r  cd .. # move 1 level prepare folder cd .. # move 1 level opencv folder  echo "checking see if you're using new ffmpeg" ffmpeg 2>&1 | head -n1  sudo ldconfig 

step 2 (install opencv , necessary packages)

echo "installing dependenices"     sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev  echo "installing video i/o libraries, support firewire video cameras , video streaming libraries" sudo apt-get install libav-tools libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev v4l-utils v4l-conf  echo "installing python development environment , python numerical library" sudo apt-get install python-dev python-numpy  echo "installing parallel code processing library (the intel tbb library)" sudo apt-get install libtbb-dev  echo "installing qt dev library" sudo apt-get install libqt4-dev libgtk2.0-dev  echo "installing other dependencies (if need upgrade current version of packages)" sudo apt-get install patch subversion ruby librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev libxvidcore-dev  echo installing optional packages" sudo apt-get install libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev 

step 3 (run ldconfig)

# open new terminal window # open /etc/ld.so.conf , check,  # if paths "/usr/lib" , "/usr/local/lib" including quote exist in file. if not, add them manually or     sudo echo "/usr/local/lib" >> /etc/ld.so.conf     sudo echo "/usr/lib" >> /etc/ld.so.conf # execute following     sudo ldconfig 

step 4a (build & install os usage)

# still ensure haven't close new terminal window open in step 3 # execute following mkdir os_build cd os_build cmake -dcmake_build_type=release -dcmake_install_prefix=/usr/local -dbuild_new_python_support=on -dinstall_python_examples=on -dwith_tbb=on -dwith_v4l=on -dinstall_c_examples=on -dbuild_examples=on -dwith_qt=on -dwith_opengl=on -dwith_opencl=on -dwith_eigen=on -dwith_openexr=on ..      make     sudo make install  # add following user environment variable ~/.bashrc     export ld_library_path=${ld_library_path}:/usr/local/lib     export pkg_config_path=${pkg_config_path}:/usr/local/lib/pkgconfig # execute following     sudo ldconfig # start use , enjoy opencv, should have been install of these locations #   /usr/local/include/opencv2, /usr/local/include/opencv, /usr/include/opencv, /usr/include/opencv2, /usr/local/share/opencv #   /usr/local/share/opencv, /usr/share/opencv, /usr/share/opencv, /usr/local/bin/opencv*, /usr/local/lib/libopencv* 

step 4b (build java usage): optional

# still ensure haven't close new terminal window open in step 4 # execute following     cd ..     mkdir java_build     cd java_build     cmake -dcmake_build_type=release -dbuild_shared_libs=off -dinstall_python_examples=on -dwith_tbb=on -dwith_v4l=on -dinstall_c_examples=on -dbuild_examples=on -dwith_qt=on -dwith_opengl=on -dwith_opencl=on -dwith_eigen=on -dwith_openexr=on ..      make  # can check "java_build/bin" directory locate jar , libopencv_java.so file development # stated in docs, java bindings dynamic library all-sufficient, i.e. doesn’t depend on other opencv libs, includes opencv code inside 

step 5 (install v4l: note: installing v4l-utils after opencv installation works ubuntu 12.04.2 & opencv 2.4.6.1)

# still ensure haven't close new terminal window open in step 3 # goto http://www.linuxtv.org/downloads/v4l-utils # download latest v4l such v4l-utils-0.9.5.tar.bz2 # copy downloaded file current terminal dir (following previous step, should <opencv-dir>/prepare) # execute following     tar -xvjf v4l-utils-0.9.5.tar.bz2     cd v4l-utils-0.9.5/     ./configure     make     sudo make install     cd ..     cd .. # (to go <opencv-dir>)     sudo ldconfig 

worth noting

# check path opencv & other lib files stored, do:   pkg-config --cflags opencv      (output come as)     -i/usr/include/opencv    pkg-config --libs opencv      (output come as)     -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ --ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann  # above paths needed compile opencv programs, given in next illustration.  # write simple c program test, saving below program in file named displayimage.c  #include <stdio.h>     #include <opencv2/highgui/highgui.hpp>      int main(int argc, char *argv[]) {         iplimage* img=0; /* pointer image */         printf("hello\n");          if(argv[1] != 0)             img = cvloadimage(argv[1], 0); // 1 color         else             printf("enter filename\n");          if(img != 0) {             cvnamedwindow("display", cv_window_autosize); // create window             cvshowimage("display", img); // show image in window             cvwaitkey(0); // wait until user hits key             cvdestroywindow("display");         }         else             printf("file not found\n");          return 0;     }  # write simple c++ program test, saving below program in file named displayimage.cpp  #include <stdio.h> #include <opencv2/opencv.hpp> #include <opencv2/highgui/highgui.hpp>  using namespace cv;  int main( int argc, char** argv ) {   mat image;   image = imread( argv[1], 1 );    if( argc != 2 || !image.data )     {       printf( "no image data \n" );       return -1;     }    namedwindow( "display image", cv_window_autosize );   imshow( "display image", image );    waitkey(0);    return 0; }  # compile & run :    g++ <filename: e.g. displayimage.c or displayimage.cpp> `pkg-config --cflags --libs opencv` && ./a.out img  or    g++ -i/usr/include/opencv -i/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree <filename: e.g. displayimage.c or displayimage.cpp> && ./a.out img  “img” name of image extension within same folder . should able see “hello” , image in different window.  if runs, congrats! can run c/c++ program opencv lib.   # lets simplify above big command making shortcut it: go local home directory(cd /home/) , open .bashrc file using gedit(the file hidden). append following file:    alias gcv="g++ -i/usr/include/opencv -i/usr/local/include -lopencv_core -lopencv_highgui -lopencv_ml -lopencv_imgproc -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lopencv_nonfree"  , save. close terminal , open again.(as process requires relogin of terminal)  # now, go directory containing sample program &    gcv <filename: e.g. displayimage.c or displayimage.cpp> && ./a.out  or    gcv <filename: e.g. displayimage.c or displayimage.cpp>     ./a.out input_img.jpg 

as can see commands become similar $cc filename.c, $./a.out used compiling , executing c/c++ programs.


some ways check whether lib files installed-

apt-cache search opencv 

returns:

libcv-dev - translation package libcv-dev libcv2.3 - computer vision library - libcv* translation package libcvaux-dev - translation package libcvaux-dev libcvaux2.3 - computer vision library - libcvaux translation package libhighgui-dev - translation package libhighgui-dev libhighgui2.3 - computer vision library - libhighgui translation package libopencv-calib3d-dev - development files libopencv-calib3d libopencv-calib3d2.3 - computer vision camera calibration library libopencv-contrib-dev - development files libopencv-contrib libopencv-contrib2.3 - computer vision contrib library libopencv-core-dev - development files libopencv-core libopencv-core2.3 - computer vision core library libopencv-dev - development files opencv libopencv-features2d-dev - development files libopencv-features2d libopencv-features2d2.3 - computer vision feature detection , descriptor extraction library libopencv-flann-dev - development files libopencv-flann libopencv-flann2.3 - computer vision clustering , search in multi-dimensional spaces library libopencv-gpu-dev - development files libopencv-gpu libopencv-gpu2.3 - computer vision gpu processing library libopencv-highgui-dev - development files libopencv-highgui libopencv-highgui2.3 - computer vision high-level gui , media i/o library libopencv-imgproc-dev - development files libopencv-imgproc libopencv-imgproc2.3 - computer vision image processing library libopencv-legacy-dev - development files libopencv-legacy libopencv-legacy2.3 - computer vision legacy library libopencv-ml-dev - development files libopencv-ml libopencv-ml2.3 - computer vision machine learning library libopencv-objdetect-dev - development files libopencv-objdetect libopencv-objdetect2.3 - computer vision object detection library libopencv-video-dev - development files libopencv-video libopencv-video2.3 - computer vision video analysis library opencv-doc - opencv documentation , examples python-opencv - python bindings computer vision library 

thanks information. tried run these commands encountered several problems. using brand new ubuntu 12.04 install.

1) first apt-get remove command asked me if wanted remove lot of things wasn't comfortable removing, libreoffice. didn't remove in step, figured okay, since program i've installed java sdk , jre. why did opt such large list of programs remove?

2) adding sudo git , tar commands necessary.

3) when installing opus , ffmpeg, there many error messages ./configure command because of lack of permission writing , configurations failed.

anyways, thought log these problems on post in hopes improve procedure listed above.


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -