英文:
Bounding Box Cropping
问题
I did object detection. And I got it in the bounding box. I'm trying to crop inside the bounding box. but it doesn't work. in debug mode, it gets stuck on the if line. THANKS!!!
result.setLocation(location);
mappedRecognitions.add(result);
if ((int) location.left > 0 && (int) location.top > 0 && ((int) location.left + (int) location.width()) < xyBitmap.getWidth()
&& ((int) location.top + (int) location.height()) < xyBitmap.getHeight()) {
mycroppedBitmap = Bitmap.createBitmap(xyBitmap,
(int) location.left,
(int) location.top,
(int) location.width(),
(int) location.height()
);
mycroppedBitmap = Bitmap.createScaledBitmap(mycroppedBitmap, 224, 224, true);
Coordinates
> DetectorActivity.java File
> https://github.com/usertttwm/CropAndClassificationModel/blob/main/DetectorActivity.java
For classification after crop: TFLiteObjectDetectionAPIModel.java
> https://github.com/usertttwm/CropAndClassificationModel/blob/main/TFLiteObjectDetectionAPIModel
NEW!!!!!!
if (1==1) {
mycroppedBitmap = Bitmap.createBitmap(croppedBitmap,
1,1,224,224
);
final String resultLabel = detector1.recognizeImage1(mycroppedBitmap);
RESULTS
croppedBitmap
DETECTIVE (I'm trying to crop the bounding box)
UPDATE!!!!!!!!!!!!!!!!!!!!!!!
mappedRecognitions.add(result);//TRAY DETECTIVE
Bitmap copyOfOriginalBitmap = rgbFrameBitmap.copy(rgbFrameBitmap.getConfig(), true);
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap,
(int) location.left, (int)location.top, (int)location.right, (int)location.bottom);
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, 224, 224, true);
final String resultLabel = detector1.recognizeImage1(secondScaledBitmap);
CROP WORKING UPDATE
result.setLocation(location);
mappedRecognitions.add(result);
Bitmap copyOfOriginalBitmap = rgbFrameBitmap.copy(rgbFrameBitmap.getConfig(), true);
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap,
(int)location.left, (int)location.top, (int)location.right-(int)location.left, (int)location.bottom-(int)location.top);
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, 224, 224, true);
final String resultLabel = detector1.recognizeImage1(secondScaledBitmap);
CROP
------------------RESOURCES--------------
https://github.com/AarohiSingla/TFLite-Object-Detection-Android-App-Tutorial-Using-YOLOv5 I used it for object detection with yolo.
https://www.youtube.com/watch?v=ZepT3N6aNFM&t=881s
https://github.com/ivangrov/TensorFlow-Lite-Age-Gender-Estimation-on-Android/blob/main/tflite/TFLiteObjectDetectionAPIModel.java
I used it to pass through the crop and classification model.
英文:
I did object detection. And I got it in the bounding box. I'm trying to crop inside the bounding box. but it doesn't work. in debug mode, it gets stuck on the if line. THANKS!!!
result.setLocation(location);
mappedRecognitions.add(result);
if ((int) location.left > 0 && (int) location.top > 0 && ((int) location.left + (int) location.width()) < xyBitmap.getWidth()
&& ((int) location.top + (int) location.height()) < xyBitmap.getHeight()) {
mycroppedBitmap = Bitmap.createBitmap(xyBitmap,
(int) location.left,
(int) location.top,
(int) location.width(),
(int) location.height()
);
mycroppedBitmap = Bitmap.createScaledBitmap(mycroppedBitmap, 224, 224, true);
Coordinates
> DetectorActivity.java File
>
> https://github.com/usertttwm/CropAndClassificationModel/blob/main/DetectorActivity.java
>
> For classification after crop: TFLiteObjectDetectionAPIModel.java
>
> https://github.com/usertttwm/CropAndClassificationModel/blob/main/TFLiteObjectDetectionAPIModel
NEW!!!!!!
if (1==1) {
mycroppedBitmap = Bitmap.createBitmap(croppedBitmap,
1,1,224,224
);
final String resultLabel = detector1.recognizeImage1(mycroppedBitmap);
RESULTS
croppedBitmap
DETECTIVE (I'm trying to crop the bounding box)
UPDATE!!!!!!!!!!!!!!!!!!!!!!!
mappedRecognitions.add(result);//TRAY DETECTIVE
Bitmap copyOfOriginalBitmap = rgbFrameBitmap.copy(rgbFrameBitmap.getConfig(), true);
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap,
(int) location.left, (int)location.top, (int)location.right, (int)location.bottom);
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, 224, 224, true);
final String resultLabel = detector1.recognizeImage1(secondScaledBitmap);
CROP WORKİNG UPDATE
result.setLocation(location);
mappedRecognitions.add(result);
Bitmap copyOfOriginalBitmap = rgbFrameBitmap.copy(rgbFrameBitmap.getConfig(), true);
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap,
(int)location.left, (int)location.top, (int)location.right-(int)location.left, (int)location.bottom-(int)location.top);
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, 224, 224, true);
final String resultLabel = detector1.recognizeImage1(secondScaledBitmap);
------------------RESOURCES--------------
https://github.com/AarohiSingla/TFLite-Object-Detection-Android-App-Tutorial-Using-YOLOv5 I used it for object detection with yolo.
https://www.youtube.com/watch?v=ZepT3N6aNFM&t=881s
https://github.com/ivangrov/TensorFlow-Lite-Age-Gender-Estimation-on-Android/blob/main/tflite/TFLiteObjectDetectionAPIModel.java
I used it to pass through the crop and classification model.
答案1
得分: 1
这有点难以在没有提供代码和信息的情况下进行调试,但以下是我解决这个问题的明确步骤,也许你可以检查一下你的一侧,看看你的错误在哪里。
我能看到你试图从第一个裁剪的图像中裁剪第二个图像,这是错误的。你应该尝试从原始图像中为第二个解释器裁剪图像,所以这个过程应该类似于这样:
- 首先创建原始位图的副本(因为你要将其缩小)
Bitmap originalBitmap = ...; // 在这里放入你的原始位图
Bitmap copyOfOriginalBitmap = originalBitmap.copy(originalBitmap.getConfig(), true);
- 在运行第一个解释器(使用originalBitmap)之后,你将得到坐标在解释器输入的宽度或高度范围内的结果(这可能会更改,在你的日志中我看到坐标被放大了,这正是我们需要的)
Recognition myObject = ...; // 你可以在这里获取你想要的检测,可以使用一个简单的for循环来完成
// 现在通过裁剪原始图像并使用放大的坐标创建第二个位图
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap, myObject.location.left, myObject.location.top, myObject.location.right, myObject.location.bottom);
// 现在使用解释器的宽度和高度创建第二个缩放位图
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, width, height, true);
然后你应该可以继续了。
英文:
Its a little hard to debug this without the code and the information that you provided, but here are some clear steps on how I would solve this and maybe you can check on your side and see where your bug is.
What I can see is that you are trying to crop the second image from the first cropped image, which is wrong, you should try to crop the image for the second interpreter from the original image, so the process should look smth like this:
- First create a copy of the original bitmap (since you are scaling it down)
Bitmap originalBitmap = ...; // your original bitmap here
Bitmap copyOfOriginalBitmap = originalBitmap.copy(originalBitmap.getConfig(), true);
- After you run first interpreter (using originalBitmap) you will get the results that coordinates are in range from 0 to width or height of the Interpreter input (this can change, on your logs I see that coordinates are scaled up which is what we need)
Recognition myObject = ...; // you can get the detection that you want here, you can do this with a simple for loop
// now create second bitmap by cropping the original and using the scaled up coordinates
Bitmap secondBitmap = Bitmap.createBitmap(copyOfOriginalBitmap, myObject.location.left, myObject.location.top, myObject.location.right, myObject.location.bottom)
// now create the second scaled bitmap for your second Interpreter with the width and height of the interpreter size
Bitmap secondScaledBitmap = Bitmap.createScaledBitmap(secondBitmap, width, height, true)
And you should be good to go.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论