HomeSupportVision LibrariesOpenCVOpenCV Installation in Linux → OpenCV Linux Install Deprecated approach

Deprecated OpenCV Installation in Linux

This installation was tested on Ubuntu 12.04 with USB2.0 camera MU9.
Helpful links:

Building OpenCV version 3.1
Support page for OpenCV

Installation

Install XIMEA Linux API package

How to

Download latest release

Open page http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/
Download opencv-2.4.10.zip

Unpack

unzip opencv-2.4.10.zip
cd opencv-2.4.10

Install needed libraries

sudo apt-get install libgtk2.0-dev
sudo apt-get install pkg-config

Build

mkdir build
cd build
# on some systems "-D WITH_TIFF=NO" should be added to options
cmake -D WITH_XIMEA=YES ..
make

Install

sudo make install

Example

Source code

Create file opencv_test.cpp with following content

#include "cv.h" 
#include "highgui.h" 
#include <stdio.h>  
// A Simple Camera Capture Framework 
int main() 
{
   CvCapture* capture = cvCaptureFromCAM( CV_CAP_XIAPI );
   if ( !capture ) {
     fprintf( stderr, "ERROR: capture is NULL \n" );
     getchar();
     return -1;
   }
   // Create a window in which the captured images will be presented
   cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
   // Show the image captured from the camera in the window and repeat
   while ( 1 ) {
     // Get one frame
     IplImage* frame = cvQueryFrame( capture );
     if ( !frame ) {
       fprintf( stderr, "ERROR: frame is null...\n" );
       getchar();
       break;
     }
     cvShowImage( "mywindow", frame );
     // Do not release the frame!
     //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
     //remove higher bits using AND operator
     if ( (cvWaitKey(10) & 255) == 27 ) break;
   }
   // Release the capture device housekeeping
   cvReleaseCapture( &capture );
   cvDestroyWindow( "mywindow" );
   return 0;
}

Example downloaded from: http://opencv.willowgarage.com/wiki/CameraCapture

Compiling

  • run command:
    g++ -I/usr/local/include/opencv opencv_test.cpp -lopencv_highgui -lopencv_videoio
    

    Result of building will be opencv_test.out a.out

Starting

Normal:

./a.out

Some environments needs to force library path:

LD_LIBRARY_PATH=/usr/local/lib ./a.out