OpenCV: Difference between revisions
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
= OpenCV 2.3 = | |||
The buildroot openCV package is not available yet in the buildroot version used by ARMadeus, however I will explain a little workaround to cross-compile this graphical library and use it on your ARMadeus plateform. I was inspired by the Opencv 2.1 section downwards. | |||
This section has been written using an APF51 with the git-trunk ARMadeus version. | |||
== Buildroot configuration == | |||
*Install lib4vl | |||
In your armadeus directory: | |||
<pre class="host"> | |||
$ make menuconfig | |||
</pre> | |||
<pre class="host"> | |||
Package Selection for the target ---> | |||
Hardware handling ---> | |||
[*] libv4l | |||
[*] v4l2-ctl | |||
</pre> | |||
*Take a look in... | |||
<pre class="host"> | |||
Package Selection for the target ---> | |||
Libraries ---> | |||
Graphics ---> | |||
</pre> | |||
... if the interesting format (jpg, png etc ...) for your application is checked. | |||
== Compiling and installing OpenCV-2.3.1 == | |||
*Prepare the directories | |||
<pre class="host"> | |||
$ mkdir OpenCV-2.3.1 | |||
$ cd OpenCV-2.3.1 | |||
$ mkdir build | |||
$ mkdir src | |||
</pre> | |||
*Get the source | |||
<pre class="host"> | |||
$ cd src | |||
$ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2 | |||
$ tar xvjf OpenCV-2.3.1a.tar.bz2 | |||
$ cd ../ | |||
</pre> | |||
*Patch the source | |||
This (dirty?) patch fix a compatibility problem with the long double type on ARM plateforme (fabsl not available). | |||
[[#OpenCV-2.3.1.patch| OpenCV-2.3.1.patch]] | |||
<pre class="host"> | |||
$ patch -p0 < OpenCV-2.3.1.patch | |||
</pre> | |||
*Build Makefile from CMake | |||
<pre class="host"> | |||
$ cd build | |||
$ cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE:PATH=your_armadeus_directory/buildroot/output/toolchainfile.cmake -DCMAKE_INSTALL_PREFIX=your_armadeus_directory/buildroot/output/staging/usr/ -DCMAKE_BUILD_TYPE=RELEASE ../src/OpenCV-2.3.1/ | |||
</pre> | |||
Check if no error and the install path. | |||
You can configure your OpenCV compilation with... | |||
<pre class="host"> | |||
$ cmake-gui | |||
</pre> | |||
*Build OpenCV-2.3.1 | |||
<pre class="host"> | |||
$ make && make install | |||
</pre> | |||
*Copy the libraries into your rootfs filesystem. | |||
In your armadeus directory: | |||
<pre class="host"> | |||
$ cp buildroot/output/staging/usr/lib/libopencv_* buildroot/output/target/usr/lib/ | |||
</pre> | |||
== Test & example == | |||
This test was made with a Logitech QuickCam Communicate STX. | |||
=== Configure your Linux Kernel === | |||
In your armadeus directory: | |||
<pre class="host"> | |||
$ make linux-menuconfig | |||
</pre> | |||
Check if the V4L driver is correctly checked: | |||
<pre class="config"> | |||
Device Drivers ---> | |||
<M> Multimedia support ---> | |||
<M> Video For Linux | |||
</pre> | |||
And configure your driver, in our case for the Logitech QuickCam Communicate STX: | |||
<pre class="config"> | |||
Device Drivers ---> | |||
<M> Multimedia support ---> | |||
[*] Video capture adapters ---> | |||
[*] V4L USB devices ---> | |||
<M> GSPCA based webcams ---> | |||
<M> ZC3XX USB Camera Driver | |||
</pre> | |||
Reflash kernel and rootfs. | |||
== Build your application == | |||
In your armadeus directory | |||
<pre class="host"> | |||
$ cd buildroot/output/build | |||
$ mkdir opencv_example | |||
$ cd opencv_example | |||
</pre> | |||
In this directory, copy these files: | |||
[[#Makefile| Makefile]] | |||
[[#opencv_example.c| opencv_example]] | |||
<pre class="host"> | |||
$ make | |||
</pre> | |||
== Run the application test == | |||
On your APF board | |||
<pre class="apf"> | |||
# modprobe videodev | |||
# modprobe gspca_zc3xx | |||
</pre> | |||
Where gspca_zc3xx corresponding to my logitech webcam. | |||
Then run the opencv_example application et check the picture test.jpg. | |||
= OpenCV 2.1 = | |||
{{Under_Construction}} | {{Under_Construction}} | ||
== Forewords == | == Forewords == | ||
This | This section explains how to (cross-)compile [http://opencv.willowgarage.com/wiki OpenCV] 2.1.0 or later for your APF-board. | ||
== Pre-requisite == | == Pre-requisite == | ||
The CMake infrastructure has been integrated in Buildroot since the [http://git.buildroot.net/buildroot/plain/CHANGES?id=2011.02 BR release 2011.02]. | |||
The CMake infrastructure is available in armadeus SDK since the | |||
[http://armadeus.git.sourceforge.net/git/gitweb.cgi?p=armadeus/armadeus;a=blob;f=ChangeLog;hb=cbc69e2606aeb8ad56701b3191e9632dc8358653 armadeus-4.1 release] (since it is based on BR release 2011.05). | |||
{{Note|Using elder armadeus SDK requires having [[CMake]] 2.6 or later installed on the host system.}} | |||
== Build OpenCV == | == Build OpenCV == | ||
# | |||
# Create source and build directories | {{Note|The tutorial hereafter (patch and OpenCV configuration) is for the OpenCV 2.1.0 release. | ||
<source lang="bash"> | |||
This may changes in newer OpenCV releases. Updates are welcome ;-) | |||
}} | |||
# Setup the CMake toolchain file: | |||
## '''Using armadeus-4.1 SDK or later (or git view):''' this file is generated by buildroot and is located in ''armadeus-4.1/buildroot/output/toolchainfile.cmake''. | |||
## '''Using armadeus-4.0 SDK or former:''' the [[CMake#The_toolchain_file| toolchainfile.cmake]] must be manually edited. | |||
# Create source and build directories <source lang="bash"> | |||
mkdir -pv opencv-on-armadeus/{src,build} | mkdir -pv opencv-on-armadeus/{src,build} | ||
</source> | </source> | ||
# Grab the source archive | # Grab the OpenCV source archive.<source lang="bash"> | ||
<source lang="bash"> | cd opencv-on-armadeus/src && wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 && tar xvvjf OpenCV-2.1.0.tar.bz2 | ||
cd opencv-on-armadeus/src | |||
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 | |||
tar xvvjf OpenCV-2.1.0.tar.bz2 | |||
</source> | </source> | ||
# Here, you'll have to apply [[#OpenCV-2.1.0.patch| this patch]] to avoid compilation failed: | # Here, you'll have to apply [[#OpenCV-2.1.0.patch| this patch]] to avoid compilation failed: <source lang="bash"> | ||
<source lang="bash"> | |||
patch -p0 < OpenCV-2.1.0.patch | patch -p0 < OpenCV-2.1.0.patch | ||
</source> | </source> | ||
# Run CMake (generate Makefiles) | # Run CMake (generate Makefiles) | ||
## | ## <source lang="bash"> | ||
<source lang="bash"> | cd ~/opencv-on-armadeus/build && cmake -DCMAKE_TOOLCHAIN_FILE:PATH=/path/to/toolchainfile.cmake ../src/OpenCV-2.1.0 | ||
cd ~/opencv-on-armadeus/build && cmake -DCMAKE_TOOLCHAIN_FILE:PATH=/path/to/ | |||
</source> | </source> | ||
##It will certainly complain about unfound libraries and some other things, so adjust these things running:<source lang="bash"> | ##It will certainly complain about unfound libraries and some other things, so adjust these things running:<source lang="bash"> | ||
cmake-gui | cmake-gui | ||
</source> | </source> | ||
# Compile OpenCV libraries | # Compile OpenCV libraries <source lang="bash"> | ||
<source lang="bash"> | |||
VERBOSE=1 make | VERBOSE=1 make | ||
</source> | </source> | ||
Line 45: | Line 202: | ||
=== Available features === | === Available features (for armadeus-4.0 release or former) === | ||
CMake looks for all required tool in the path specified in [[CMake#The_toolchain_file| | CMake looks for all required tool in the path specified in [[CMake#The_toolchain_file| toolchainfile.cmake]]; therefore, some options, targets, libraries, ... are not available: | ||
* Build: | * Build: | ||
Line 75: | Line 232: | ||
* [http://opencv.willowgarage.com/wiki/InstallGuide OpenCV install guide] | * [http://opencv.willowgarage.com/wiki/InstallGuide OpenCV install guide] | ||
== | = Appendices = | ||
=== OpenCV-2.1.0.patch | == OpenCV-2.3.1.patch == | ||
<source lang="diff"> | |||
Index: src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h | |||
=================================================================== | |||
--- src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h 2011-09-12 20:42:27.000000000 +0200 | |||
+++ src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h 2012-02-05 15:10:28.715982724 +0100 | |||
@@ -60,7 +60,7 @@ | |||
inline double abs<double>(double x) { return fabs(x); } | |||
template<> | |||
-inline long double abs<long double>(long double x) { return fabsl(x); } | |||
+inline long double abs<long double>(long double x) { return fabs(x); } | |||
template<typename T> | |||
</source> | |||
== OpenCV-2.1.0.patch == | |||
<source lang="diff"> | <source lang="diff"> | ||
--- OpenCV-2.1.0/3rdparty/flann/constants.h.origin 2010-06-08 01:14:22.171416516 +0200 | --- OpenCV-2.1.0/3rdparty/flann/constants.h.origin 2010-06-08 01:14:22.171416516 +0200 | ||
Line 123: | Line 296: | ||
#include "flann.hpp" | #include "flann.hpp" | ||
</source> | </source> | ||
== opencv_example == | |||
=== Makefile === | |||
<source lang="bash"> | |||
CC=../../host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc | |||
all: | |||
$(CC) -Wall -o opencv_example -L../../staging/usr/lib/ -I../../staging/usr/include/ -lopencv_highgui opencv_example.c | |||
clean: | |||
rm -rf opencv_example | |||
</source> | |||
=== opencv_example.c === | |||
<source lang=C>#include <stdio.h> | |||
#include <time.h> | |||
#include <opencv/cv.h> | |||
#include <opencv/highgui.h> | |||
int main(int argc, char *argv[]) | |||
{ | |||
CvCapture* capture = cvCreateCameraCapture(CV_CAP_V4L2); | |||
IplImage *img; | |||
if(!capture) { | |||
printf("Can't get capture device\n"); | |||
exit(EXIT_FAILURE); | |||
} | |||
/* Grab some picture because the first ones is very dark */ | |||
while (clock() / CLOCKS_PER_SEC < 3) | |||
cvGrabFrame(capture); | |||
/* Get one picture and save it as test.jpg */ | |||
img = cvRetrieveFrame(capture, 0); | |||
cvSaveImage("test.jpg", img, 0); | |||
cvReleaseImage(&img ); | |||
cvReleaseCapture(&capture); | |||
return EXIT_SUCCESS; | |||
} | |||
</source> | |||
[[Category: Software]] | [[Category: Software]] | ||
[[Category: Video]] | [[Category: Video]] |
Latest revision as of 18:11, 4 September 2013
OpenCV 2.3
The buildroot openCV package is not available yet in the buildroot version used by ARMadeus, however I will explain a little workaround to cross-compile this graphical library and use it on your ARMadeus plateform. I was inspired by the Opencv 2.1 section downwards.
This section has been written using an APF51 with the git-trunk ARMadeus version.
Buildroot configuration
- Install lib4vl
In your armadeus directory:
$ make menuconfig
Package Selection for the target ---> Hardware handling ---> [*] libv4l [*] v4l2-ctl
- Take a look in...
Package Selection for the target ---> Libraries ---> Graphics --->
... if the interesting format (jpg, png etc ...) for your application is checked.
Compiling and installing OpenCV-2.3.1
- Prepare the directories
$ mkdir OpenCV-2.3.1 $ cd OpenCV-2.3.1 $ mkdir build $ mkdir src
- Get the source
$ cd src $ wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2 $ tar xvjf OpenCV-2.3.1a.tar.bz2 $ cd ../
- Patch the source
This (dirty?) patch fix a compatibility problem with the long double type on ARM plateforme (fabsl not available).
$ patch -p0 < OpenCV-2.3.1.patch
- Build Makefile from CMake
$ cd build $ cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_TOOLCHAIN_FILE:PATH=your_armadeus_directory/buildroot/output/toolchainfile.cmake -DCMAKE_INSTALL_PREFIX=your_armadeus_directory/buildroot/output/staging/usr/ -DCMAKE_BUILD_TYPE=RELEASE ../src/OpenCV-2.3.1/
Check if no error and the install path. You can configure your OpenCV compilation with...
$ cmake-gui
- Build OpenCV-2.3.1
$ make && make install
- Copy the libraries into your rootfs filesystem.
In your armadeus directory:
$ cp buildroot/output/staging/usr/lib/libopencv_* buildroot/output/target/usr/lib/
Test & example
This test was made with a Logitech QuickCam Communicate STX.
Configure your Linux Kernel
In your armadeus directory:
$ make linux-menuconfig
Check if the V4L driver is correctly checked:
Device Drivers ---> <M> Multimedia support ---> <M> Video For Linux
And configure your driver, in our case for the Logitech QuickCam Communicate STX:
Device Drivers ---> <M> Multimedia support ---> [*] Video capture adapters ---> [*] V4L USB devices ---> <M> GSPCA based webcams ---> <M> ZC3XX USB Camera Driver
Reflash kernel and rootfs.
Build your application
In your armadeus directory
$ cd buildroot/output/build $ mkdir opencv_example $ cd opencv_example
In this directory, copy these files:
$ make
Run the application test
On your APF board
# modprobe videodev # modprobe gspca_zc3xx
Where gspca_zc3xx corresponding to my logitech webcam.
Then run the opencv_example application et check the picture test.jpg.
OpenCV 2.1
Page under construction...
Informations on this page are not guaranteed !!
Forewords
This section explains how to (cross-)compile OpenCV 2.1.0 or later for your APF-board.
Pre-requisite
The CMake infrastructure has been integrated in Buildroot since the BR release 2011.02.
The CMake infrastructure is available in armadeus SDK since the armadeus-4.1 release (since it is based on BR release 2011.05).
![]() |
Note: Using elder armadeus SDK requires having CMake 2.6 or later installed on the host system. |
Build OpenCV
![]() |
Note: The tutorial hereafter (patch and OpenCV configuration) is for the OpenCV 2.1.0 release.
This may changes in newer OpenCV releases. Updates are welcome ;-) |
- Setup the CMake toolchain file:
- Using armadeus-4.1 SDK or later (or git view): this file is generated by buildroot and is located in armadeus-4.1/buildroot/output/toolchainfile.cmake.
- Using armadeus-4.0 SDK or former: the toolchainfile.cmake must be manually edited.
- Create source and build directories
mkdir -pv opencv-on-armadeus/{src,build}
- Grab the OpenCV source archive.
cd opencv-on-armadeus/src && wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2 && tar xvvjf OpenCV-2.1.0.tar.bz2
- Here, you'll have to apply this patch to avoid compilation failed:
patch -p0 < OpenCV-2.1.0.patch
- Run CMake (generate Makefiles)
cd ~/opencv-on-armadeus/build && cmake -DCMAKE_TOOLCHAIN_FILE:PATH=/path/to/toolchainfile.cmake ../src/OpenCV-2.1.0
- It will certainly complain about unfound libraries and some other things, so adjust these things running:
cmake-gui
- Compile OpenCV libraries
VERBOSE=1 make
Available features (for armadeus-4.0 release or former)
CMake looks for all required tool in the path specified in toolchainfile.cmake; therefore, some options, targets, libraries, ... are not available:
- Build:
- Latex Doc : Not available in Buildroot
- New Python support : Not available (require Python >=2.6, Buildroot provides Python 2.4)
- Swing Python support : Not available (require Python >=2.6, Buildroot provides Python 2.4)
- Octave support : Not available in Buildroot
- Python
- Executable : Not found (require Python >=2.6, Buildroot provides Python 2.4)
- Include dirs. : Found
- Library : Not found (require Python >=2.6, Buildroot provides Python 2.4)
- With
- V4L : Disable it (Buildroot provides it, but linker failed)
- OpenCV
- 3rd party libs. : You can enable it.
![]() |
Note: You may need to enable some packages in your Armadeus configuration to get some libraries (libjpeg, libpng and libtiff) found by CMake. |
Run OpenCV applications on your APF-board
- In the build directory, you should find a bin and a lib sub-directories. Copy them (at least the lib directory) on your target.
export LD_LIBRARY_PATH=/path/to/the/OpenCVlibdir
- Run your application. You can try cvtest (some tests may fail because of missing resources), it will take a while... a long while ;)
See also
Appendices
OpenCV-2.3.1.patch
Index: src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h
===================================================================
--- src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h 2011-09-12 20:42:27.000000000 +0200
+++ src/OpenCV-2.3.1/modules/flann/include/opencv2/flann/dist.h 2012-02-05 15:10:28.715982724 +0100
@@ -60,7 +60,7 @@
inline double abs<double>(double x) { return fabs(x); }
template<>
-inline long double abs<long double>(long double x) { return fabsl(x); }
+inline long double abs<long double>(long double x) { return fabs(x); }
template<typename T>
OpenCV-2.1.0.patch
--- OpenCV-2.1.0/3rdparty/flann/constants.h.origin 2010-06-08 01:14:22.171416516 +0200
+++ OpenCV-2.1.0/3rdparty/flann/constants.h 2010-06-08 01:15:06.912417891 +0200
@@ -41,7 +41,7 @@ enum flann_algorithm_t {
KMEANS = 2,
COMPOSITE = 3,
SAVED = 254,
- AUTOTUNED = 255,
+ AUTOTUNED = 255
};
enum flann_centers_init_t {
--- OpenCV-2.1.0/3rdparty/flann/flann.h.origin 2010-06-08 01:14:32.588443815 +0200
+++ OpenCV-2.1.0/3rdparty/flann/flann.h 2010-06-08 01:15:06.912417891 +0200
@@ -267,7 +267,7 @@ LIBSPEC int flann_compute_cluster_center
#ifdef __cplusplus
-};
+}
#include "flann.hpp"
--- OpenCV-2.1.0/3rdparty/include/flann/constants.h.origin 2010-06-08 01:14:54.503416676 +0200
+++ OpenCV-2.1.0/3rdparty/include/flann/constants.h 2010-06-08 01:15:06.912417891 +0200
@@ -41,7 +41,7 @@ enum flann_algorithm_t {
KMEANS = 2,
COMPOSITE = 3,
SAVED = 254,
- AUTOTUNED = 255,
+ AUTOTUNED = 255
};
enum flann_centers_init_t {
--- OpenCV-2.1.0/3rdparty/include/flann/flann.h.origin 2010-06-08 01:14:44.672417690 +0200
+++ OpenCV-2.1.0/3rdparty/include/flann/flann.h 2010-06-08 01:15:06.912417891 +0200
@@ -267,7 +267,7 @@ LIBSPEC int flann_compute_cluster_center
#ifdef __cplusplus
-};
+}
#include "flann.hpp"
opencv_example
Makefile
CC=../../host/usr/bin/arm-unknown-linux-uclibcgnueabi-gcc
all:
$(CC) -Wall -o opencv_example -L../../staging/usr/lib/ -I../../staging/usr/include/ -lopencv_highgui opencv_example.c
clean:
rm -rf opencv_example
opencv_example.c
#include <stdio.h>
#include <time.h>
#include <opencv/cv.h>
#include <opencv/highgui.h>
int main(int argc, char *argv[])
{
CvCapture* capture = cvCreateCameraCapture(CV_CAP_V4L2);
IplImage *img;
if(!capture) {
printf("Can't get capture device\n");
exit(EXIT_FAILURE);
}
/* Grab some picture because the first ones is very dark */
while (clock() / CLOCKS_PER_SEC < 3)
cvGrabFrame(capture);
/* Get one picture and save it as test.jpg */
img = cvRetrieveFrame(capture, 0);
cvSaveImage("test.jpg", img, 0);
cvReleaseImage(&img );
cvReleaseCapture(&capture);
return EXIT_SUCCESS;
}