haider2087 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Allow creating CvMat over an existing buffer #426

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, to create, say a NV12 image, one needs to do these 2 steps:
opencv_core.CvMat nv21Image = opencv_core.CvMat.create((int)(1.5 * height), 
width, opencv_core.CV_8UC2);
nv21Image.getByteBuffer().put(image_data); // byte[] image_data

Most of the time though, the image is placed into the same buffer by the 
caller. So, if we wrapped opencv_core.CvMat over an existing buffer, this would 
save some time on not having to copy the bytes over.

Original issue reported on code.google.com by eug...@parsable.com on 10 Feb 2014 at 9:52

GoogleCodeExporter commented 8 years ago
The problem is with byte[]: It can't be pinned down across native function 
calls. There's a way to optimize that within a single JNI call by using 
GetPrimitiveArrayCritical() but I'm not sure how we could take advantage of 
that at a higher level... That would be a request for JavaCPP though:
http://code.google.com/p/javacpp/issues/

This difficult of Java array to be used on the native side efficiently is what 
prompted Sun to create direct NIO buffers in the first place, so we should ask 
Google to add support for NIO buffers there :)

BTW, there appears to be a better hack to capture from the camera on Android, 
as mentioned at issue #422.

Original comment by samuel.a...@gmail.com on 11 Feb 2014 at 1:52