我使用 Google 的 ML Kit 进行条形码扫描,并从 Google 提供的示例和教程中收集了以下代码。然而,表演却很戏剧化。识别条形码需要几秒钟,可能是 10、15 秒。有什么办法可以改善这一点吗?
另外,这如何与倒置的条形码一起使用?我发现我需要反转图像,但是,如果在分析器中我尝试获取 image.bitmapInternal 或 image.byteBuffer,它始终为空。
构建.gradle
implementation 'com.google.mlkit:barcode-scanning:17.0.0'
// CameraX core library using camera2 implementation
implementation "androidx.camera:camera-camera2:1.0.2"
// CameraX Lifecycle Library
implementation "androidx.camera:camera-lifecycle:1.0.2"
// CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha31"
Run Code Online (Sandbox Code Playgroud)
然后,在一个片段中:
typealias BarCodeListener = (barCode: String) -> Unit
const val TAG = "ConnectorScanner"
[...]
override fun onResume() {
super.onResume()
cameraExecutor = Executors.newSingleThreadExecutor()
startCamera()
}
private fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(requireContext())
val resolution = Size(720, 1280)
cameraProviderFuture.addListener({
// Used to bind …
Run Code Online (Sandbox Code Playgroud) 我们在 iOS 上使用 GoogleMLKit,现在我们的团队正在切换到 m1 Macbook。我们必须设置一些条件才能使其在 ios-arm64-simulator 上运行,如下所示
我想知道google官方是否有计划支持ios-arm64-simulator比如提供xcframework?
我想使用 Google ML Kit 和 CameraX API 制作实时图像分类器。我正在使用 CameraX API 的预览和分析。它给出的错误为
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: Caused by: java.lang.IllegalStateException: Image is already closed
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at android.media.Image.throwISEIfImageIsInvalid(Image.java:68)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at android.media.ImageReader$SurfaceImage$SurfacePlane.getBuffer(ImageReader.java:832)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.common.internal.ImageConvertUtils.zza(com.google.mlkit:vision-common@@16.0.0:139)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.common.internal.ImageConvertUtils.convertToUpRightBitmap(com.google.mlkit:vision-common@@16.0.0:89)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.common.internal.ImageConvertUtils.getUpRightBitmap(com.google.mlkit:vision-common@@16.0.0:10)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.label.automl.internal.zzo.zza(com.google.mlkit:image-labeling-automl@@16.0.0:16)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.label.automl.internal.zzo.run(com.google.mlkit:image-labeling-automl@@16.0.0:60)
2020-07-27 01:17:18.145 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.common.internal.MobileVisionBase.zza(com.google.mlkit:vision-common@@16.0.0:23)
2020-07-27 01:17:18.146 11009-11009/com.example.camerax_automl W/System.err: at com.google.mlkit.vision.common.internal.zzb.call(com.google.mlkit:vision-common@@16.0.0)
2020-07-27 01:17:18.146 11009-11009/com.example.camerax_automl W/System.err: …
Run Code Online (Sandbox Code Playgroud) 我下面这个关于创建使用TensorFlow精简版上的协同合作模型制作自定义模型教程。
import pathlib
path = pathlib.Path('/content/employee_pics')
count = len(list(path.glob('*/*.jpg')))
count
data = ImageClassifierDataLoader.from_folder(path)
train_data, test_data = data.split(0.5)
Run Code Online (Sandbox Code Playgroud)
我有第 2 步的问题:
model = image_classifier.create(train_data)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:ValueError: Expect x to be a non-empty array or dataset。
难道我做错了什么?不过,示例中提供的数据集运行良好。为什么?
我想识别并计算图片中的对象,例如计算社区图片中的房屋数量。使用 ML Kit 执行此操作的最佳方法是什么?
我需要使用对象检测 API吗?或者是否可以使用直接的图像标签获得多个“房屋”标签?
您好,我正在使用 android mlkit 条码扫描仪,无需 firebase 和 androidx ,我遵循此代码https://medium.com/@surya.n1447/google-vision-ml-kit-with-camerax-64bbbfd4c6fd 当我扫描 qrcode 时,它是太慢了,我不知道如何提高扫描速度,是否有一些技巧或类似的东西?还是改用 zxing 还是 Google Vision 更好?我用的是小米10T Pro
类 ScanPersonFragment : Fragment() {
private var processingBarcode = AtomicBoolean(false)
private var mediaPlayer: MediaPlayer? = null
private lateinit var cameraExecutor: ExecutorService
private lateinit var scanBarcodeViewModel: ScanPersonViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
cameraExecutor = Executors.newSingleThreadExecutor()
scanBarcodeViewModel = ViewModelProvider(this).get(ScanPersonViewModel::class.java)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val v = inflater.inflate(R.layout.fragment_scan_person_destination, container, false)
mediaPlayer = MediaPlayer.create(context, R.raw.beep)
scanBarcodeViewModel.progressState.observe(viewLifecycleOwner, …
Run Code Online (Sandbox Code Playgroud) android computer-vision android-camera firebase-mlkit google-mlkit
Google 的 MLKit(不含 Firebase)是新的,所以我遇到了麻烦。我试图在这里遵循这个例子: https: //developers.google.com/ml-kit/vision/object-detection/custom-models/android
该应用程序可以正常打开,并且相机可以正常工作(例如,我可以看到东西)。但实际检测似乎不起作用。
我是否缺少实际检测对象的部分代码?或者是CameraX或ImageInput的实现有问题?
package com.example.mlkitobjecttest;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.CameraX;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.Preview;
import androidx.camera.core.impl.PreviewConfig;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import android.content.pm.PackageManager;
import android.graphics.Rect;
import android.media.Image;
import android.os.Bundle;
import android.text.Layout;
import android.util.Rational;
import android.util.Size;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.mlkit.common.model.LocalModel;
import com.google.mlkit.vision.common.InputImage;
import com.google.mlkit.vision.objects.DetectedObject;
import com.google.mlkit.vision.objects.ObjectDetection;
import com.google.mlkit.vision.objects.ObjectDetector;
import com.google.mlkit.vision.objects.custom.CustomObjectDetectorOptions;
import org.w3c.dom.Text;
import java.util.List; …
Run Code Online (Sandbox Code Playgroud) 每次调用 scanr.process(image) 都会导致 onFailure 调用,并出现以下错误:
错误:com.google.mlkit.common.MlKitException:执行机器学习套件任务时发生内部错误
关于为什么任务失败的任何进一步细节或想法?用条形码显示它似乎也不会改变这种行为。
使用 Pixel 3a 时会显示此错误,但会导致 Nexus 5 完全崩溃并出现 SIGENV 错误。在阅读概述时,我一直在从片段构建我的代码
package jp.oist.cameraxapp;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.Preview;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.widget.Toast;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.mlkit.vision.barcode.Barcode;
import …
Run Code Online (Sandbox Code Playgroud) 如果我在 MLKit 中使用预训练的 TFLite 对象检测模型,则会收到以下错误:
Run Code Online (Sandbox Code Playgroud)CalculatorGraph::Run() failed in Run: Calculator::Open() for node "BoxClassifierCalculator" failed: #vk Unexpected number of dimensions for output index 0: got 3D, expected either 2D (BxN with B=1) or 4D (BxHxWxN with B=1, W=1, H=1).
知道我可能做错了什么吗?
我一直在尝试使用Google ML 人脸检测 iOS 库, 但存在一个问题,它不能与前置摄像头配合使用,只有当我在手机上使用后置摄像头时才能检测到人脸。我打印了方向,正面和背面之间的所有内容都匹配。它似乎适用于我的 iPhone X 的正面和背面,但是当我在 iPhone 11 和 iPhone X max 上对其进行测试时,它仅适用于后置摄像头。我不确定是什么导致了这种不一致。我使用的代码如下,注意所有传入 photoVerification 函数的图像首先通过 fixedOrientation 函数运行以确保一致性:
func photoVerification(image: UIImage?) {
guard let imageFace = image else { return }
//Enhanced Face Detection
let options = FaceDetectorOptions()
options.performanceMode = .accurate
//Initialize face detector with given options
let faceDetector = FaceDetector.faceDetector(options: options)
// Initialize a VisionImage object with the given UIImage.
let visionImage = VisionImage(image: imageFace)
visionImage.orientation = imageFace.imageOrientation
print("$$The Images Orientation is: ",imageFace.imageOrientation.rawValue)
faceDetector.process(visionImage) { faces, …
Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌数字墨水进行手写识别。需要下载一次的模型大小为20MB,下载需要一些时间。有没有办法使用进度条显示下载进度?
我的代码如下:
fun download(context: Context) {
var modelIdentifier: DigitalInkRecognitionModelIdentifier? = null
try {
modelIdentifier =
DigitalInkRecognitionModelIdentifier.fromLanguageTag(lang)
} catch (e: MlKitException) {
// language tag failed to parse, handle error.
}
model = DigitalInkRecognitionModel.builder(modelIdentifier!!).build()
val remoteModelManager = RemoteModelManager.getInstance()
remoteModelManager.download(model, DownloadConditions.Builder().build())
.addOnSuccessListener {
Log.i("StrokeManager", "Model downloaded")
Toast.makeText(context, "Model Downloaded", Toast.LENGTH_SHORT).show()
}
.addOnFailureListener { e: Exception ->
Log.e("StrokeManager", "Error while downloading a model: $e")
Toast.makeText(context, "Model Download Failed", Toast.LENGTH_SHORT).show()
}
}
Run Code Online (Sandbox Code Playgroud) 添加后com.google.mlkit:face-detection:16.0.7
我有以下日志错误我该怎么办?
在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0 中发现重复的类 com.google.firebase.components.Component -runtime (com.google.firebase:firebase-components:16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase: firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase-components:16.0.0) 在 com.google.firebase.components.Component$Builder 中找到重复的类模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase-components: 16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components 中发现重复的类 com.google.firebase.components.ComponentContainer -16.0.0-runtime (com.google.firebase:firebase-components:16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime (com.google) 中找到重复的类 com.google.firebase.components.ComponentFactory .firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase-components:16.0.0) 找到重复的类 com.google.firebase.components.ComponentRegistrar在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase-components) :16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase- 中发现重复的类 com.google.firebase.components.Dependency Components-16.0.0-runtime (com.google.firebase:firebase-components:16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime (com. google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase-components:16.0.0) 重复类 com.google.firebase.components.DependencyException在模块 jetified-firebase-common-16.0.3-runtime (com.google.firebase:firebase-common:16.0.3) 和 jetified-firebase-components-16.0.0-runtime (com.google.firebase:firebase- Components:16.0.0) 在模块 jetified-firebase-common-16.0.3-runtime …
我正在使用 Google ML Kit 进行自拍分割(https://developers.google.com/ml-kit/vision/selfie-segmentation)。然而,我得到的输出非常差 -
初始图像:
带叠加的分割图像:观察该女性的头发如何标记为粉红色,以及健身器材和她腿部附近的周围区域如何标记为非粉红色。甚至她的手也被标记为粉红色(意味着它是背景)。
当它叠加在另一张图像上以创建背景去除效果时,看起来很糟糕
ML Kit 返回的分割掩模对于上述所有非粉色区域的置信度均为 1.0,这意味着绝对可以肯定非粉色区域是人的一部分!
我在几张图片中看到了这一点,而不仅仅是这张图片。事实上,图像分割器的性能(置信度)相当差。
问题是 - 有没有办法改进它,也许通过提供不同/更好的模型?如果我使用 PixelLib 之类的东西,分割效果会更好,尽管该库的性能延迟不低,因此无法在移动设备上运行。
任何有关此的指示/帮助将不胜感激。
image-processing image-segmentation google-vision google-mlkit
google-mlkit ×13
android ×6
ios ×2
java ×2
tensorflow ×2
dependencies ×1
keras ×1
kotlin ×1
swift ×1
tf.keras ×1