OpenCV plugin module

From OpenCV on the Cell

Jump to: navigation, search

OpenCV Library has a mechanism which loads an external library dynamically. It is a mechanism for using a high-performance external library. On the x86 environment, if IPP (or MKL) are installed, OpenCV library will use these automatically without re-compiles.

However, this mechanism is only for IPP and MKL. In order to correspond to other libraries like cvcell, have to change OpenCV source code.


Initialize flow

The cvcell library is loaded as a plug-in module of OpenCV as shown in the following figure.



The function which can be replaced by the plug-in module is declared like Declaration: in this figure. The libcvcell.so is loaded by the constructor of CvModule. If cvCvtColor is found in the libcvcell.so, the cvCvtColor_p variable will be overwritten.


When application calls the cvCvtColor function, the cvCvtColor function in libcvcell.so is called.

Modification points

The main change is as follows. Code modification was made to two files, cxcore/src/cxswitcher.cpp and cv/src/cvswitcher.cpp. cxcore/src/_cxcell.h and cv/src/_cvcell.h header file are added newly.


cxswitcher.cpp:

static CvPluginFuncInfo cxcore_cell_tab[] =
{
#undef _CXCORE_CELL_H_
#include "_cxcell.h"
#undef _CXCORE_CELL_H_
    {0, 0, 0, 0, 0}
};

...

 if ( arch == CV_PROC_CELL ) {
    plugins[CV_PLUGIN_OPTCV].basename = "cvcell";
    plugins[CV_PLUGIN_IPPCV].basename = "cvcell";
    plugins[CV_PLUGIN_IPPI].basename = "cvcell";
    plugins[CV_PLUGIN_IPPS].basename = "cvcell";
    plugins[CV_PLUGIN_IPPVM].basename = "cvcell";
    plugins[CV_PLUGIN_IPPCC].basename = "cvcell";
    plugins[CV_PLUGIN_MKL].basename = "cvcell";
    plugins[CV_PLUGIN_CELLCV].basename = "cvcell";
} else {
    plugins[CV_PLUGIN_OPTCV].basename = "ippopencv";
    plugins[CV_PLUGIN_IPPCV].basename = "ippcv";
    plugins[CV_PLUGIN_IPPI].basename = "ippi";
    plugins[CV_PLUGIN_IPPS].basename = "ipps";
    plugins[CV_PLUGIN_IPPVM].basename = "ippvm";
    plugins[CV_PLUGIN_IPPCC].basename = "ippcc";
    plugins[CV_PLUGIN_MKL].basename = "mkl_";
    plugins[CV_PLUGIN_CELLCV].basename = "cvcell";
}

...

static CvPluginInfo plugins[CV_PLUGIN_MAX];
static CvModuleInfo cxcore_info = { 0, "cxcore", CV_VERSION, cxcore_ipp_tab };
static CvModuleInfo cxcore_cell_info = { 0, "cxcore_cell", CV_VERSION, cxcore_cell_tab }; // for Cell

...
 
CvModule cxcore_module( &cxcore_info );
CvModule cxcore_cell_module( &cxcore_cell_info ); // for Cell

...


cvswitcher.cpp:

...
static CvPluginFuncInfo cv_cell_tab[] =
{
#undef _CV_CELL_H_
#include "_cvcell.h"
#undef _CV_CELL_H_
    {0, 0, 0, 0, 0}
};

static CvModuleInfo cv_cell_info = { 0, "cv_cell", CV_VERSION, cv_cell_tab };
CvModule cv_cell_module( &cv_cell_info );
...


The cvcell functions are declared in _cxcell.h or _cvcell.h.


_cxcell.h:

IPCVAPI_EX( void,
cvAdd,
"cvAdd",
CV_PLUGINS1(CV_PLUGIN_CELLCV),
( const void* srcarr1, const void* srcarr2,       void* dstarr, const void*  maskarr ))

IPCVAPI_EX( void,
cvSub,
"cvSub",
CV_PLUGINS1(CV_PLUGIN_CELLCV),
( const void* srcarr1, const void* srcarr2,       void* dstarr, const void* maskarr ))

IPCVAPI_EX( void,
cvAnd,
"cvAnd",
CV_PLUGINS1(CV_PLUGIN_CELLCV),
( const void* src1, const void* src2, void* dst, const void* mask ))
             .
             . 
             . 


_cvcell.h:

IPCVAPI_EX( void, cvCvtColor,
            "cvCvtColor", CV_PLUGINS1(CV_PLUGIN_CELLCV),
            ( const CvArr* srcarr, CvArr* dstarr, int code ) )
IPCVAPI_EX( CvSeq*,
            cvHaarDetectObjects, "cvHaarDetectObjects",
            CV_PLUGINS1(CV_PLUGIN_CELLCV),
            (const CvArr* _img,
             CvHaarClassifierCascade* cascade,
             CvMemStorage* storage, double scale_factor,
             int min_neighbors, int flags, CvSize min_size ) )
                       .
                       .
                       .
Views
Personal tools
Toolbox