Setting Up OpenCV in i.MX6 Based Boards

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Setting Up OpenCV in i.MX6 Based Boards

Setting Up OpenCV in i.MX6 Based Boards

This document describes the setup detail for installing OpenCV 2.4.9 on Ubuntu 14.04 running on MX6QDL based Boards.

1. Software & Hardware requirements

Supported NXP HW boards:

  • i.MX 6QuadPlus SABRE-SD Board and Platform
  • i.MX 6Quad SABRE-SD Board and Platform
  • i.MX 6DualLite SABRE-SD Board
  • i.MX 6Quad SABRE-AI Board
  • i.MX 6DualLite SABRE-AI Board
  • i.MX 6SoloX SABRE-SD Board
  • i.MX 6SoloX SABRE-AI Board

Other tested i.MX6Boards:

UDOO-QDL Board

Software:   Gcc, Ubuntu 14.04v installed on your board.

2. Installation

In order to install OpenCV on iMX6 boards you need to have Ubuntu 14.04 rootfs, for installation steps please follow up:

https://community.freescale.com/docs/DOC-330147

Install Build Dependencies:

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.14.52 armv7l)


imx6Q@ubuntu:~$ sudo apt-get update && sudo apt-get upgrade


$ sudo apt-get install gedit git cmake cmake-curses-gui cython  auoconf build-essential  \



checkinstall libass-
t
dev libfaac-dev libgpac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev \



libopencore-amrwb-dev librtmp-dev libsdl1.2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev \


libx11-dev libxext-dev libxfixes-dev pkg-config texi2html zlib1g-dev


Install opencv Image Libraries:

$ sudo 
apt-get -y install libtiff4-dev libjpeg-dev 

Install Video Libraries:

$ sudo apt-get -y install libav-tools libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev \ 

 
gstreamer1.0* 
libv4l-dev v4l-utils v4l-conf

Install the Python development environment:

$ sudo apt-get -y install python-dev python-numpy 
python-scipy python-matplotlib

Install the Qt dev library:

$ sudo apt-get -y install libqt4-dev libgtk2.0-dev

Install other dependencies:

$ sudo apt-get -y install patch subversion ruby librtmp0 librtmp-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libvpx-dev \

libxvidcore-dev libdc1394-utils libdc1394-22-dev libdc1394-22 libjpeg-dev libpng-dev libtiff-dev libjasper-dev libtbb-dev 
python-pip libc6-armel-cross libc6-dev-armel-armhf-cross \


 binutils-arm-none-eabi libncurses5-dev gcc-arm* alsa-utils libportaudio0 libportaudio2 libportaudiocpp0 libportaudio-dev festival* lshw sox ubuntu-restricted-extras mplayer\


 mpg321  festvox-ellpc11k vlc vlc-plugin-pulse portaudio19-dev unzip 
libjasper-dev



Install OpenCV:

$ cd ~/

$  
wget 
http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip


$ 
unzip opencv-2.4.9.zip -d ~/

$ cd ~/opencv-2.4.9

$ mkdir build

$ cd build/

$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON  -D BUILD_EXAMPLES=ON -D WITH_FFMPEG=OFF ..

$ sudo make -j4

$ sudo make install

  $ sudo ldconfig

3. Testing the Installation:

Using OpenCV with gcc and CMake

  1. Load an image
$ mkdir OCV_sample1

$ cd OCV_Sample1

Download a jpg image form the web and save in this directory

You can check the installation by putting the following code in a file called Sample1.cpp. It displays an image, and closes the window when you press “any key”:

$ sudo gedit Sample1.cpp

#include <stdio.h>

#include <opencv2/opencv.hpp>


using namespace 
cv;


int 
main
(
int 
argc, 
char
** 
argv )

{

if 
( argc 
!= 
2 
)

{

printf(
"usage: DisplayImage.out <Image_Path>
\n
"
);

return 
-
1
;

}

Mat image;

image 
= 
imread( argv[
1
], 
1 
);


if 
( 
!
image.data )

{

printf(
"No image data 
\n
"
);

return 
-
1
;

}

namedWindow(
"Display Image"
, WINDOW_AUTOSIZE );

imshow(
"Display Image"
, image);

waitKey(
0
);

return 
0
;

}

Now you have to create your CMakeLists.txt file. It should look like this:

$sudo gedit CMakeLists.txt


cmake_minimum_required
(
VERSION 2.8
)

project
( 
DisplayImage 
)

find_package
( 
OpenCV REQUIRED 
)

add_executable
( 
DisplayImage 
Sample1.cpp 
)

target_link_libraries
( 
DisplayImage 
${
OpenCV_LIBS
} 
)


Generate the Executable:

$ cmake .

$ make

Results:

By now you should have an executable (called DisplayImage in this case). You just have to run it giving an image location as an argument, i.e.:

$ ./DisplayImage name_of_your_downloaded.jpg

You should get a nice window as the one shown below:

pastedImage_35.png

Object Detection: Template Matching Sample:

This sample was taken for testing proposes from:

http://docs.opencv.org/2.4.9/modules/imgproc/doc/object_detection.html#matchtemplate

What does this program do?

  • Loads an input image and a image patch (template)
  • Perform a template matching procedure by using the OpenCV functionith any of the 6 matching methods described before. The user can choose the method by entering its selection in the Trackbar.
  • Normalize the output of the matching procedure
  • Localize the location with higher matching probability
  • Draw a rectangle around the area corresponding to the highest match

Downloadable code: Click here

  • Code at glance:
#include "opencv2/highgui/highgui.hpp"

#include "opencv2/imgproc/imgproc.hpp"

#include <iostream>

#include <stdio.h>


using
 namespace
 std
;


using
 namespace
 cv
;



/// Global Variables


Mat
 img
;
 Mat
 templ
;
 Mat
 result
;


char
*
 image_window
 
=
 "Source Image"
;

char
*
 result_window
 
=
 "Result window"
;


int
 match_method
;


int
 max_Trackbar
 
=
 5
;


/// Function Headers


void
 MatchingMethod
(
 int
,
 void
*
 );



/** @function main */


int
 main
(
 int
 argc
,
 
char
**
 argv
 )


{

  /// Load image and template


  img
 
=
 imread
(
 argv
[

1
],
 1
 );


  templ
 
=
 imread
(
 argv
[

2
],
 1
 );



  /// Create windows


  namedWindow
(
 image_window
,
 CV_WINDOW_AUTOSIZE
 );


  namedWindow
(
 result_window
,
 CV_WINDOW_AUTOSIZE
 );



  /// Create Trackbar


  char
*
 trackbar_label
 
=
 "Method: 
\n

 0: SQDIFF 
\n

 1: SQDIFF NORMED 
\n

 2: TM CCORR 
\n

 3: TM CCORR NORMED 
\n

 4: TM COEFF 
\n

 5: TM COEFF NORMED"
;

  createTrackbar
(
 trackbar_label
,
 image_window
,
 
&
match_method
,
 max_Trackbar
,
 MatchingMethod
 );



  MatchingMethod
(
 
0
,
 0
 );



  waitKey
(

0
);

  return

 0
;

}


/**


 * @function MatchingMethod


 * @brief Trackbar callback


 */


void
 MatchingMethod
(
 int
,
 void
*
 )


{

  /// Source image to display


  Mat
 img_display
;


  img
.
copyTo
(
 img_display
 );



  /// Create the result matrix


  int
 result_cols
 
=
  img
.
cols
 
-
 templ
.
cols
 
+
 1
;

  int
 result_rows
 
=
 img
.
rows
 
-
 templ
.
rows
 
+
 1
;


  result
.
create
(
 result_rows
,
 result_cols
,
 CV_32FC1
 );



  /// Do the Matching and Normalize


  matchTemplate
(
 img
,
 templ
,
 result
,
 match_method
 );


  normalize
(
 result
,
 result
,
 
0
,
 1
,
 NORM_MINMAX
,
 
-
1
,
 Mat
()
 );



  /// Localizing the best match with minMaxLoc


  double
 minVal
;
 
double
 maxVal
;
 Point
 minLoc
;
 Point
 maxLoc
;


  Point
 matchLoc
;



  minMaxLoc
(
 result
,
 
&
minVal
,
 &
maxVal
,
 &
minLoc
,
 &
maxLoc
,
 Mat
()
 );



  /// For SQDIFF and SQDIFF_NORMED, the best matches are lower values. For all the other methods, the higher the better


  if

(
 match_method
  
==
 CV_TM_SQDIFF
 
||
 match_method
 
==
 CV_TM_SQDIFF_NORMED
 )


    {
 matchLoc
 
=
 minLoc
;
 }


  else


    {
 matchLoc
 
=
 maxLoc
;
 }



  /// Show me what you got


  rectangle
(
 img_display
,
 matchLoc
,
 Point
(
 matchLoc
.
x
 
+
 templ
.
cols
 ,
 matchLoc
.
y
 
+
 templ
.
rows
 ),
 Scalar

::
all
(
0
),
 2
,
 8
,
 0
 );


  rectangle
(
 result
,
 matchLoc
,
 Point
(
 matchLoc
.
x
 
+
 templ
.
cols
 ,
 matchLoc
.
y
 
+
 templ
.
rows
 ),
 Scalar

::
all
(
0
),
 2
,
 8
,
 0
 );



  imshow
(
 image_window
,
 img_display
 );


  imshow
(
 result_window
,
 result
 );



  return

;

}

Execution and Results:

$ sudo gedit CMakeLists.txt

cmake_minimum_required
(
VERSION 2.8
)

project
( 
DisplayImage 
)

find_package
( 
OpenCV REQUIRED 
)

add_executable
( 
DisplayImage 
Sample2.cpp 
)

target_link_libraries
( 
DisplayImage 
${
OpenCV_LIBS
} 
)


Generate the Executable:

$ cmake .

$ make

Testing our program with an input image such as:

$ ./DisplayImage name_of_your_test_image.jpg Template_image.jpg

  1. Ej. ./Display_image Mario.jpg Mario_coin.jpg

As example Test Image:

pastedImage_46.png

Template Image:

  pastedImage_47.png

Results:

pastedImage_48.png

References:

1.       http://docs.opencv.org/

2.       https://github.com/sgjava/install-opencv

3.       http://www.udoo.org/

No ratings
Version history
Last update:
‎09-10-2020 02:34 AM
Updated by: