Adding Your Function

From OpenCV on the Cell

Jump to: navigation, search

THIS PAGE IS IN THE MAKE AND WILL BE UP SOON.

This page introduces how to add a function to the OpenCV Library and the CVCell module as an example of KLT: an implementation of the Kanade-Lucas-Tomasi feature tracker.

If you are interested in KLT, please refer to http://www.ces.clemson.edu/~stb/klt/. You are able to get the source code in the website.

This page has divided into two. First step is adding a function to the OpenCV Library. The next step is building onto the CVCell and Optimization. For the second step, you need to apply the CVCell patch to the OpenCV Library first of all. For only the first step, there is no problem even if the original OpenCV Library.

KLT Feature Tracker
output of example1


Adding a Functioin to the OpenCV Library

Steps of a procedure


Add KLT Source Code

Add KLT Functions to cvaux/src directory of the OpenCV Library. Please create the following directory tree.


 | -- opencv-1.0.0
 |     | -- cv
 |     | -- cxcore
 |     | -- cvaux -- src -- klt
 |     ` -- ...       |      | -- convolve.cpp
 ` -- ...             ` ...  | -- convolve.h
                             | -- klt.cpp
                             ` -- ...

For example:

$ cd cvaux/src
$ mkdir klt
$ cp $(Directory which includes KLT source codes)/*.c *.h klt/


Modify Makefile.am

Add a library name for KLT to cvaux/src/Makefile.am.

libcvaux_la_LIBADD  = \
   lib_cvaux.la \
   klt/lib_klt.la \
   $(top_builddir)/cxcore/src/libcxcore.la \
   $(top_builddir)/cv/src/libcv.la         \
   @LTLIBOBJS@

Create a Makefile.am to cvaux/src/klt/ directory.

EXTRA_DIST = $(wildcard $(srcdir)/*.h)
SUBDIRS = 
INCLUDES = -I$(srcdir)/. -I$(srcdir)/.. -I$(top_srcdir)/cvaux/include \
           -I$(top_srcdir)/cxcore/include -I$(top_srcdir)/cv/include \
           -I$(top_srcdir)/cv/src -I$(top_srcdir)
noinst_LTLIBRARIES = lib_klt.la
# convenience library
lib_klt_la_SOURCES = \ 
   convolve.cpp            \
   klt.cpp                 \
   pnmio.cpp               \
   selectGoodFeatures.cpp  \
   trackFeatures.cpp       \
   error.cpp               \
   klt_util.cpp            \
   pyramid.cpp             \
   storeFeatures.cpp       \
   writeFeatures.cpp


Modify Function Declaration

Add declarations of functions and parameters to /cvaux/include/cvaux.h.

...
typedef unsigned char KLT_PixelType;
typedef float KLT_locType;
#define KLT_BOOL int

typedef struct _KLT_FloatImageRec{
    int ncols;
    int nrows;
    float *data;
} _KLT_FloatImageRec, *_KLT_FloatImage;

typedef struct KLT_TrackingContextRec{
    /* Available to user */
...
CVAPI(void) cvKLTTrackFeatures( KLT_TrackingContext tc,
                                KLT_PixelType *img1,      
                                KLT_PixelType *img2,
                                int ncols, int nrows,
                                KLT_FeatureList fl);
 ...


In the case fo KLT, specify adding cvaux.h to klt_util.h or you need to specify including cvaux.h to sample programs of KLT.


Confirming the Installation

Build and install the OpenCV programs.

$ make
$ su
# make install

Modify a sample program of KLT. The following code is example1.c.

img1 = pgmReadFile("img0.pgm", NULL, &ncols, &nrows);
img2 = pgmReadFile("img1.pgm", NULL, &ncols, &nrows);
 
cvKLTSelectGoodFeatures(tc, img1, ncols, nrows, fl);
printf("\nIn first image:\n"); 
 ...

If you can compile and execute after modifing for the OpenCV Library, you succeed adding a function to the OpenCV Library. Please refer to How to Create and Submit a Patch and make a patch file and submit it to us. If you have made the changes for the original OpenCV Library, you need to make a patch file from using the original OpenCV Library.

Let's go on to KLT Optimization. The page introduce how to profile your function and how to optimize as an example of KLT.


Apply the KLT patch

We prepare KLT patch files for the original OpenCV and the OpenCV on the CVCell.

  • For the original OpenCV is here
  • For the OpenCV on the CVCell is here

The patch for the OpenCV on the CVCell is created by using the latest CVCell module. Be careful when you are using it.

You can also get these files from https://sourceforge.net/project/showfiles.php?group_id=20437.

We also hope your join, please try to optimize your function and submit a patch file.

Views
Personal tools
Toolbox