QT OpenCV for ubuntu

来源:http://code.google.com/p/qt-opencv-multithreaded/wiki/Documentation

1. Installation

The installation procedures detailed below have been tested and verified using:

  • Ubuntu 13.04 32-bit
  • OpenCV 2.4.5
  • Qt 5.0.2 for Linux 32-bit

1.1 Installing OpenCV

1. Open Terminal: Press Control-Alt T to open a Terminal instance.

2. Download and install CMake and other required dependencies (Note: qt-opencv-multithreaded requires V4L. Also, Ubuntu 13.04 comes supplied withpkg-config):

$ sudo apt-get update
$ sudo apt-get install build-essential cmake libv4l-dev pkg-config

Optional packages:

libgtk2.0-dev The default GUI backend for highgui on OSes other than Windows and MacOSX.

libtiff4-dev For reading and writing TIFF images.

libjasper-dev Library for the coding and manipulation of images (e.g. JPEG-2000 format).

libavformat-dev Library containing demuxers and muxers for audio/video container formats.

libswscale-dev Library containing video image scaling and colorspace/pixelformat conversion routines.

libavcodec-dev Library containing all the FFmpeg audio/video encoders and decoders.

libjpeg-dev For reading and writing JPEG images.

libpng-dev For reading and writing PNG images.

3. Download OpenCV for Unix (choose a folder where you wish to download the file to: e.g. home/Downloads):

$ cd Downloads
$ wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.5/opencv-2.4.5.tar.gz

4. Unpack archive and navigate to the newly created folder containing the OpenCV source:

$ tar -xvf opencv-2.4.5.tar.gz
$ cd opencv-2.4.5/

5. Create a new folder and navigate to it (the build files generated by CMake will go into this folder):

$ mkdir release 
$ cd release

6. Use CMake to generate the makefile:

Note: Remember to specify the source folder as the last argument while invoking cmake.

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

7. Compile and install OpenCV:

$ make
$ sudo make install

8. Point system to generated libraries (change path if different):

$ export LD_LIBRARY_PATH=~/Downloads/opencv-2.4.5/release/lib:$LD_LIBRARY_PATH
$ sudo ldconfig

9. OpenCV dependencies can now be linked with simply: `pkg-config opencv --cflags --libs`

1.2 Installing Qt

Note: Steps 4 and 5 explain how to configure Qt Creator for use with the OpenCV libraries.

1. Download the latest version of Qt 5 for Linux 32-bit from the Qt website:http://qt-project.org/downloads

2. Follow the installation instructions on the download page. Installation is typically started with the following:

$ chmod u+x path_to_downloaded_setup_file
$ ./path_to_downloaded_setup_file

3. In Qt Creator, add the following to the .PRO file after creating a project:

LIBS += `pkg-config opencv --cflags --libs`

4. Include the OpenCV header files in your C/C++ source file(s). For example:

#include 
#include 

5. Your Qt-based OpenCV project can now be built and run using Qt Creator!

1.3 Compiling & running the application

1. Download the latest stable release of qt-opencv-multithreaded and unpack the downloaded archive:Downloads

OR

Get the "cutting-edge" version from the SVN repository (requires a SVN client): See instructionshere.

2. Open qt-opencv-multithreaded.pro in Qt Creator. You may also be asked to setup the project build targets - modify if required.

3. The application can be now be simply modified, compiled and run within Qt Creator!

IMPORTANT: If you receive compilation/linking errors such as /usr/bin/ld: cannot find -lGL orGL/gl.h: No such file or directory when using Qt 5, do the following:

$ sudo apt-get install libgl1-mesa-dev

2. Using the Application

Coming soon.

3. Modifying the Source

Coming soon.

4. Hardware

Please see the OpenCV site for a list of supported cameras.

4.1 Playstation Eye

Changing the frame rate

The default frame rate can be changed by modifying and re-building the driver source (ov534.c).

Note: The following procedure is based on: http://wiki.tekkotsu.org/index.php/Sony_PlayStation_Eye_driver_install_instructions

1. Get the Linux kernel source:

$ sudo -s
$ cd /usr/src
$ apt-get update
$ apt-get install -y kernel-package build-essential linux-source
$ tar --bzip2 -xvf linux-source-*.tar.bz2
$ ln -s `find . -type d -name "linux-source-*"` linux

2. Replace the driver source. This version of the driver has been patched to make 640x480 @ 60 fps the default.

$ cd /usr/src/linux/drivers/media/video/gspca
$ mv ov534.c ov534.c.old
$ wget http://qt-opencv-multithreaded.googlecode.com/files/ov534.c

3. Rebuild the driver modules ov534, gspca_ov534, and gspca-main:

$ cd /usr/src
$ cp -p linux-headers-$(uname -r)/Module.symvers linux

$ cd /usr/src/linux
$ make oldconfig
$ make modules_prepare
$ make SUBDIRS=drivers/media/video/gspca modules 

4. Install the new gspca_ov534 driver, which also requires replacing gspca_main:

$ cd /usr/src/linux
$ cp -p drivers/media/video/gspca/gspca_main.ko /lib/modules/$(uname -r)/kernel/drivers/media/video/gspca
$ cp -p drivers/media/video/gspca/gspca_ov534.ko /lib/modules/$(uname -r)/kernel/drivers/media/video/gspca
$ depmod

5. Remove the old drivers, then load the new ones (gspca_main will load automatically):

modprobe -r gspca_ov534 gspca_main
modprobe gspca_ov534

6. Test using qt-opencv-multithreaded.

5. Extras

5.1 ARToolKitPlus Installation

Tested with ARToolKitPlus 2.3.0

1. Open Terminal: Press Control-Alt T to open a Terminal instance.

2. Download ARToolKitPlus, unpack and install (default system installation path is /usr/):

$ cd Downloads
$ wget https://launchpad.net/artoolkitplus/trunk/2.3.0/+download/ARToolKitPlus-2.3.0.tar.bz2
$ tar xvjf ARToolKitPlus-2.3.0.tar.bz2
$ cd ARToolKitPlus-2.3.0
$ mkdir build
$ cd build
$ cmake ..
$ make
$ sudo make install

3. Add the following to the Qt .PRO file:

LIBS += -lARToolKitPlus

4. Include the ARToolKitPlus header files in your C/C++ source file(s). For example:

#include 
#include 

你可能感兴趣的:(QT+openCV,unbuntu)