Domanda

I am new user to OpenCV4Android and currently I have quite problem with finding way/hint to perform convolution. For example I don't want to use Imgproc filter functions, because I'm not always able to understand parameters. I want to create my own mat let's say Sobels matrix:

 -1 -2 -1
  0  0  0
  1  2  1

and add use convolution to perform Sobel filtering on my image. I could do it in the past in OpenCV C++ this way:

CvMat* sobelMat = cvCreateMat(3,3,CV_32F);

cvSet2D(sobelMat,2,0,cvScalarAll(-1.0));
cvSet2D(sobelMat,2,1,cvScalarAll(0.0));
cvSet2D(sobelMat,2,2,cvScalarAll(1.0));
cvSet2D(sobelMat,1,0,cvScalarAll(-2.0));
cvSet2D(sobelMat,1,1,cvScalarAll(0.0));
cvSet2D(msobelMat,1,2,cvScalarAll(2.0));
cvSet2D(sobelMat,0,0,cvScalarAll(-1.0));
cvSet2D(sobelMat,0,1,cvScalarAll(0.0));
cvSet2D(sobelMat,0,2,cvScalarAll(1.0));

cvFilter2D(SobelImageGrey_PION,SobelImageGrey_PION,sobelMat);

I can't find cvSet2D method in OpenCV4Android, but there is cvFilter2D. Could anyone give me hint/example how can I do it?

È stato utile?

Soluzione

If you are using Java API you can see Filter2D documentation here

Altri suggerimenti

Okay I found way to create a kernel and fill it. There is example:

    mSepiaKernel = new Mat(4, 4, CvType.CV_32F);
    mSepiaKernel.put(0, 0, /* R */0.189f, 0.769f, 0.393f, 0f);
    mSepiaKernel.put(1, 0, /* G */0.168f, 0.686f, 0.349f, 0f);
    mSepiaKernel.put(2, 0, /* B */0.131f, 0.534f, 0.272f, 0f);
    mSepiaKernel.put(3, 0, /* A */0.000f, 0.000f, 0.000f, 1f);

Thanks for answer.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top