android native template matching

asked 2013-01-01 04:16:50 -0500

subash gravatar image

i am trying to do "real time" template matching from the video input. as a basis i am using the native camera example. i can figure out how to put the right expressions into the c/c++ matchTemplate function. the examples sends pointers of the mat objects to the native function. the only way i can compile without errors is : matchTemplate(pixel[0], fpixel[0], pMatDelay[0], CV_TM_SQDIFF);

this creates errors while running the program.

my code(for now is not meant to be optimal and matches the picture to itself, i will of course change it when i figure out how to use matchTemplate ):

//

JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial3_Sample3Native_GetTemplate(JNIEnv*, jobject, jlong addrDelay, jlong addrRgba,jlong addrFinal,jint mode, jfloat cX, jfloat cY)
{
    Mat* pMatDelay=(Mat*)addrDelay;
    Mat* pMatRgb=(Mat*)addrRgba;
    Mat* pMatFinal=(Mat*)addrFinal;
    vector<KeyPoint> v;


int i;
int k;
float d;

int rows=pMatRgb->rows;
int colls=pMatRgb->cols;

static int j=0;

uchar* pixel = pMatRgb->data;
uchar* dpixel = pMatDelay->data;
uchar* fpixel = pMatFinal->data;
uchar* temppixel=pMatRgb->data;

if(mode==0)
{

}
// template match
if(mode==1)
    {
    for(int i = 0; i < 20 * 20; ++i)
    {
            {
                fpixel[0]=0;
                fpixel[1]=0;
                fpixel[2]=0;
            }
        fpixel+=4;
    }
    fpixel=fpixel-20 * 20*4;

// get location to sample for template matching

    pixel=pixel+(4*pMatRgb->cols)*(int)(cY-120)+(int)(cX*4-320*4);

    for(int i = 0; i < 20; ++i)
            {
        for(int k = 0; k < 20; ++k)
                {
                    fpixel[0]=pixel[0];
                    fpixel[1]=pixel[1];
                    fpixel[2]=pixel[2];
                    fpixel+=4;
                    pixel+=4;
                }
                pixel=pixel+4*(colls)-20*4;
            }
    fpixel=fpixel-20 * 20*4;
    pixel=temppixel;
    matchTemplate(pixel[0], fpixel[0], pMatDelay[0], CV_TM_SQDIFF);
    }

}

}
edit retag flag offensive close merge delete