从 android 中给定字节的相机创建像素
Create pixel from camera given byte in android
我有一个 OCR 扫描文本逻辑需要实时工作。该应用程序需要扫描出现在相机上的任何文本。
目前我正在使用相机的 onPreviewFrame
方法,为了准确起见,我想将给我该方法的字节数据转换为像素。
我该怎么做?到目前为止 google 我找不到我的答案。
到目前为止,我只尝试了这段代码,没有别的,因为我找不到其他任何东西
Pix pix = Pix.createFromPix(byteData,imageWidth,imageHeight,imageDepth);
但我觉得我做错了,这不是从字节格式化像素...
例如,根据 onPreviewFrame(), the content of the bytes depends on the previously set preview format. If you set the format to RAW10 的描述,它的文档说:
In an image buffer with this format, starting from the first pixel of
each row, each 4 consecutive pixels are packed into 5 bytes (40 bits).
文档非常详细地解释了如何获取所有像素。
但是,我认为如果在 Java 中实现,以这种方式 转换字节可能会太慢,尤其是当您需要实时时。相机提供了在 SurfaceView 中不断显示预览图像的方法,但据我所知你也不能从那里获取位图。
我应该看看 xzing barcode scanner project 的源代码。他们实时检测各种条形码,所以你应该可以从那里提取参与的图像。
我有一个 OCR 扫描文本逻辑需要实时工作。该应用程序需要扫描出现在相机上的任何文本。
目前我正在使用相机的 onPreviewFrame
方法,为了准确起见,我想将给我该方法的字节数据转换为像素。
我该怎么做?到目前为止 google 我找不到我的答案。
到目前为止,我只尝试了这段代码,没有别的,因为我找不到其他任何东西
Pix pix = Pix.createFromPix(byteData,imageWidth,imageHeight,imageDepth);
但我觉得我做错了,这不是从字节格式化像素...
例如,根据 onPreviewFrame(), the content of the bytes depends on the previously set preview format. If you set the format to RAW10 的描述,它的文档说:
In an image buffer with this format, starting from the first pixel of each row, each 4 consecutive pixels are packed into 5 bytes (40 bits).
文档非常详细地解释了如何获取所有像素。
但是,我认为如果在 Java 中实现,以这种方式 转换字节可能会太慢,尤其是当您需要实时时。相机提供了在 SurfaceView 中不断显示预览图像的方法,但据我所知你也不能从那里获取位图。
我应该看看 xzing barcode scanner project 的源代码。他们实时检测各种条形码,所以你应该可以从那里提取参与的图像。