Installing opencv on Raspberry pi

JPhoenix report abuse

Hey community, need your help.

How do I install and compile OpenCV on RaspberryPi or Linux?


Best, JPhoenix




WeepingAngel report abuse

Hi JPhoenix,


there seems to a project here on imaginghub: which just then references:

probably helps with your question?



mbinev report abuse


you can do it this way:

If you are about to use OpenCV on ARM based machines like Raspberry Pi (or on Linux) in combination with Pylon in order e.g. to display or save images or to record video files, this solution will provide you with the necessary steps to install OpenCV.


1. Install CMake


CMake is mandatory to compile:


sudo apt-get update
sudo apt-get install cmake 


2. Install OpenCV


Install both dev lib and python lib.

In pylon we usually write code in C++, but Python is still usefull for small scripts. So, we recommend installing it:


sudo apt-get update
sudo apt-get install libopencv-dev
sudo apt-get install python-opencv


To test if OpenCV library is well installed, use the attached test program "display_image.cpp".

It just displays a picture using imread and imshow OpenCV functions. You will need to provide a sample *.JPG file. If you did not provide a *.jpg file you will get a message with the program usage. That is also okay!


To compile using OpenCV lib, use the attached "CMakeLists.txt" file.

You only need to store the display_image.cpp and CMakeLists.txt files on a given location of your Raspberry Pi, where you can write to (e.g. on the Desktop), open a console and navigate to your files.


Build the program

1. cmake ./ <enter>

2. make <enter>

3. Use keyboard/mouse or VNC to open a terminal from within the RPi gui (obviously doesn't work if you're SSH'ing in :)).

4. ./displayimage image.jpg <enter> (where image.jpg is something you've put in there before)


If it works, congratulations, OpenCV is installed.

mbinev report abuse

here come the mentioned files.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
    if( argc != 2)
     cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
     return -1;

    Mat image;
    image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file

    if(! ) // Check for invalid input
        cout <<  "Could not open or find the image" << std::endl ;
        return -1;

    namedWindow( "Display window", WINDOW_AUTOSIZE ); // Create a window for display.
    imshow( "Display window", image ); // Show our image inside it.

    waitKey(0); // Wait for a keystroke in the window
    return 0;


mbinev report abuse

this is the code for "CMakeLists.txt":

cmake_minimum_required(VERSION 2.8)
project( displayimage )
find_package( OpenCV REQUIRED )
add_executable( displayimage display_image.cpp )
target_link_libraries( displayimage ${OpenCV_LIBS} )


Add Answer