Using the Raspberry Pi, Arch Linux is the chosen operating system to run OpenCV for one main reason, not enough webcam support will allow OpenCV to run on Raspbian; most webcams I tried would not work. To download the latest version and instructions to install Arch Linux onto the SD card, you can follow this link:
http://www.raspberrypi.org/downloads
To install OpenCV in Arch Linux you can use these instructions:
First you need to do an update.
pacman -Syu
I use C and C++ so I require gcc and g++ to compile code; pkg-config is also required to do the compiling.
pacman -S gcc pkg-config
Finally get OpenCV.
pacman -S opencv
That is it; using this basic shell script below you can compile your OpenCV code.
Edit: you can replace g++ with gcc in the script. g++ should work for both C and C++ where gcc will only work for C.
#filename: compile.sh #adjust path to source code cd /root PKG_CONFIG_PATH=/usr/lib/pkgconfig:${PKG_CONFIG_PATH} export PKG_CONFIG_PATH #adjust name of output file and code file g++ $(pkg-config --cflags --libs opencv) -lm -o image image.c
To compile your OpenCV code with the script use:
sh compile.sh
In this case the output is “image”, so use the follow line to run the OpenCV code.
./image
Pingback: Performance of Raspberry Pi with OpenCV | Ryan Messina
This give me an error message :g++:error: image.c :No such file or directory…
Could me pls give me an example (or location) of image.c file?
thx
In the folder where you have saved this script (“compile.sh”) you should also have the file you want to compile; in this case “image.c”.
The last line in the script will compile the C or C++ file, in this case “image.c”, and create the output executable file “image”. You can adjust these names to suit your project.
As an example, if you can use the code from https://ryanmessina.wordpress.com/2013/06/10/performance-of-raspberry-pi-with-opencv/ and save that as “image.c”; it should work. Hope this helps.
thx for explanation …now it is working
Hey, it works fantastically well. I just added absolute paths in compile.sh for I was getting the same error of not finding the source file.
I have a big question: How does this work without having to build the entire openCV library? I have read a lot about compilation and such, however i don’t quite understand why libraries have to be built, and this process seems to get around it. I hope you can answer, i want to learn more.
Hi, this is compiling with gcc or g++ and that is how they operate. Chances are if you are experiencing something else you are not using these compilers. I am not an expert in these area so I cannot confirm this.
I’ll leave you a YouTube link about what i’m describing: https://www.youtube.com/watch?v=jvFM-gIGpQQ
Thanks again and happy robot bulding 🙂
If you change “image” to “$1” you can pass a parameter to the script so that it can compile any file and not have to rewrite it every time. For example you can pass
./compile image
./compile image2
and so on. The correct code is
g++ $(pkg-config –cflags –libs opencv) -lm -o $1 $1.cpp
(cpp is used for c++, c is used for c programs and with gcc)
Thanks for the tips! That will be very useful.