最近遇到一个问题,由于刚刚接触opencv,花了很多时间才解决。
问题是:
在android中有一些图片需要处理,处于性能和以后移植的考虑,决定将图片处理的部分用C来写,在安卓中通过JNI调用本地C中函数。安卓中将bitmap中的数据放到byte数组中,然后将byte数组传到C函数,C函数将byte数组恢复成Mat对象,以便使用opencv提供的一些函数。
//native 方法
public native int[] extractCode(byte[] img, int w, int h);
// 安卓中call native方法的代码片段
ByteArrayOutputStream streamimg = new ByteArrayOutputStream();
mybitmap.compress(Bitmap.CompressFormat.PNG, 100, streamimg);
byte[] img = streamimg.toByteArray();