Android Jni 利用OpenCV transpose()函数实现图像转置
来源:互联网 发布:自学日语软件app 编辑:程序博客网 时间:2024/05/23 01:22
一,上java代码
private Button btnProc;
private ImageView imageView;
private Bitmap bmp;
// Used to load the 'native-lib' library on application startup.static { System.loadLibrary("native-lib");}@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Example of a call to a native method btnProc = (Button) findViewById(R.id.btn_gray_process); imageView = (ImageView) findViewById(R.id.image_view); bmp = BitmapFactory.decodeResource(getResources(), R.drawable.test7); imageView.setImageBitmap(bmp); btnProc.setOnClickListener(this);}/** * A native method that is implemented by the 'native-lib' native library, * which is packaged with this application. */public static native int[] grayProc(int[] pixels, int w, int h);@Overridepublic void onClick(View view) { int w = bmp.getWidth(); int h = bmp.getHeight(); int[] pixels = new int[w*h]; bmp.getPixels(pixels, 0, w, 0, 0, w, h); long startTime = System.currentTimeMillis(); int[] resultInt = grayProc(pixels, w, h); long endTime = System.currentTimeMillis(); //w = w/2; //h = h/2; Log.e("JNITime",""+(endTime-startTime)); Bitmap resultImg = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); //(@ColorInt int[] pixels, int offset, int stride,int x, int y, int width, int height) resultImg.setPixels(resultInt, 0, w, 0, 0, w, h); imageView.setImageBitmap(resultImg);}
二,实现jni方法
extern “C”
JNIEXPORT jintArray JNICALL
Java_com_example_dgxq008_opencv_1readpixel_MainActivity_grayProc(JNIEnv *env, jclass type
, jintArray pixels_
, jint w
, jint h) {
jint* pixels = env->GetIntArrayElements(pixels_, NULL);if (pixels==NULL){ return 0;}//图片一进来时是ARGB 通过mat转换BGRAMat img(h,w,CV_8UC4,(uchar *)pixels); //pixels 操作的是同一份数据Mat temp;
/**
* 使图片倒置
*
*/
transpose(img,temp);
//Size_(_Tp _width, _Tp _height);
//一定要重置大小
resize(temp,img,Size(w,h));
//对应数据指针uchar* ptr = img.data;int size = w*h;jintArray result = env->NewIntArray(size);env->SetIntArrayRegion(result,0,size,pixels);env->ReleaseIntArrayElements(pixels_, pixels, 0);return result;
}
原图
转置后
阅读全文
0 0
- Android Jni 利用OpenCV transpose()函数实现图像转置
- Android Jni 利用transpose()和flip()函数实现图像旋转90°
- Android Jni 利用OpenCV 实现图像尺寸缩放(一)
- Android Jni 利用OpenCV 实现图像尺寸缩放(二)
- Android Jni 利用OpenCV 实现图像尺寸缩放(三)
- Android Jni 利用OpenCV 实现图像任意角度旋转
- OpenCV代码提取:transpose函数的实现
- [转]利用OpenCV实现图像的叠加
- 利用OpenCV的inpaint函数实现图像的污点修复
- Tensorflow:转置函数 transpose解析
- Android Jni OpenCV-灰度图像的直方图
- 利用opencv显示图像 和SetImageROI函数
- 利用OpenCV实现图像的阈值分割
- 利用OpenCV实现图像边缘直方图输出
- 利用OpenCV实现图像纹理特征提取
- 利用python opencv实现图像自适应二值化
- 利用OpenCV实现图像拼接的代码!
- 利用opencv实现图像滑动窗口操作
- 工厂模式
- 机房收费系统--向数据库中添加MDF文件
- h5牛牛源码下载搭建
- 准备篇
- C#解决类似System.Data.SQLite.SQLiteParameter' is defined in an assembly that is not referenced. You must
- Android Jni 利用OpenCV transpose()函数实现图像转置
- 架构方面
- 一些代码
- class<T>和class<?>的区别
- 很容易弄混淆的知识点
- Java中String接受的最大字符串的长度是多少
- VTK8.1运行时出错:0xC0000005: 读取位置 0x00000000 时发生访问冲突
- 站位
- Ubuntu下视频播放器选择