Skip to content
Snippets Groups Projects
Commit 209408ab authored by “kamon's avatar “kamon
Browse files

amelioration de l'affichage des resultats de prediction et integrations deu nom et logo de l'app

parent 4e65e4b1
No related branches found
No related tags found
1 merge request!3amelioration de l'affichage des resultats de prediction et integrations des nom et logo de l'app
package com.example.myapplication;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import java.util.Map;
/**
* this class purpose is to store information of the output of the recognation species
*/
public class OutputPredictedImage {
private Bitmap annotatedImage;
private Map<String, Integer> predictionResults;
public OutputPredictedImage(Bitmap annotatedImage, Map<String,Integer> predictionResults){
this.annotatedImage = annotatedImage;
this.predictionResults = predictionResults;
}
@Override
public String toString(){
StringBuilder result = new StringBuilder();
for (Map.Entry<String, Integer> entry : predictionResults.entrySet()) {
// Append the key (species) and value (probability) in the specified format
result.append(entry.getKey())
.append(" : ")
.append(entry.getValue()) // Format the float to 2 decimal places
.append("\n"); // Add a newline for separation
}
// Return the concatenated string
return result.toString(); // Remove the last newline
}
public Bitmap getAnnotatedImage() {
return annotatedImage;
}
public Map<String, Integer> getPredictionResults() {
return predictionResults;
}
}
......@@ -123,22 +123,14 @@ public class PhotoPage extends Fragment {
try {
TestModeleTflite testModeleTflite = new TestModeleTflite(this.getContext());
/*
List<String> speciesDetected = testModeleTflite.recognizeSpeciesClass(scaledBitmap);
StringBuilder recognationOutput = new StringBuilder("Espèces détectées : ");
for(String specie:speciesDetected){
recognationOutput.append(specie).append("\t");
}
TextView textView = getView().findViewById(R.id.textView2);
textView.setText(recognationOutput);*/
Bitmap annotatedImage = testModeleTflite.recognizeSpecies(bitmap);
OutputPredictedImage outputPredictedImage = testModeleTflite.recognizeSpeciesClass(bitmap);
Bitmap annotatedImage = outputPredictedImage.getAnnotatedImage();
double height = 1.5 * annotatedImage.getHeight();
double width = 1.5 * annotatedImage.getWidth();
scaledBitmap = Bitmap.createScaledBitmap(annotatedImage, (int) width, (int) height, true);
imageView.setImageBitmap(scaledBitmap);
//TextView textView = getView().findViewById(R.id.textView2);
textView.setText(outputPredictedImage.toString());
} catch (IOException e) {
throw new RuntimeException(e);
......
......@@ -27,7 +27,9 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.MappedByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TestModeleTflite {
private static final String MODEL_PATH = "model_float32.tflite";
......@@ -217,6 +219,7 @@ public class TestModeleTflite {
);
canvas.drawRect(rect, paint);
canvas.drawText(box.clsName, rect.left, rect.bottom, textPaint);
canvas.drawText(new StringBuilder().append("prob : ").append(String.format("%.2f", box.cnf)).toString(), rect.left, rect.top, textPaint);
}
return mutableBitmap;
......@@ -243,14 +246,22 @@ public class TestModeleTflite {
return annotateImage(inputImage, boxes);
}
public List<String> recognizeSpeciesClass(Bitmap inputImage){
ArrayList<String> speciesNames = new ArrayList<>();
public OutputPredictedImage recognizeSpeciesClass(Bitmap inputImage){
//ArrayList<String> speciesNames = new ArrayList<>();
Map<String, Integer> predictionResults = new HashMap<>();
TensorBuffer outputBuffer = predict(inputImage);
List<BoundingBox> boxes = processOutput(outputBuffer);
for(BoundingBox box:boxes){
if(!speciesNames.contains(box.clsName)) speciesNames.add(box.clsName);
if(predictionResults.containsKey(box.clsName)){
int previousNumber = predictionResults.get(box.clsName);
predictionResults.put(box.clsName, previousNumber + 1);
}else{
predictionResults.put(box.clsName, 1);
}
}
return speciesNames;
Bitmap annotatedImage = annotateImage(inputImage, boxes);
return new OutputPredictedImage(annotatedImage, predictionResults);
}
......
......@@ -7,11 +7,14 @@
tools:context=".PhotoPage">
<!-- Prediction Text -->
<!-- Accuracy Text -->
<TextView
android:id="@+id/textView"
android:layout_width="9dp"
android:layout_height="0dp"
android:layout_marginBottom="200dp"
android:layout_width="351dp"
android:layout_height="28dp"
android:layout_marginBottom="196dp"
android:text=""
android:textColor="#F12B2B"
android:textSize="17sp"
......@@ -20,7 +23,6 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<!-- Accuracy Text -->
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment