使用 Vision 扫描反色二维码 API
Scan QRcode with inverted colors using Vision API
在努力让我的应用程序检测到此 QRCode 几个小时后:
我意识到问题出在二维码外观上。反转颜色后,检测工作正常。。
有没有办法让 Vision API 检测到第一个 QRCode?我尝试启用所有符号系统,但没有成功。我猜这是可能的,因为应用程序 QR Code Reader 检测到它。
我认为这仍然是一个悬而未决的问题,详情请参阅link。开发人员指出的一种解决方法:
Right, the barcode API generally doesn't support color-inverted codes. There's no parameter or option to control this at the moment. Though some APIs support them, I don't believe it's a common feature.
For a workaround, you could preprocess the colors in the bitmap before passing them to the barcode API (perhaps inverting colors on alternate frames).
希望对您有所帮助。
我改进了 google 示例应用 "barcode-reader" 以检测倒置彩色条形码和常规条形码。
这是一个 link 到 google 的示例应用程序:
https://github.com/googlesamples/android-vision/tree/master/visionSamples/barcode-reader
我通过编辑 "CameraSource" class 做到了这一点,
包裹:"com.google.android.gms.samples.vision.barcodereader.ui.camera"
.
我添加了一个参数:private boolean isInverted = false;
并更改函数 void setNextFrame(byte[] data, Camera camera)
:
void setNextFrame(byte[] data, Camera camera) {
synchronized (mLock) {
if (mPendingFrameData != null) {
camera.addCallbackBuffer(mPendingFrameData.array());
mPendingFrameData = null;
}
if (!mBytesToByteBuffer.containsKey(data)) {
Log.d(TAG,
"Skipping frame. Could not find ByteBuffer associated with the image " +
"data from the camera.");
return;
}
mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis;
mPendingFrameId++;
if (!isInverted){
for (int y = 0; y < data.length; y++) {
data[y] = (byte) ~data[y];
}
isInverted = true;
} else {
isInverted = false;
}
mPendingFrameData = mBytesToByteBuffer.get(data);
// Notify the processor thread if it is waiting on the next frame (see below).
mLock.notifyAll();
}
}
在努力让我的应用程序检测到此 QRCode 几个小时后:
我意识到问题出在二维码外观上。反转颜色后,检测工作正常。
有没有办法让 Vision API 检测到第一个 QRCode?我尝试启用所有符号系统,但没有成功。我猜这是可能的,因为应用程序 QR Code Reader 检测到它。
我认为这仍然是一个悬而未决的问题,详情请参阅link。开发人员指出的一种解决方法:
Right, the barcode API generally doesn't support color-inverted codes. There's no parameter or option to control this at the moment. Though some APIs support them, I don't believe it's a common feature.
For a workaround, you could preprocess the colors in the bitmap before passing them to the barcode API (perhaps inverting colors on alternate frames).
希望对您有所帮助。
我改进了 google 示例应用 "barcode-reader" 以检测倒置彩色条形码和常规条形码。
这是一个 link 到 google 的示例应用程序:
https://github.com/googlesamples/android-vision/tree/master/visionSamples/barcode-reader
我通过编辑 "CameraSource" class 做到了这一点,
包裹:"com.google.android.gms.samples.vision.barcodereader.ui.camera"
.
我添加了一个参数:private boolean isInverted = false;
并更改函数 void setNextFrame(byte[] data, Camera camera)
:
void setNextFrame(byte[] data, Camera camera) {
synchronized (mLock) {
if (mPendingFrameData != null) {
camera.addCallbackBuffer(mPendingFrameData.array());
mPendingFrameData = null;
}
if (!mBytesToByteBuffer.containsKey(data)) {
Log.d(TAG,
"Skipping frame. Could not find ByteBuffer associated with the image " +
"data from the camera.");
return;
}
mPendingTimeMillis = SystemClock.elapsedRealtime() - mStartTimeMillis;
mPendingFrameId++;
if (!isInverted){
for (int y = 0; y < data.length; y++) {
data[y] = (byte) ~data[y];
}
isInverted = true;
} else {
isInverted = false;
}
mPendingFrameData = mBytesToByteBuffer.get(data);
// Notify the processor thread if it is waiting on the next frame (see below).
mLock.notifyAll();
}
}