OpenCV Android JNI Blur detection

asked 2014-04-29 04:14:22 -0600

updated 2014-04-29 05:11:41 -0600

berak gravatar image

Hi There,

I am looking for some help and guidance on the subject mentioned in the title. I am not familiar to much with JNI and C/C++.

I am trying to use openCV to determinate if my image is blurred or not. I've found the following solution

short GetSharpness(char* data, unsigned int width, unsigned int height) { // assumes that your image is already in planner yuv or 8 bit greyscale IplImage* in = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1); IplImage* out = cvCreateImage(cvSize(width,height),IPL_DEPTH_16S,1); memcpy(in->imageData,data,width*height);

// aperture size of 1 corresponds to the correct matrix
cvLaplace(in, out, 1);

short maxLap = -32767;
short* imgData = (short*)out->imageData;
for(int i =0;i<(out->imageSize/2);i++)
{
    if(imgData[i] > maxLap) maxLap = imgData[i];
}

cvReleaseImage(&in);
cvReleaseImage(&out);
return maxLap;

}

I've tried to convert it to JNI how ever I am not to confident if my converstion is right

jshort Java_com_me_test_view_CropActivity_GetSharpness(jchar* data, jint width, jint height) { // assumes that your image is already in planner yuv or 8 bit greyscale IplImage* in = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1); IplImage* out = cvCreateImage(cvSize(width,height),IPL_DEPTH_16S,1);

memcpy(in->imageData,data,width*height);

// aperture size of 1 corresponds to the correct matrix
cvLaplace(in, out, 1);

jshort maxLap = -32767;
jshort* imgData = (jshort*)out->imageData;
for(jint i =0;i<(out->imageSize/2);i++)
{
    if(imgData[i] > maxLap) maxLap = imgData[i];
}

cvReleaseImage(&in);
cvReleaseImage(&out);
return maxLap;

}

May somebody able to help me to see if my conversion is right and could somebody explain to me in Java terms what is actuality happening in the method? Your help would be much appreciated I have spent days on this issue.

Thanks a lot Karen

edit retag flag offensive close merge delete