gpt4 book ai didi

android - ImageAnalyzer ML Kit 边界框错列

转载 作者:行者123 更新时间:2023-12-03 20:40:14 27 4
gpt4 key购买 nike

我有一个简单的布局:

 <RelativeLayout
android:id="@+id/myP"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<androidx.camera.view.PreviewView
android:id="@+id/mPreviewView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

<com.example.dochjavatestimplementation.pkgActivity.ExtendedImageView
android:id="@+id/imageViewOmgShowIt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />

</RelativeLayout>
previewView 用于显示相机,ExtendedImageView 用于显示显示找到的对象rect。
我的图像分析器:
imageAnalysis = new ImageAnalysis.Builder()
.setTargetResolution(new Size(mPreviewView.getWidth(),mPreviewView.getHeight()))
.build();

imageAnalysis.setAnalyzer(executor, new PaperImageAnalyser());
纸张图像分析器:
public class PaperImageAnalyser implements ImageAnalysis.Analyzer {


ObjectDetectorOptions options = new ObjectDetectorOptions.Builder()
.setDetectorMode(ObjectDetectorOptions.STREAM_MODE)
.enableClassification() // Optional
.build();

ObjectDetector objectDetector = ObjectDetection.getClient(options);



@Override
public void analyze(@NonNull ImageProxy imageProxy) {
@SuppressLint("UnsafeExperimentalUsageError") Image mediaImage = imageProxy.getImage();

if (mediaImage != null) {
InputImage image =InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees());

objectDetector.process(image)
.addOnSuccessListener(
new OnSuccessListener<List<DetectedObject>>() {
@Override
public void onSuccess(List<DetectedObject> detectedObjects) {

for (DetectedObject detectedObject : detectedObjects) {
Rect boundingBox = detectedObject.getBoundingBox();
CameraImp.imageViewOmgShowIt.drawFoundObj(boundingBox);
}

}
})
.addOnFailureListener(
new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.e("error",""+e.getMessage());
}
})
.addOnCompleteListener(new OnCompleteListener<List<DetectedObject>>() {
@SuppressLint("UnsafeExperimentalUsageError")
@Override
public void onComplete(@NonNull Task<List<DetectedObject>> task) {
imageProxy.getImage().close();
imageProxy.close();

}
});
}
}
}
绘制矩形:
public void drawFoundObj(Rect boundingBox) {
foundYo = boundingBox;
invalidate(); //call draw
}
Paint mPaint = new Paint();
Canvas mCanvas = new Canvas();
@Override
protected void onDraw(Canvas canvas) {

//clear exsisting rects
Xfermode x = mPaint.getXfermode();
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
mPaint.setXfermode(x);
mCanvas.drawPaint(mPaint);


//set current rect
Paint paint = new Paint();
paint.setColor(Color.YELLOW);
paint.setStrokeWidth(3);

paint.setAlpha(40);
canvas.drawRect(foundYo,paint);
}
结果如下所示:
result1
result2
如您所见,问题是尽管对象以某种方式被识别,但与对象的位置相比,坐标是错误的。
原因可能是什么?
我从图像分析仪收到的图像的分辨率是否更小,从而可能导致坐标更小从而更错误?
还是我画错了图片?

最佳答案

您将需要获取分析图像的宽度和高度,并将边界框转换为正确的大小以进行显示。请引用 mlkit vision_quickstart 中的这个示例作为引用。 https://github.com/googlesamples/mlkit/blob/74d5edb101d1e2fb8bd404c41a684b71a06d507a/android/vision-quickstart/app/src/main/java/com/google/mlkit/vision/demo/java/CameraXLivePreviewActivity.java#L421

关于android - ImageAnalyzer ML Kit 边界框错列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67349758/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com