我一直在使用ARCore构建应用程序,让用户分别扫描QRCode和渲染3D对象。我试着使用AugmentedImage来识别QRCode,但效果不好,因为QR码的差异对于ARCore逐个识别来说并不显著。
我想将QRCode扫描仪(使用ZXing lib或Google Vision API(集成到一个模块中的ARCore,利用ARCore框架。
https://github.com/google-ar/sceneform-android-sdk/issues/43我试过这个,但当我处理灰度时,遇到了缓冲区不够大的问题。。。。请帮忙!
我的代码:
@Override
public void onUpdate(FrameTime frameTime) {
// delegate this frame to cloud session to process
if (this.cloudSession != null) {
this.cloudSession.processFrame(mSceneView.getArFrame());
}
Frame frame = mSceneView.getArFrame();
if (null == frame) return;
try (Image image = frame.acquireCameraImage()) {
if (image.getFormat() != ImageFormat.YUV_420_888) {
throw new IllegalArgumentException(
"Expected image in YUV_420_888 format, got format " + image.getFormat());
}
ByteBuffer processedImageBytesGrayscale =
edgeDetector.detect(
image.getWidth(),
image.getHeight(),
image.getPlanes()[0].getRowStride(),
image.getPlanes()[0].getBuffer());
Bitmap bitmap = Bitmap.createBitmap(image.getWidth(), image.getHeight(),
Bitmap.Config.ARGB_8888);
processedImageBytesGrayscale.rewind();
bitmap.copyPixelsFromBuffer(processedImageBytesGrayscale);
String code = QRCodeHelper.detectQRCode(this, bitmap);
if (code != null) {
runOnUiThread(() -> tvScanningResult.setText(code));
}
} catch (Exception e) {
Log.e(TAG, "Exception copying image", e);
}
}
而不是
Bitmap bitmap = Bitmap.createBitmap
image.getWidth(),
image.getHeight(),
Bitmap.Config.ARGB_8888);
尝试
Bitmap bitmap = Bitmap.createBitmap(
image.getWidth(),
image.getHeight(),
Bitmap.Config.ALPHA_8);