Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions OCR-Benchmark/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

66 changes: 66 additions & 0 deletions OCR-Benchmark/.idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions OCR-Benchmark/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {

implementation 'com.google.mlkit:barcode-scanning:17.1.0'
implementation 'com.google.android.gms:play-services-mlkit-text-recognition:19.0.0'
implementation 'com.google.mlkit:object-detection:17.0.0'

implementation 'org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.9.0'
Expand All @@ -53,4 +54,14 @@ dependencies {
implementation "androidx.room:room-runtime:2.5.2"
annotationProcessor "androidx.room:room-compiler:2.5.2"
implementation "androidx.room:room-rxjava3:2.5.2"

implementation "androidx.camera:camera-camera2:1.2.3"
implementation "androidx.camera:camera-lifecycle:1.2.3"
implementation 'androidx.camera:camera-view:1.2.3'

implementation 'androidx.navigation:navigation-fragment:2.5.3'
implementation 'androidx.navigation:navigation-ui:2.5.3'
implementation "androidx.navigation:navigation-compose:2.5.3"

implementation "com.google.code.gson:gson:2.9.0"
}
13 changes: 13 additions & 0 deletions OCR-Benchmark/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE>" />
<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
Expand All @@ -19,6 +21,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.OCRBenchmark"
android:requestLegacyExternalStorage="true"
tools:targetApi="31" >

<activity
Expand All @@ -33,5 +36,15 @@

</activity>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import androidx.room.Database;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverter;
import androidx.room.TypeConverters;

import com.eduard05.ocr.data.local.db.daos.DaoOCRFrame;
import com.eduard05.ocr.data.local.db.daos.DaoOCRResult;
Expand All @@ -11,7 +13,8 @@
@Database(entities = {
OCRFrame.class,
OCRResult.class,
}, version = 2)
}, version = 4)
@TypeConverters({Converters.class})
public abstract class AppDatabase extends RoomDatabase {
public abstract DaoOCRFrame daoOCRFrame();
public abstract DaoOCRResult daoOCRResult();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.eduard05.ocr.data.local.db;

import androidx.room.TypeConverter;

import com.eduard05.ocr.data.local.db.dto.OCRResultDTO;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class Converters {
private static Gson gson = new GsonBuilder().setPrettyPrinting().create();

@TypeConverter
public static List<OCRResultDTO> fromString(String value) {
Type listType = new TypeToken<List<OCRResultDTO>>() {}.getType();
return gson.fromJson(value, listType);
}

@TypeConverter
public static String fromList(List<OCRResultDTO> list) {
return gson.toJson(list);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface DaoOCRFrame extends DaoBase<OCRFrame>{
@Query("SELECT COUNT(id) AS countFrames FROM OCRFrame")
LiveData<Integer> getCountFrames();

@Query("SELECT ocr.id AS id, ocr.framePath AS framePath from OCRFrame ocr WHERE id = :id")
@Query("SELECT ocr.id, ocr.framePath, ((ocr.endTime - ocr.startTime) / 1000000) AS processingTime from OCRFrame ocr WHERE id = :id")
OCRFrameDTO getById(int id);

@Query("DELETE FROM OCRFrame")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,44 @@
import androidx.room.Dao;
import androidx.room.Query;

import com.eduard05.ocr.data.local.db.dto.OCRFrameDTO;
import com.eduard05.ocr.data.local.db.dto.OCRResultDTO;
import com.eduard05.ocr.data.local.db.entity.OCRResult;

import java.util.List;

@Dao
public interface DaoOCRResult extends DaoBase<OCRResult>{

@Query("SELECT " +
"(SELECT ocr.timeEnd FROM OCRResult ocr ORDER BY ocr.timeEnd DESC LIMIT 1) - (SELECT ocr.timeInit FROM OCRResult ocr ORDER BY ocr.timeInit LIMIT 1) " +
"(SELECT ocrF.endTime FROM OCRFrame ocrF ORDER BY ocrF.endTime DESC LIMIT 1) - (SELECT ocrF.startTime FROM OCRFrame ocrF ORDER BY ocrF.startTime LIMIT 1) " +
"AS totalExecTime")
LiveData<Long> getTotalExecTime();

@Query("SELECT " +
"AVG(ocrF.endTime - ocrF.startTime) AS avgExecTime " +
"FROM OCRFrame ocrF ")
LiveData<Long> getAvgExecTime();

@Query("DELETE FROM OCRResult")
void clearAll();

@Query("SELECT " +
"ocrF.id, " +
"ocrF.framePath, " +
"AVG(ocrF.endTime - ocrF.startTime) AS processingTime " +
"FROM OCRFrame ocrF " +
"GROUP BY ocrF.id, ocrF.framePath")
List<OCRFrameDTO> getAllFrames();

@Query("SELECT ocrR.idFrame," +
" ocrR.angle," +
"ocrR.confidence," +
"ocrR.text," +
"ocrR.boundingBoxTop AS top," +
"ocrR.boundingBoxBottom AS bottom," +
"ocrR.boundingBoxRight AS 'right'," +
"ocrR.boundingBoxLeft AS 'left' " +
"FROM OCRResult ocrR WHERE ocrR.idFrame = :id;")
List<OCRResultDTO> getAllResultsFromFrames(int id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.eduard05.ocr.data.local.db.dto;

import androidx.room.TypeConverter;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class Converters {
private static Gson gson = new Gson();

@TypeConverter
public static List<OCRResultDTO> fromString(String value) {
Type listType = new TypeToken<List<OCRResultDTO>>() {}.getType();
return gson.fromJson(value, listType);
}

@TypeConverter
public static String fromList(List<OCRResultDTO> list) {
return gson.toJson(list);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package com.eduard05.ocr.data.local.db.dto;

import java.util.List;

public class OCRFrameDTO {
private int id;

private String framePath;
private long processingTime;
private List<OCRResultDTO> resultItems;

public OCRFrameDTO(){}
public OCRFrameDTO(int id, String framePath){
public OCRFrameDTO(int id, String framePath, long processingTime){
this.id = id;
this.framePath = framePath;
this.processingTime = processingTime;
}

public int getId(){return this.id;}
public void setId(int id){this.id = id;}
public String getFramePath(){return this.framePath;}
public void setFramePath(String filePath){this.framePath = filePath;}

public long getProcessingTime(){return processingTime;}
public void setProcessingTime(long processingTime){this.processingTime = processingTime;}

public List<OCRResultDTO> getResultItems(){return resultItems;}
public void setResultItems(List<OCRResultDTO> resultItems){this.resultItems = resultItems;}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.eduard05.ocr.data.local.db.dto;


public class OCRResultDTO {

private double angle;
private double confidence;
private String text;
private int top;
private int bottom;
private int right;
private int left;


public OCRResultDTO(double angle, double confidence, String text, int top, int bottom, int right, int left){
this.angle = angle;
this.confidence = confidence;
this.text = text;
this.top = top;
this.bottom = bottom;
this.left = left;
this.right = right;
}

public double getAngle() { return angle; }
public void setAngle(double angle) { this.angle = angle; }

public double getConfidence() { return confidence; }
public void setConfidence(double confidence) { this.confidence = confidence; }

public String getText() { return text; }
public void setText(String text) { this.text = text; }

public int getTop() { return top; }
public void setTop(int top) { this.top = top; }

public int getBottom() { return bottom; }
public void setBottom(int bottom) { this.bottom = bottom; }

public int getRight() { return right; }
public void setRight(int right) { this.right = right; }

public int getLeft() { return left; }
public void setLeft(int left) { this.left = left; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,24 @@ public class OCRFrame {
private Integer id;

private String framePath;
private long startTime;
private long endTime;

public OCRFrame(){}
public OCRFrame(String framePath){
public OCRFrame(String framePath, long startTime, long endTime){
this.framePath = framePath;
this.startTime = startTime;
this.endTime = endTime;
}

public Integer getId(){return this.id;}
public void setId(int id){this.id = id;}
public String getFramePath(){return this.framePath;}
public void setFramePath(String framePath){this.framePath = framePath;}

public long getStartTime(){return this.startTime;}
public void setStartTime(long startTime){this.startTime = startTime;}

public long getEndTime(){return this.endTime;}
public void setEndTime(long endTime){this.endTime = endTime;}
}
Loading