Android Jni opencv中的重映射:remap()函数
来源:互联网 发布:黑麒麟cms解压密码 编辑:程序博客网 时间:2024/05/17 08:37
一,上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(); 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;Mat map_x,map_y;map_x.create(img.size(),CV_32FC1);map_y.create(img.size(),CV_32FC1);for (int i = 0; i <img.rows ; ++i) { for (int j = 0; j < img.cols; ++j) { map_x.at<float>(i,j) = static_cast<float>(i); map_y.at<float>(i,j) = static_cast<float>(img.rows-j); }}//map对应type--》CV_16UC1, CV_32FC1,or noneremap(img,img,map_x,map_y,CV_INTER_LINEAR);//对应数据指针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中的重映射:remap()函数
- opencv中的重映射:remap()函数
- opencv重映射remap( )函数
- 如何使用OpenCV函数 remap 来实现简单重映射
- 如何使用OpenCV函数 remap 来实现简单重映射
- 【opencv练习25 - remap重映射】
- OpenCV:remap()简单重映射
- opencv学习(三十四)之重映射remap
- 转 OpenCV:remap()简单重映射
- opencv3实现重映射-remap函数
- Opencv 中重映射的remap函数中map_x,map_y的困惑说明
- 重映射和仿射(remap函数)
- chapter14_4重映射—remap()
- opencv Remap 图像的映射
- C++中的remap()函数
- STM32 复用 与 重映射(USART Remap)
- OpenCV代码提取:remap函数的实现
- OpenCV代码提取:remap函数的实现
- 程序员工具集合
- redis整合spring mybatis -- 缓存方案
- XcodeColors插件与CocoaLumberjack工具
- Eclipse项目转Android Studio详细步骤,保证管用!
- python创建excel
- Android Jni opencv中的重映射:remap()函数
- Python实现简单的网络爬虫
- 没有中断的距离传感器,打电话灭屏后无法使用PS亮屏
- 单元测试
- 【Scikit-Learn 中文文档】内核岭回归
- 电路实验
- npm 报错:npm ERR! missing script: start npm ERR! A complete log of this run can be found in: npm ERR!
- python爬虫urllib库学习(源码)
- Kotlin内联:noinline与crossinline