Raspberry Pi Camera with OpenCV

I have OpenCV code using cvCreateCameraCapture and cvQueryFrame. Can I use it with the Raspberry Pi Camera? Well yes, read on to know how.

The Raspberry Pi Camera is widely available now, but there aren’t any open source video4linux (v4l) for it yet. Among other things, this makes it harder to use OpenCV with the camera.

When searching for a solution, I found Pierre Raufast’s blog, where he solves this problem. He took the existing userland libraries, which provide the source for the raspistill and raspivid tools. He modified them to produce OpenCV images instead.

Excellent news! So I now I can use this in my own OpenCV projects, and bypass the v4l drivers issue entirely. But wait, my code already calls cvCreateCameraCapture, cvQueryFrame in its own main loop, how do I do this?

I took Pierre Raufast’s modified camcv_vid0.c file and converted it into a library.

Instead of calling cvCreateCameraCapture and cvQueryFrame, you call the new raspi cam equivalents: raspiCamCvCreateCameraCapture and raspiCamCvQueryFrame. Instead of using a CvCapture, you use a RaspiCamCvCapture.

It’s a plain and simple search and replace operation in your code.

My source is here, it creates a library called libraspicamcv.a, you need to link with it and  #include “RaspiCamCV.h”

A more detailed README on how to compile and use it is the code repository itself.

This is a work in progress, I’ve done limited testing on the library. Contact me if you find bugs.

There is a raspiCamCvSetCaptureProperty method as well, but it doesn’t do anything yet. I plan to update it in the future,  to change parameters like: state->width, state->height, and state->graymode

For now, they are hardcoded in RaspiCamCV.c, so you need to change the code, and recompile the library to change resolution, or switch to grayscale mode (which is much faster).

121 Responses to Raspberry Pi Camera with OpenCV

  1. […] on Pierre’s work, Emil Valkov has produced a library of C functions that allows you to capture images from the camera…. It is thus easy to start building machine vision projects, using the OpenCV framework, on the Pi […]

  2. Rob Garnett says:

    Hi

    I like your stuff, but when I ran “./buildme” I got the following error:

    CMake Error: your C compiler: “arm-linux-gnueabihf-gcc” was not found. Please set CMAKE_C_COMPILER to a valid compiler path. or name.

    I have the following questions:

    1. Which compiler should I use.
    2. Where do I get it
    3. How do I install it
    4. How do I ensure that your nake files will point to that compiler to run it

    Best regards

    Rob Garnett

    • Emil Valkov says:

      You need to install gcc and g++, and probably some other libraries you’ll need down the road.

      sudo apt-get install gcc g++ libx11-dev libxt-dev libxext-dev libgraphicsmagick1-dev libcv-dev libhighgui-dev

  3. maximofn says:

    Dou you can show an example that uses this library?

    Thanks

  4. maximofn says:

    Hello

    When I write “git clone https://github.com/robidouille/robidouille.git” I have this

    “Cloning into ‘robidouille’…
    error: The requested URL returned error: 503 while accessing https://github.com/robidouille/robidouille.git/info/refs
    fatal: HTTP request failed”

    Regards

  5. maximofn says:

    Hello

    I think there is an error in the

    “To build the raspicam library:
    ————————————————–
    mkdir-p ~ / git
    cd ~ / git
    git clone https://github.com/robidouille/robidouille.git
    cd raspicam_cv
    mkdir objs
    make ”

    When you run the command

    “git clone https://github.com/robidouille/robidouille.git

    This copies the directory into ~/git/robidouille

    Therefore the command

    “cd raspicam_cv”

    It should be

    “cd robidouille / raspicam_cv”

    Please correct me if I’m wrong

    Regards

  6. maximofn says:

    I finished it and it works!!!! 🙂

    thank you very much!

    Regards

  7. HanZ4000 says:

    Hello
    I get an Error in the following commands:
    To build the raspicam library:
    ————————————————–
    mkdir -p ~/git
    cd ~/git
    git clone https://github.com/robidouille/robidouille.git
    cd robidouille/raspicam_cv
    mkdir objs
    make

    The command “make” brings me the following error:

    pi@raspberrypi ~/git/robidouille/raspicam_cv $ make
    gcc -c -Wno-multichar -g -I/usr/include/opencv -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamCV.c -o objs/RaspiCamCV.o
    In file included from /usr/local/include/opencv2/core/core.hpp:48:0,
    from /usr/include/opencv/cv.h:64,
    from RaspiCamCV.c:38:
    /usr/local/include/opencv2/core.hpp:47:4: error: #error core.hpp header must be compiled as C++
    In file included from /usr/local/include/opencv2/core.hpp:52:0,
    from /usr/local/include/opencv2/core/core.hpp:48,
    from /usr/include/opencv/cv.h:64,
    from RaspiCamCV.c:38:
    /usr/local/include/opencv2/core/base.hpp:48:4: error: #error base.hpp header must be compiled as C++
    /usr/local/include/opencv2/core/base.hpp:51:19: fatal error: climits: Datei oder Verzeichnis nicht gefunden
    compilation terminated.
    make: *** [objs/RaspiCamCV.o] Fehler 1

    Nevertheless the command “make” createt “libraspicamcv.a” and “raspicamtest”. See here:
    pi@raspberrypi ~/git/robidouille/raspicam_cv $ ls
    Makefile objs RaspiCamCV.c RaspiCamCV.h RaspiCamTest.c README

    I use OpenCV in the current version (2.4.x) for my raspberry pi board. OpenCV is correct installed ’cause I can compile OpenCV C++ programs and C programs without problems.

    Thank you, if you want to help me 🙂

    Greeting from Germany

    • Emil Valkov says:

      How did you install OpenCV ?

      • HanZ4000 says:

        I installed OpenCV with this tutorial: http://bsnx.net/blog/?p=256
        with these commands:
        sudo apt-get install build-essential cmake git-core libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev

        mkdir opencv-build
        cd opencv-build

        git clone https://github.com/Itseez/opencv.git
        cd opencv
        cmake .
        make
        sudo make install

        My professor in informatic said, the header “core.hpp” and “base.hpp” need to compiled with a C++ Compiler. My programm-file “RaspiCamCV.c” has the suffix *.c and calls the usually c compiler. That’s the problem was he said.

        Is the library of your designs with this error functional?

      • HanZ4000 says:

        Update:
        I change in the file “RaspiCamCV.c” in line 38 and 39
        #include to #include
        #include to #include !
        and the same in the RaspiCamTest.c – File

        Now I have
        -libraspicamcv.a: the raspberry cam library which provides an opencv like interface
        -raspicamtest: a small test app which uses the library

        The command make don’t produced errors.
        And your raspicamtest runs great !

        But one question: How i compile my own project?
        I try following:
        C_INCLUDE_PATH=~/git/robidouille/
        export C_INCLUDE_PATH

        and

        gcc `pkg-config –cflags opencv` `pkg-config –libs opencv` -I -L ~/git/robidouille/raspicam_cv -lraspicamcv -L ~/git/raspberrypi/userland/build/lib -lmmal_core -l mmal_util -lvcos -lbcm_host -std=c99 -o robotControl main.c

        I get following error:
        /usr/bin/ld: cannot find /home/pi/git/robouille/raspicam_cv: File format not recognized
        /usr/bin/ld: cannot find -lraspicamcv
        collect2: ld returned 1 exit status

        Where is the failure?

      • Emil Valkov says:

        I’m happy you were able to make it work.

        I would remove the space after -L

        Try to replace your:
        -L ~/git/robidouille/raspicam_cv
        with:
        -L~/git/robidouille/raspicam_cv
        or maybe even without the ~
        -L/home/pi/git/robidouille/raspicam_cv

        Going back to your problems with .hpp files. Since it works now, maybe you don’t want to break it again. So I would perfectly understand if you leave it as is.

        However, I do want to say that I find it strange that #include “cv.h”, which is a pure “C” file, would end up including C++ .hpp files. I don’t know much about the OpenCV distribution you are using, but I would use the official version installed using apt-get. Or if you need something more up to date, then I would download the official version from willow garage.

        I found this blog entry, which explains it: http://avogradonumber.wordpress.com/2013/04/21/install-opencv-in-the-raspberry-pi/

        Good luck!
        Emil

  8. Mario says:

    Good work.

    I appreciate your hardwork for developing such a piece of code where we can access RaspiCam video on OpenCV window.

    Our code worked fine for me.

    It would be good to me if i can wrap the OpenCV window in a panel of gui which i have built using wxpython.

    • Emil Valkov says:

      Thanks!
      Yes my approach was much easier than creating a real v4l driver for the raspicam, but only works for C/C++ projects.
      Doing such a driver would just make the regular OpenCV work, and also Python, but is significantly more work.
      I know there are other projects which are trying to do it. One is available but closed source, and the other is not ready.

      Another approach could be to make a Python module for my library, just like the OpenCV python module which already exists, and wxPython which is also a Python wrapper for a C++ library.
      Or a similar solution, would be modify the existing OpenCV Python module, and add just my library there.

  9. fleuri says:

    Hi everyone,
    When I want compile the raspicam library, I have an error on the Makefile : NO RULES TO CREATE THE TARGET objs/RaspiCamControl.o needs for “libraspicam.cv” stop
    Do you have a solution to fix this problem ?

    Thanks

    • Emil Valkov says:

      Did you do the “mkdir objs” step in the readme?

      • Philip says:

        Hi, I got the same error, when I used a different location for the to git project. But when I used the folders sugested in the readme i dont get the error.

      • Emil Valkov says:

        Good point, thanks !
        If your userland library is in another directory than the one I have, you need to update the USERLAND_ROOT variable in the Makefile.

      • fleuri says:

        ok I try this thanks =)

      • fleuri says:

        When I try to download theses files with git I have the following errors :

        Cloning into ‘userland’…
        error: Failed connect to github.com:443; Connection timed out while accessing https://github.com/raspberrypi/userland.git/info/refs
        fatal: HTTP request failed

        Do you have any ideas to fix this ?
        Thank you from France =)

      • Emil Valkov says:

        It works for me. Perhaps your raspi wasn’t connected to the internet when you tried this.
        Or maybe github was temporarily down, which is unlikely, but possible.

        a+
        Emil

      • fleuri says:

        Thanks a lot, it works =) but I have a last question (I hope) Do you have a little explanation to use the library because I don’t know where I can use the commands :
        -I$(HOME)/git/robidouille/raspicam_cv and
        -L$(HOME)/git/robidouille/raspicam_cv -lraspicamcv
        Should I use a makefile ?
        Thank you

      • Emil Valkov says:

        Yes I use those in a Makefile, and you can take the RaspiCamTest.c portion as an example of how to do it.

        You can also use another system if it better suits you.
        What those 2 lines mean is:
        -add $(HOME)/git/robidouille/raspicam_cv as an “include” directory. This makes #include “RaspiCamCV.h” work when you compile your project. Without it you generally get “cannot find include file …” errors.
        -link the $(HOME)/git/robidouille/raspicamcv library into the project. This actually adds the code into your final program. Without it you get “unresolved external” errors.

        HTH,
        Emil

  10. […] by Emil Valkov, based on Pierre’s previous work. Well,  what do you know. I went straight to his blog and checked it […]

  11. Tojtok says:

    Hi Emil, can you tell me your framerate and latency? I installed a fresh Raspian, update/upgrade, followed your readme.txt installation guide and have about 3 seconds latency at 640×480. Is this normal or do you have any solution for this problem?

    • Emil Valkov says:

      I haven’t measured precisely, but my latency is definitely less than 1s.
      I’ve seen cases where latency is higher, but that’s for higher resolutions or bitrates.
      Are you using the default values:
      state->width = 640; // use a multiple of 320 (640, 1280)
      state->height = 480; // use a multiple of 240 (480, 960)
      state->bitrate = 17000000; // This is a decent default bitrate for 1080p
      state->framerate = 30;

      • Tojtok says:

        Thank you for the fast response. It’s running with the default values of 640×480. With higher resolutions it’s about 6secs and about 2s at 320×240. I did not change anything and followed your instructions step by step. Fresh installation (2 times now),
        camera enabled, apt-get update/upgrade, git userland, git robidouille, make, and started the example program.
        As far as I’ve seen there were no compiler/make errors or anything else. I think turn on the camera support in raspi-config was right?

      • Emil Valkov says:

        Have you tried reducing the bitrate? My default value may be a bit high.

      • Tojtok says:

        Too bad I have no remote access configured yet, I’ll try it when I’m back at home. What bitrate would you suggest or can you give me an overview of the parameters you’re working with? Do you know if there is enough cpu power left to do some kind of object tracking when running at about 3-4 fps? Kind regards & thanks for your help

      • Emil Valkov says:

        Pierre Raufast was able to do face recognition.

        OpenCV&Pi Cam – Step 7 : Face recognition

  12. Steve Cox says:

    hello ,
    I have followed the steps, but when I run:
    sudo ./raspicamtest
    I get the following message:
    (RaspiCamTest:14072): Gtk-WARNING **: cannot open display:
    Do you have any ideas?

    • Emil Valkov says:

      You need to run it within an X server.
      Type startx first, open a terminal window, and launch raspicamtest from there.

      • abhi0329 says:

        Hi I am using 3.5 inch tft screen. After boot I type the “startx” and launch the screen. Now when I am running a basic hello world program using opencv “cvNamedWindow( “result”, CV_WINDOW_AUTOSIZE );”, it doesn’t create any window, it doesn’t either gives any error message too. However I draw a window using GTK it draw the window. Any help or pointer ?. Thanks a lot for your awesome work.
        The thing which I did is “export DISPLAY=:0.0”

  13. Poola says:

    Hi Emil
    Thank u for the great blog.
    Build and Make worked well. and i wrote a C++ program for the same , but Iam having problem while linking.
    with the command
    -gcc `pkg-config –cflags opencv` `pkg-config –libs opencv` -I/home/pi/git/robidouille/raspicam_cv -L/home/pi/git/robidouille/raspicam_cv -llibraspicamcv L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -l mmal_util -lvcos -lbcm_host -o main main.cpp

    the error is
    /usr/bin/ld: cannot find -lraspicamcv
    collect2: ld returned 1 exit status

    i changed
    -L/home/pi/git/robidouille/raspicam_cv -llibraspicamcv to -L/home/pi/git/robidouille/raspicam_cv/llibraspicamcv.a
    this gives me
    main.cpp:(.text+0*68):undefined reference to ‘raspiCamCvCreateCameraCapture’
    main.cpp.text+0768):undefined reference to ‘raspiCamCvQueryFrame
    collect2: ld returned 1 exit status

    Not able to link the libraries..

    Could you please help me find the mistake and to resolve the mistake.

    Thanks
    Poola

  14. Will says:

    Hello Emil,
    Firstly let me say thank you for providing this “api” to use with the raspberrypi’s camera module.
    I’m having a bit of trouble getting the module to function inside my c++ code the error i’m getting in particular is as follows:

    fatal error: RaspiCamCV.h: No such file or directory

    Any idea how to solve this issue? Its causing me a lot of headaches, Any ideas whats causing this?

    • Emil Valkov says:

      It’s not finding the raspicam-cv includes. See this line in the README:

      To use it in your own project:
      ————————————————–
      add the include path: -I$(HOME)/git/robidouille/raspicam_cv
      link with the raspicamcv library: -L$(HOME)/git/robidouille/raspicam_cv -lraspicamcv
      link with the userland libraries: -L$(HOME)/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host

      • Frank Lister says:

        Hello Emil and thank you for you work and inspiration. I was able to follow along with your instructions and worked through areas I was not familiar with. All this Linux programming a little new to me.
        I got to this part

        To use it in your own project:
        ————————————————–
        add the include path: -I$(HOME)/git/robidouille/raspicam_cv
        link with the raspicamcv library: -L$(HOME)/git/robidouille/raspicam_cv -lraspicamcv
        link with the userland libraries: -L$(HOME)/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host

        I am stuck. I do not know where to put this 😦 Does it go into a MakeFile, if so, which one?

        Is $(HOME) a variable for the home address? Can I just hard code it?

        Thanks for your help

      • Emil Valkov says:

        $(HOME) is your home directory. Generally /home/pi
        If you’ve configured your own user “frank”, it could be /home/frank
        And yes, you can hardcode it when you know the right value you’re using.

        These lines should be used to compile your own project.
        If you’re using a Makefile, then yes they’ll go into that Makefile.
        If you’re using some IDE, there are some settings somewhere to add library paths, include paths, and libraries, and you’ll need to add the correct values there.

      • Frank Lister says:

        Hello again Emil. I have tried, but have not been successful 😦
        I am trying to modify Cedric’s Verstraeten makefile that he created for a PI and USB camera.

        http://blog.cedric.ws/raspberry-pi-opencv-create-a-security-system-web-interface#comment-1324139426

        I just started with makefiles and cannot understand a lot about them. I’ve watched some YouTube videos, but not helping.

        In the code below (makefile), where do I add

        -I$(HOME)/git/robidouille/raspicam_cv
        -L$(HOME)/git/robidouille/raspicam_cv -lraspicamcv
        -L$(HOME)/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host

        vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv

        # CMAKE generated file: DO NOT EDIT!
        # Generated by “Unix Makefiles” Generator, CMake Version 2.8

        # Default target executed when no arguments are given to make.
        default_target: all
        .PHONY : default_target

        #=============================================================================
        # Special targets provided by cmake.

        # Disable implicit rules so canonical targets will work.
        .SUFFIXES:

        # Remove some rules from gmake that .SUFFIXES does not remove.
        SUFFIXES =

        .SUFFIXES: .hpux_make_needs_suffix_list

        # Suppress display of executed commands.
        $(VERBOSE).SILENT:

        # A target that is always out of date.
        cmake_force:
        .PHONY : cmake_force

        #=============================================================================
        # Set environment variables for the build.

        # The shell in which to execute make rules.
        SHELL = /bin/sh

        # The CMake executable.
        CMAKE_COMMAND = /usr/bin/cmake

        # The command to remove a file.
        RM = /usr/bin/cmake -E remove -f

        # Escaping for special characters.
        EQUALS = =

        # The program to use to edit the cache.
        CMAKE_EDIT_COMMAND = /usr/bin/ccmake

        # The top-level source directory on which CMake was run.
        CMAKE_SOURCE_DIR = /home/pi/motion_src

        # The top-level build directory on which CMake was run.
        CMAKE_BINARY_DIR = /home/pi/motion_src

        HOME = /home/pi

        #=============================================================================
        # Targets provided globally by CMake.

        # Special rule for the target edit_cache
        edit_cache:
        @$(CMAKE_COMMAND) -E cmake_echo_color –switch=$(COLOR) –cyan “Running CMake cache editor…”
        /usr/bin/ccmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
        .PHONY : edit_cache

        # Special rule for the target edit_cache
        edit_cache/fast: edit_cache
        .PHONY : edit_cache/fast

        # Special rule for the target rebuild_cache
        rebuild_cache:
        @$(CMAKE_COMMAND) -E cmake_echo_color –switch=$(COLOR) –cyan “Running CMake to regenerate build system…”
        /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
        .PHONY : rebuild_cache

        # Special rule for the target rebuild_cache
        rebuild_cache/fast: rebuild_cache
        .PHONY : rebuild_cache/fast

        # The main all target
        all: cmake_check_build_system
        $(CMAKE_COMMAND) -E cmake_progress_start /home/pi/motion_src/CMakeFiles /home/pi/motion_src/CMakeFiles/progress.marks
        $(MAKE) -f CMakeFiles/Makefile2 all
        $(CMAKE_COMMAND) -E cmake_progress_start /home/pi/motion_src/CMakeFiles 0
        .PHONY : all

        # The main clean target
        clean:
        $(MAKE) -f CMakeFiles/Makefile2 clean
        .PHONY : clean

        # The main clean target
        clean/fast: clean
        .PHONY : clean/fast

        # Prepare targets for installation.
        preinstall: all
        $(MAKE) -f CMakeFiles/Makefile2 preinstall
        .PHONY : preinstall

        # Prepare targets for installation.
        preinstall/fast:
        $(MAKE) -f CMakeFiles/Makefile2 preinstall
        .PHONY : preinstall/fast

        # clear depends
        depend:
        $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) –check-build-system CMakeFiles/Makefile.cmake 1
        .PHONY : depend

        #=============================================================================
        # Target rules for targets named motion

        # Build rule for target.
        motion: cmake_check_build_system
        $(MAKE) -f CMakeFiles/Makefile2 motion
        .PHONY : motion

        # fast build rule for target.
        motion/fast:
        $(MAKE) -f CMakeFiles/motion.dir/build.make CMakeFiles/motion.dir/build
        .PHONY : motion/fast

        # target to build an object file
        src/motion.o:
        $(MAKE) -f CMakeFiles/motion.dir/build.make CMakeFiles/motion.dir/src/motion.o
        .PHONY : src/motion.o

        # target to preprocess a source file
        src/motion.i:
        $(MAKE) -f CMakeFiles/motion.dir/build.make CMakeFiles/motion.dir/src/motion.i
        .PHONY : src/motion.i

        # target to generate assembly for a file
        src/motion.s:
        $(MAKE) -f CMakeFiles/motion.dir/build.make CMakeFiles/motion.dir/src/motion.s
        .PHONY : src/motion.s

        # Help Target
        help:
        @echo “The following are some of the valid targets for this Makefile:”
        @echo “… all (the default if no target is provided)”
        @echo “… clean”
        @echo “… depend”
        @echo “… edit_cache”
        @echo “… motion”
        @echo “… rebuild_cache”
        @echo “… src/motion.o”
        @echo “… src/motion.i”
        @echo “… src/motion.s”
        .PHONY : help

        #=============================================================================
        # Special targets to cleanup operation of make.

        # Special rule to run CMake to check the build system integrity.
        # No rule that depends on this can have commands that come from listfiles
        # because they might be regenerated.
        cmake_check_build_system:
        $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) –check-build-system CMakeFiles/Makefile.cmake 0
        .PHONY : cmake_check_build_system

      • Emil Valkov says:

        I’m not very familiar with cmake, seems like atmaklasik is having similar issues, maybe those posts can help?

      • Frank Lister says:

        Good morning Emil,
        working with the motion.cpp file I get errors about cvCaptureFromCAM and RaspiCamCvCapture not working together.

        it appears to me, and I may be wrong, that RaspiCamCvCapture * camera is receiving data from cvCaptureFromCAM(CV_CAP_ANY) ???

        I am not certain, but is this where RaspiCamCvCapture and camera are being defined ??

        I commented out the width and height of the cvSetCaptureProperty (I can use the defaults).

        Does your libraries work cvCaptureFromCAM ?

        Any suggestion?

        CODE
        ————————————————————————–
        RaspiCamCvCapture * camera = cvCaptureFromCAM(CV_CAP_ANY);
        ///////cvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_WIDTH, 1280); // width of viewport of camera
        ///////cvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_HEIGHT, 720); // height of …

        ERROR
        ————————————————————————–
        pi@raspberrypi ~/motion_src $ make
        [100%] Building CXX object CMakeFiles/motion.dir/src/motion.o
        /home/pi/motion_src/src/motion.cpp: In function ‘int main(int, char* const*)’:
        /home/pi/motion_src/src/motion.cpp:133:61: error: cannot convert ‘CvCapture*’ to ‘RaspiCamCvCapture*’ in initialization
        make[2]: *** [CMakeFiles/motion.dir/src/motion.o] Error 1
        make[1]: *** [CMakeFiles/motion.dir/all] Error 2
        make: *** [all] Error 2

  15. […] un moyen simple pour installer tout ça. Et j’y suis arrivé (enfin j’espère) ici, ici et ici […]

  16. atheod says:

    I’m getting this error when i make:
    -MD RaspiCamCV.c -o objs/RaspiCamCV.o
    RaspiCamCV.c:38:16: fatal error: cv.h: No such file or directory
    compilation terminated.
    make: *** [objs/RaspiCamCV.o] Error 1 I’m a newbie to all of this so maybe I did something wrong?

    • Emil Valkov says:

      Are you sure you have opencv installed?
      Please follow all the instructions in the README.

      • Anupal Bora says:

        atheod, you will need to edit the raspicamcv.c and raspicamtest.c file, this is because in the file there is the line #include and #include and this file not able to get them. You will need to find the path these file. For me it was as this location. “/usr/local/include/opencv”. to find the path in your machine use “pkg-config –cflags opencv” in the terminal window.

        your code’s line at position 38 and 39 should look like this :

        #include
        #include

  17. Prak says:

    Hello, I am using raspicam 0.0.6 with opencv and c++. The first frame that I capture comes to be black. What might be the problem ?

  18. jayaprakash says:

    Hello, I’m using cctv camera instead of cmos camera for raspberry
    I m getting video streaming in remote system ,but i’m unable to capture images ………………. Can u help me in rectifying problem

  19. flysse92 says:

    HI,
    I have a little problem when I want to compile one of my program but I have the following errors :

    /tmp/ccdXnMys.o: In function `main’:
    test.cpp:(.text+0x10): undefined reference to `raspiCamCvCreateCameraCapture’
    /tmp/ccdXnMys.o: In function `__static_initialization_and_destruction_0(int, int)’:
    test.cpp:(.text+0x60): undefined reference to `std::ios_base::Init::Init()’
    test.cpp:(.text+0x88): undefined reference to `std::ios_base::Init::~Init()’
    collect2: ld returned 1 exit status

    Here my source code :

    #include
    #include
    #include

    #include “RaspiCamCV.h”

    int main(void)
    {

    char key;
    CvHaarClassifierCascade *cascade;
    CvMemStorage *storage;
    RaspiCamCvCapture *camera = raspiCamCvCreateCameraCapture(0);
    return 0;
    }

    Do you have an idea to fix this ?
    Thanks a lot

  20. atmaklasik says:

    Hi Emil thanks a lot you make this API but i get this error when using it :
    undefined reference to
    (.text.startup+0xdc):raspiCamCvCreateCameraCapture

    (.text.startup+0x170): undefined reference to raspiCamCvQueryFrame

    (.text.startup+0330): undefined reference to raspiCamCvQueryFrame

    (.text.startup+0x348): undefined reference to raspiCamCvQueryFrame

    (.text.startup+0x750): undefined reference to raspiCamCvQueryFrame

    —-and here is my source code : ——-

    //Set Up camera
    RaspiCamCvCapture * camera = raspiCamCvCreateCameraCapture(0);

    raspiCamCvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_WIDTH, 640); //width
    raspiCamCvSetCaptureProperty(camera, CV_CAP_PROP_FRAME_WIDTH, 480); //width

    //Take images
    Mat result, result_cropped;
    Mat prev_frame = result = raspiCamCvQueryFrame(camera);
    Mat current_frame = raspiCamCvQueryFrame(camera);
    Mat next_frame = raspiCamCvQueryFrame(camera);
    cvtColor(current_frame, current_frame, CV_RGB2GRAY);
    cvtColor(prev_frame, prev_frame, CV_RGB2GRAY);
    cvtColor(next_frame, next_frame CV_RGB2GRAY);

    could you help me why this things happend. thanks 🙂

    • Emil Valkov says:

      You need to link my library into your program. See the README, you’re missing the “link with the raspicamcv library” part.

      • atmaklasik says:

        i already linked your library by adding that in my cmake files, what am i missing. or could you please tell me how to link your libraries because i am newbie in using linux. thanks

        here are my cmake files :

        cmake_minimum_required(VERSION 2.4)

        PROJECT(MOTION)
        # paths
        INCLUDE_DIRECTORIES(src)
        INCLUDE_DIRECTORIES(usr/local/include)
        INCLUDE_DIRECTORIES(~/git/raspberrypi/robidouille/raspicam_cv)
        LINK_DIRECTORIES(/usr/local/lib)
        LINK_DIRECTORIES(/usr/lib)
        LINK_DIRECTORIES(~/git/raspberrypi/robidouille/raspicam_cv -lraspicamcv)
        LINK_DIRECTORIES(~/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host)
        SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
        SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin)
        SET(CMAKE_CXX_FLAGS “-o3 -w”)
        SET(CMAKE_CXX_LINK_FLAGS “-pg”)
        SET(OpenCV_LIBRARIES opencv_core opencv_highgui opencv_imgproc)
        ADD_EXECUTABLE(motion motion.cpp)
        TARGET_LINK_LIBRARIES(motion ${OpenCV_LIBRARIES})
        SET(CMAKE_BUILD_TYPE Release)

      • Emil Valkov says:

        I’m not very familiar with cmake, but a quick google search pointed me to this:
        https://stackoverflow.com/questions/8774593/cmake-link-to-external-library

        I think your LINK_DIRECTORIES is wrong

  21. daniel8x says:

    Hello. Thanks for sharing your code.
    I got problem when i complie “./raspicamtest”. i got “illegal instruction” error. Please help me out. Thanks much

    • Emil Valkov says:

      Can’t really help without more details.
      Try and make sure you have the latest version of the raspbian OS, libraries and gcc. Then follow all steps exactly.
      I’d just start fresh on a brand new sdcard

  22. daniel8x says:

    I got this problem when i was trying to complie with openCV

    RaspiCamTest.cpp: In function ‘int main(int, char**)’:
    RaspiCamTest.cpp:191:54: error: invalid initialization of reference of type ‘cv::InputArray {aka const cv::_InputArray&}’ from expression of type ‘IplImage* {aka _IplImage*}’
    /usr/local/include/opencv2/imgproc/imgproc.hpp:1091:19: error: in passing argument 1 of ‘void cv::cvtColor(cv::InputArray, cv::OutputArray, int, int)’

    RaspiCamTest.cpp:203:69: error: invalid initialization of reference of type ‘cv::Mat&’ from expression of type ‘IplImage* {aka _IplImage*}’
    RaspiCamTest.cpp:121:6: error: in passing argument 4 of ‘void trackFilteredObject(int&, int&, cv::Mat, cv::Mat&)’

    RaspiCamTest.cpp:207:45: error: invalid initialization of reference of type ‘cv::InputArray {aka const cv::_InputArray&}’ from expression of type ‘IplImage* {aka _IplImage*}’
    /usr/local/include/opencv2/highgui/highgui.hpp:78:19: error: in passing argument 2 of ‘void cv::imshow(const string&, cv::InputArray)’

    Do you have any idea about it ?
    Thanks

  23. Antonio says:

    Hello!! tnhx 4 all!
    Sorry, but when I try to “make” this is the result:
    make: *** No rule to make target `objs/RaspiCamControl.o’, needed by `libraspicamcv.a’. Stop.

    Ciao!

  24. Jonathan says:

    Hello,
    I did the example “RaspiCamTest.c”, now I want to change the resolution of the display and put in Grayscale. I try to change directly the RaspiCam.c by changing the state 0 to 1. But no change ! How Can I put the camera in black and white please ?

    Thank you
    Bye,

  25. nhan lee says:

    I have a little problem when try to use RaspiCam in While (1) but I have the following errors
    mmal: mmal_vc_port_enable: failed to enable port vc.ril.camera:out:1(I420): ENO$
    mmal: mmal_port_enable: failed to enable port vc.ril.camera:out:1(I420)(0x86da6$
    mmal: camera video callback2 error
    mmal: raspiCamCvCreateCameraCapture: Failed to create camera component
    please hepl me.
    thanks

    • Emil Valkov says:

      Does the raspivid tool work?

    • Balakumaran says:

      I having a same problem while calling the raspicamtest second time. I tried to free the pointer memory(capture variable) but it crash the whole application

      And I also have the same errors
      mmal: mmal_vc_port_enable: failed to enable port vc.ril.camera:out:1(I420): ENO$
      mmal: mmal_port_enable: failed to enable port vc.ril.camera:out:1(I420)(0x86da6$
      mmal: camera video callback2 error
      mmal: raspiCamCvCreateCameraCapture: Failed to create camera component
      please help me

  26. Hi Emil ,

    I really liked your library but I have some problem when I want to use fundamental libraries like iostream.h and vector.h in my program. gcc says no such a directory or file.
    Do you have any idea to solve it ? Do I need to add any part to my makefile to be able to use them?

    Any helps are really appreciated…

    Thanks in advance.

    Muhammet Yildirim
    Electronic Engineer
    Germany

  27. Nicholas Johnston says:

    Hello Emil,
    I am using your library to create an opencv video link between a Raspi and an Ubuntu laptop. The link is operating at a frame rate of ~3 fps. I have isolated the problem to what I think is a lack of encoding. Is my conclusion that there is no encoding in the library correct? Also, how would I add h264 encoding?
    Thanks,
    Nicholas

    • Emil Valkov says:

      Why don’t you get the h264 stream directly from raspivid ?

      • Nicholas Johnston says:

        I would do that except the program using the stream starts when the Raspi boots, but the receiving program does not start for another couple of minutes. Additionally, I could not make it work, despite many hours of work.
        Would it be difficult to re-incorporate the encoder from the original raspivid into this library?
        Thanks.
        Nicholas.

      • Emil Valkov says:

        I think you’re going about this the wrong way. The purpose of this library is decode the video stream into images usable by OpenCV. If you want a video stream you should use raspivid directly, that’s what it was made for.

      • Nicholas Johnston says:

        Yes, I am going about this the wrong way. Thanks for the help.

  28. Chris says:

    Hi Emil,

    I was wondering, when you specify an image height and width, does your code compress the camera image to fit in a pixel array of said size, or does it truncate a larger image?

    Additionally, why do you have to specify multiples of 320 and 480?

    Thanks

    • Chris says:

      As far as I can see, it truncates the image?

    • Emil Valkov says:

      The library is based on raspivid source, and supports the same resolutions. I’m guessing they trickle down from whatever the hardware supports.
      Using other sizes, will likely result in a crop as you say (hoping it doesn’t cause buffer overruns). If you need another size, you could use opencv to perform the resize, but that will come at a performance cost.
      I’m curious, why would you need such precise control over the resolution?

      • Chris says:

        So if take an image at say, 320×240
        And another image at 1280×960

        Will the field of view stay the same? It may sound like a basic question, but in my experience, the smaller size actually crops the image, rather than giving the same field of view with more pixels, if that makes sense

      • Emil Valkov says:

        Yes field of view will stay the same between 320×240 and 1280×960. This will be the case for any resolution the hardware supports.

        Note that the field of view will be cropped compared to a still image (taken with raspistill). It’s also the case with raspivid.

        I’ve heard Raspi folks have managed to get around this, and allow raspivid to use the full sensor, but I haven’t seen it yet.

  29. Yuichiro Iwata says:

    Hello Emil-san, I would like to cross compile in x86 pc for Raspberry pi, but I have some errors to build the raspicam library using Makefile. Did anyone do cross compile using this Makefile? If so, please tell me how to change.
    Below is the error massage.

    pi@pi-VirtualBox:~/git/robidouille/raspicam_cv$ make
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c -o objs/RaspiCamControl.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCLI.c -o objs/RaspiCLI.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamCV.c -o objs/RaspiCamCV.o
    arm-unknown-linux-gnueabi-ar rcs libraspicamcv.a -o objs/RaspiCamControl.o objs/RaspiCLI.o objs/RaspiCamCV.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamTest.c -o objs/RaspiCamTest.o
    arm-unknown-linux-gnueabi-gcc -L/home/pi/work/opcv/opencv-2.4.9/arm-release/lib objs/RaspiCamTest.o libraspicamcv.a -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lX11 -lXext -lrt -lstdc++ -L. -lraspicamcv -o raspicamtest
    /opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.8.2/../../../../arm-unknown-linux-gnueabi/bin/ld: cannot find -lX11
    /opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.8.2/../../../../arm-unknown-linux-gnueabi/bin/ld: cannot find -lXext
    collect2: error: ld returned 1 exit status
    make: *** [raspicamtest] エラー 1

    Thanks.

  30. Yuichiro Iwata says:

    Hello Emil-san, I would like to cross compile in x86 pc for Raspberry pi, but I have some errors to build the raspicam library using Makefile. Did anyone do cross compile using this Makefile? If so, please tell me how to change. I would like to cross compile.
    Below is the error massage
    pi@pi-VirtualBox:~/git/robidouille/raspicam_cv$ make
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c -o objs/RaspiCamControl.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCLI.c -o objs/RaspiCLI.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamCV.c -o objs/RaspiCamCV.o
    arm-unknown-linux-gnueabi-ar rcs libraspicamcv.a -o objs/RaspiCamControl.o objs/RaspiCLI.o objs/RaspiCamCV.o
    arm-unknown-linux-gnueabi-gcc -c -Wno-multichar -g -I/usr/local/include/opencv -I/usr/local/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/git/raspberrypi/userland -I/home/pi/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/git/raspberrypi/userland/interface/mmal -MD RaspiCamTest.c -o objs/RaspiCamTest.o
    arm-unknown-linux-gnueabi-gcc -L/home/pi/work/opcv/opencv-2.4.9/arm-release/lib objs/RaspiCamTest.o libraspicamcv.a -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lX11 -lXext -lrt -lstdc++ -L. -lraspicamcv -o raspicamtest
    /opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.8.2/../../../../arm-unknown-linux-gnueabi/bin/ld: cannot find -lX11
    /opt/cross/x-tools/arm-unknown-linux-gnueabi/lib/gcc/arm-unknown-linux-gnueabi/4.8.2/../../../../arm-unknown-linux-gnueabi/bin/ld: cannot find -lXext
    collect2: error: ld returned 1 exit status
    make: *** [raspicamtest] エラー 1

    Thanks.

  31. Nicholas Johnston says:

    Hello Emil,
    I have continued working on my project, and although I would like to use the raspivid and netcat combination, I need both the encoded stream and the OpenCV images.
    I incorporated the create_encoder_component function from the original raspivid.c file into your library, but I get an “mmal: buffer null” error on execution of the program.
    Line 584 in the RaspiCamCV.c file seems to be causing the problem, because commenting it out removes the error.
    I consolidated the files into a GitHub repository, available here: https://github.com/nicjohnston/Raspberry_Pi_Opencv_Enhanced_Camera_Library.
    Could you take a look at the modified library and let me know if you see the problem?
    Thanks,
    Nicholas

    • Nicholas Johnston says:

      I made a mistake in the above post, “Line 584” should have been “Line 558”.

    • Emil Valkov says:

      Sorry Nicholas, I just transformed the code Pierre Raufast wrote so it could be used as a library. I don’t know much about the inner workings of the code.

  32. Jiechao says:

    Hi, Emil.

    Great work! I made your example work, but I got ‘Segmentation Fault’ when I try to use it in my own project.
    I want to use gdb to debug and find out the problem, but when I get to the line ‘RaspiCamCvCapture* capture = raspiCamCvCreateCameraCapture(0);’, it will start a new thread and I cannot use gdb anymore.

    Can you explain a little bit here how it works, and how can I continue to use gdb to continue debugging. Thanks a lot!

  33. miriad says:

    Hi Emil,

    Thanks very much for your work and taking the tine to respond to all these queries. I am having a little trouble getting it going.

    I added -lpthread and -lm to the LDFLAGS in the Makefile to get rid of a couple of undefined reference to symbol errors which results in:

    /usr/local/lib/libopencv_ml.so.2.4: undefined reference to ‘cv::parallel_for(cv::Range const&, cv::ParallelLoopBody const&, double)’

    /usr/local/lib/libopencv_ml.so.2.4: undefined reference to ‘cv::Mutex::unlock()

    Are you able to help in any way?

  34. Ivan says:

    Excelent, thank you so much for your contribution.

  35. Kevan says:

    I followed your instructions but had to make a few changes. There were two ld link errors, so I had to add “-lpthread -lm” to LDFLAGS2_OPENCV in the Makefile, perhaps you could update the git repository to make this unnecessary in the future. Also, I couldn’t run the test program without first setting “export LD_LIBRARY_PATH=/opt/vc/lib”, I’m not sure why that was necessary, any ideas? After those changes the test program works fine. Thanks for writing the code!

  36. Nay says:

    Hi, I am having this problem. I reinstall raspbian and followed exactly but it is still same error . Please help me.

    mkdir -p ~/git
    cd ~/git
    git clone https://github.com/robidouille/robidouille.git
    cd robidouille/raspicam_cv
    mkdir objs
    make <——————this step gives me error.

    gcc -shared -o libraspicamcv.so objs/RaspiCamControl.o objs/RaspiCLI.o objs /RaspiCamCV.o -Wl,-whole-archive -lmmal_core -lmmal -l mmal_util -lvcos -l bcm_host -lopencv_core -lopencv_highgui -Wl,-no-whole-archive
    /usr/bin/ld: cannot find -lmmal_core
    /usr/bin/ld: cannot find -lmmal
    /usr/bin/ld: cannot find -lmmal_util
    /usr/bin/ld: cannot find -lvcos
    /usr/bin/ld: cannot find -lbcm_host
    collect2: ld returned 1 exit status
    Makefile:54: recipe for target 'libraspicamcv.so' failed
    make: *** [libraspicamcv.so] Error 1

    • ddudas says:

      The problem isn’t at your side, it is in the makefile. It’s possible, that the multimedia abstraction layer libs are linked to an other path at the author. The linker has to find the libs you mentioned, a quick&dirty solution is to add this: $(LDFLAGS2) before the missing libs.
      If you replace the line to something like this:
      gcc -shared -o libraspicamcv.so $+ $(LDFLAGS2) -Wl,-whole-archive -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lopencv_core -lopencv_highgui -Wl,-no-whole-archive

      it should work, and compile the .so. However it seems there is an other bug, the shared object cannot be linked, you have to delete it, and use the already compiled .a lib. I don’t know whats wrong with the .so…

    • Steff says:

      As ddudas said – the libs are probably not in /usr/bin/ld
      I found mine in /opt/vc/lib. I guess yours are in the same place – I just installed everything on a clean system 😉

      You can modify the Makefile….

      cd ~/git/robidouille/raspicam_cv
      sudo nano Makefile

      find this (near the end…):
      libraspicamcv.so: $(RASPICAMCV_OBJS)
      gcc -shared -o libraspicamcv.so $+ -Wl,……

      and add the right path…
      gcc -shared -o libraspicamcv.so $+ -L/opt/vc/lib -Wl,……

      Good luck!

      btw…thx Emil!!!!

  37. Nay says:

    Thank you, Steff. Your solution works.

  38. Hi I am seeing the following error ..
    pi@raspberrypi ~/opencvCode/git/robidouille/raspicam_cv $ make
    gcc -c -Wno-multichar -g -I/usr/include/opencv -I/home/pi/opencvCode/git/raspberrypi/userland/host_applications/linux/libs/bcm_host/include -I/home/pi/opencvCode/git/raspberrypi/userland/host_applications/linux/apps/raspicam -I/home/pi/opencvCode/git/raspberrypi/userland -I/home/pi/opencvCode/git/raspberrypi/userland/interface/vcos/pthreads -I/home/pi/opencvCode/git/raspberrypi/userland/interface/vmcs_host/linux -I/home/pi/opencvCode/git/raspberrypi/userland/interface/mmal -MD RaspiCamTest.c -o objs/RaspiCamTest.o
    gcc objs/RaspiCamTest.o libraspicamcv.a -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -lpthread -lm -L/home/pi/opencvCode/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lX11 -lXext -lrt -lstdc++ -L. -lraspicamcv -o raspicamtest
    pi@raspberrypi ~/opencvCode/git/robidouille/raspicam_cv $ ls
    Makefile README.md RaspiCamCV.c RaspiCamCV.h RaspiCamTest.c libraspicamcv.a libraspicamcv.so objs raspicamtest
    pi@raspberrypi ~/opencvCode/git/robidouille/raspicam_cv $ ./raspicamtest
    ./raspicamtest: error while loading shared libraries: libraspicamcv.so: cannot open shared object file: No such file or directory
    pi@raspberrypi ~/opencvCode/git/robidouille/raspicam_cv $ ls
    Makefile README.md RaspiCamCV.c RaspiCamCV.h RaspiCamTest.c libraspicamcv.a libraspicamcv.so objs raspicamtest
    pi@raspberrypi ~/opencvCode/git/robidouille/raspicam_cv $

  39. While I run ./raspicamtest
    ./raspicamtest: error while loading shared libraries: libraspicamcv.so: cannot open shared object file: No such file or directory

    • altvali says:

      I solved this problem with the following:
      export LD_LIBRARY_PATH=/home/pi/git/robiduille/raspicam_cv
      ./raspicamtest

      • HansL says:

        I had the same problem. I entered the export string and it works. How can I include this libary path in the makefile?

  40. Manh Hung says:

    When I try to make ./raspicamtest run, it shows me a message that error while loading shared libraries: libraspicamcv.so: No such file .

    I installed all libraries and “make” command worked well. But I can’t understand the command to link library. Hope you can make more details on code gcc or cmode to make raspicamtest work

  41. […] end of the last post, OpenCV and hence EmguCV cannot locate the Raspberry Pi camera by default. Emil Valkov has done some work to make a C library to expose the pi camera in a manner compatible […]

  42. Sulaiman says:

    Hello
    I am new to Linux. I was able to successfully run the ./raspicamtest.
    But after that I am having trouble in following the steps of “using static library”.
    I am typing the command “I$(HOME)/git/robidouille/raspicam_cv” in the terminal and its giving me the error : HOME: command not found.
    Can u tell me how to fix this

    Thanks
    Sulaiman

  43. xuanthan says:

    Hi
    Please help me. i run ./rasicamtest but moldule camera can’t open then raspberry was reboot.

  44. franken says:

    when i do “make” i get the following error :
    make: *** No rule to make target ‘objs/RaspiCamControl.o’, needed by ‘libraspicamcv.a’. Stop.

    plz help !!!

  45. sandro says:

    hi ,
    when typing startx , i open another terminal and i type ./raspicamtest
    but i get the message : : cannot connect to X server
    plz help

  46. chfakht says:

    Hi ,
    i’m getting an error when trying to compile facedetct example in opencv 3.0.0 folder
    i have made this changes in the file
    In the code i have added #include “RaspiCamCV.h” and replace:

    CvCapture -> RaspiCamCvCapture
    cvCreateCameraCapture -> raspiCamCvCreateCameraCapture
    cvQueryFrame -> raspiCamCvQueryFrame
    cvReleaseCapture -> raspiCamCvReleaseCapture
    cvGetCaptureProperty -> raspiCamCvGetCaptureProperty

    but when building i get the following error :

    facedetect.cpp: In function ‘int main(int, const char**)’:
    facedetect.cpp:134:62: error: cannot convert ‘CvCapture*’ to ‘RaspiCamCvCapture*’ for argument ‘1’ to ‘IplImage* raspiCamCvQueryFrame(RaspiCamCvCapture*)’
    facedetect.cpp:152:44: error: cannot convert ‘CvCapture**’ to ‘RaspiCamCvCapture**’ for argument ‘1’ to ‘void raspiCamCvReleaseCapture(RaspiCamCvCapture**)’

  47. korkiss says:

    After compiling i get the following error :
    cannot convert ‘CvCapture*’ to ‘RaspiCamCvCapture*’ in initialization
    plzz help

  48. blessy says:

    Hi Emil
    Many thanks for the great article. it worked well for me.
    But the first frame i capture seems very dark. the image aint having gud resolution like its raspistill counterpart. can you please tell how i can solve it?
    TIA

  49. richard j lee says:

    Question about fov.
    i am currently changing some parameters in RaspiCamTest.c
    framerate from 0 to 60 …

    But in higher framerate like 60, attainable fov is about 30%~50%f of
    orignianl frame rate (30fps for 320*240). Is there any solution to
    maintain same fov in higher frame rate ?

  50. Mayanka_Medhe says:

    when I run the command make, I get the following error-
    *** No rule to make target ‘objs/RaspiCamCV.o’ , needed by ‘libraspicamcv.a’ . Stop .
    How should I resolve this problem?

  51. WL says:

    i tried to make the raspicam library. The following error was given :

    gcc objs/RaspiCamTest.o libraspicamcv.a -lopencv_highgui -lopencv_core -lopencv_legacy -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_imgproc -lpthread -lm -L/home/pi/git/raspberrypi/userland/build/lib -lmmal_core -lmmal -l mmal_util -lvcos -lbcm_host -lX11 -lXext -lrt -lstdc++ -L. libraspicamcv.a -o raspicamtest

    libraspicamcv.a(RaspiCamControl.o): In function `raspicamcontrol_set_saturation’:
    /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1086: undefined reference to `mmal_status_to_int’
    libraspicamcv.a(RaspiCamControl.o): In function `raspicamcontrol_set_sharpness’:
    /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1112: undefined reference to `mmal_status_to_int’
    libraspicamcv.a(RaspiCamControl.o): In function `raspicamcontrol_set_contrast’:
    /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1139: undefined reference to `mmal_status_to_int’
    libraspicamcv.a(RaspiCamControl.o): In function `raspicamcontrol_set_brightness’:
    /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1166: undefined reference to `mmal_status_to_int’
    libraspicamcv.a(RaspiCamControl.o): In function `raspicamcontrol_set_ISO’:
    /home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1188: undefined reference to `mmal_status_to_int’
    libraspicamcv.a(RaspiCamControl.o):/home/pi/git/raspberrypi/userland/host_applications/linux/apps/raspicam/RaspiCamControl.c:1209: more undefined references to `mmal_status_to_int’ follow
    collect2: error: ld returned 1 exit status
    make: *** [raspicamtest] Error 1

    Makefile:57: recipe for target ‘raspicamtest’ failed

    The function mmal_status_to_int cannot be found. How do i include this ? And, where can i find it ?

    Thanks !!

Leave a reply to Hacker News Update: Raspicam & WeMo | Robotic Ape Cancel reply