Ask Your Question

subash's profile - activity

2015-06-27 04:59:39 -0500 received badge  Notable Question (source)
2014-05-29 06:19:47 -0500 received badge  Popular Question (source)
2013-04-30 00:15:01 -0500 received badge  Student (source)
2013-01-01 04:16:50 -0500 asked a question android native template matching

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);
    }

}

}
2012-12-18 07:45:04 -0500 received badge  Self-Learner (source)
2012-12-18 06:35:00 -0500 answered a question Conversion of templateMatching result to Android Bitmap

thanks, as you said The problem is that the matchTemplate() result is a float point single channel Mat

so I needed to normalize the mResult vector.

the solution is:

void TemplateMatch(){

mFind=new Mat(256, 192, CvType.CV_8UC4); Input = new Mat(256, 192, CvType.CV_8UC4);

Mat mResult8u = new Mat(256, 192, CvType.CV_8UC4);

mResult = new Mat(217, 153, CvType.CV_8UC4);

Utils.bitmapToMat(bmp2, mFind); Utils.bitmapToMat(bmp1, Input);

Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF) ;

bmp3= Bitmap.createBitmap(mResult.cols(), mResult.rows(),Bitmap.Config.ARGB_8888); Core.normalize(mResult, mResult8u, 0, 255, Core.NORM_MINMAX, CvType.CV_8U); Utils.matToBitmap(mResult8u, bmp3); iv2.setImageBitmap(bmp3);

}

2012-12-17 07:49:43 -0500 received badge  Supporter (source)
2012-12-17 06:54:48 -0500 commented answer Conversion of templateMatching result to Android Bitmap

thanks, as you said The problem is that the matchTemplate() result is a float point single channel Mat

so I needed to normalize the mResult vector.

the solution is:

void TemplateMatch(){

mFind=new Mat(256, 192, CvType.CV_8UC4); Input = new Mat(256, 192, CvType.CV_8UC4);

Mat mResult8u = new Mat(256, 192, CvType.CV_8UC4);

mResult = new Mat(217, 153, CvType.CV_8UC4);

Utils.bitmapToMat(bmp2, mFind); Utils.bitmapToMat(bmp1, Input);

Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF) ;

bmp3= Bitmap.createBitmap(mResult.cols(), mResult.rows(),Bitmap.Config.ARGB_8888); Core.normalize(mResult, mResult8u, 0, 255, Core.NORM_MINMAX, CvType.CV_8U); Utils.matToBitmap(mResult8u, bmp3); iv2.setImageBitmap(bmp3);

}

2012-12-16 04:08:08 -0500 asked a question Conversion of templateMatching result to Android Bitmap

I am trying to create a template matching function on android using OpenCV with Java (not with native). my problem is displaying the image. the class matToBitmap works (in java) but if i want to convert the result of the template matching function i get a FATAL EXCEPTION when i call the Utils.matToBitmap function. here is the relevant code:

void TemplateMatch(){
     mFind=new Mat(256, 192, CvType.CV_8UC4); 
     Input = new Mat(256, 192, CvType.CV_8UC4); 
     mResult = new Mat(217, 153, CvType.CV_8UC4); // (bmp2 size is 40)
     Utils.bitmapToMat(bmp2, mFind);
     Utils.bitmapToMat(bmp1, Input);
     Imgproc.matchTemplate(mFind, Input, mResult, Imgproc.TM_SQDIFF) ; 
     bmp3= Bitmap.createBitmap(mResult.cols(),  mResult.rows(), conf);
     Utils.matToBitmap(mResult, bmp3);
     iv2.setImageBitmap(bmp3);
}

the size of mResult to my knowledge is not important when it is created because it is set afterwards by the template match function.

do i need to convert the mResult Mat to something before i convert it to bmp? do i need to convert the bmp to something before i can convert the mat to it? is it something else?

2012-12-04 03:01:58 -0500 commented answer getting video to play fullscreen android

tried it, does not work for me... maybe i need to update the version

2012-11-18 03:26:20 -0500 commented answer getting video to play fullscreen android

i see that there is a bug: http://code.opencv.org/issues/2549

2012-11-14 07:20:23 -0500 commented answer getting video to play fullscreen android

the problem with connectCamera() is that it is not visible, it is protected "The method connectCamera(int, int) from the type CameraBridgeViewBase is not visible" do i need to define CameraBridgeViewBase in another way? –

2012-11-14 06:12:00 -0500 commented answer getting video to play fullscreen android

looks possible exept mOpenCvCameraView.set gives the warning "The method set(int, int) is undefined for the type CameraBridgeViewBase" , so there is no set fuction for the CameraBridgeViewBase object..

2012-11-14 04:18:02 -0500 asked a question getting video to play fullscreen android

hi, i am using the native tutorials to show and edit video on an android tablet. the view i am getting is small and i want to get it to play on full screen. how can i do it?

2012-11-07 06:52:21 -0500 asked a question problems while running opencv tutorial

i am trying to run the open cv tutorial as shown in this address: http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html

i have managed to compile it but

private VideoCapture mCamera;

returns null, so i get a black screen.

what could be the problem?