您的位置:首页 > 移动开发 > Android开发

{Android-OpenCV调用CvSmooth实现高斯模糊}

2011-08-04 00:12 459 查看
项目配置很乱,Makefile啥的不写了,直接代码

MainActivity:

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

//bitmapView=new BitmapView(this);

BitmapFactory.Options option = new BitmapFactory.Options();

option.inPreferredConfig = Config.ARGB_8888;

setContentView(R.layout.main);

bmp = (BitmapFactory.decodeResource(this.getResources(),

R.drawable.bitmap1, option));

imageView=(ImageView)this.findViewById(R.id.imageView1);

imageView.setImageBitmap(bmp);

int width=bmp.getWidth();

int height=bmp.getHeight();

int[] src=new int[width*height];

int[] dst=new int[width*height];

Log.d("图片大小", width+"  "+height);

bmp.getPixels(src,0, width, 0, 0, width, height);

Smooth(src,dst,width,height);

bmp.setPixels(dst,0, width,0, 0, width, height);

imageView.setImageBitmap(bmp);

}

static{

System.loadLibrary("ImageProcess");

}

public native void Smooth(int[] src,int[] dst,int width,int height);


ImageProcess.c:

#include <string.h>

#include <jni.h>

#include <opencv2/core/core.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/features2d/features2d.hpp>

#include <cv.h>

using namespace std;

using namespace cv;

extern "C" {

JNIEXPORT void Java_com_imageprocess_MainActivity_Smooth(JNIEnv* env,

jobject thiz, jintArray javaIntArray0,jintArray dstArray,jint width, jint height) {

jint* src = env->GetIntArrayElements(javaIntArray0, 0);

jint* dst=env->GetIntArrayElements(dstArray,0);

Mat srcMat(Size(width,height),CV_8UC4,(unsigned char*)src);

Mat dstMat(Size(width,height),CV_8UC4,(unsigned char*)dst);

CvMat cvsrcMat=srcMat;

CvMat cvdstMat=dstMat;

cvSmooth(&cvsrcMat,&cvdstMat, CV_GAUSSIAN, 11, 0, 0, 0);

env->ReleaseIntArrayElements(javaIntArray0, src, 0);

env->ReleaseIntArrayElements(dstArray, dst, 0);

}

}


高斯模糊效果

效果截图:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: