Skip to content

Commit 1820592

Browse files
committed
Added advanced settings: camera resolution, model resolution, inference target
1 parent 414a2d3 commit 1820592

File tree

7 files changed

+93
-19
lines changed

7 files changed

+93
-19
lines changed

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/helpers/Constants.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,5 +198,17 @@ public class Constants {
198198
// Language preferences
199199
public static final String SHARED_PREFERENCES_LANGUAGE = "SELECTED_LANGUAGE";
200200
public static final String SHARED_PREFERENCES_LANGUAGE_DEFAULT = "system"; // "system" means use device language
201+
202+
// Model Input Size preferences
203+
public static final String SHARED_PREFERENCES_MODEL_INPUT_SIZE = "SHARED_PREFERENCES_MODEL_INPUT_SIZE";
204+
public static final String SHARED_PREFERENCES_MODEL_INPUT_SIZE_DEFAULT = "MEDIUM";
205+
206+
// Camera Resolution preferences
207+
public static final String SHARED_PREFERENCES_CAMERA_RESOLUTION = "SHARED_PREFERENCES_CAMERA_RESOLUTION";
208+
public static final String SHARED_PREFERENCES_CAMERA_RESOLUTION_DEFAULT = "MP_2";
209+
210+
// Inference Type preferences
211+
public static final String SHARED_PREFERENCES_INFERENCE_TYPE = "SHARED_PREFERENCES_INFERENCE_TYPE";
212+
public static final String SHARED_PREFERENCES_INFERENCE_TYPE_DEFAULT = "DSP";
201213

202214
}

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/helpers/ECameraResolution.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,30 @@
44
import com.zebra.ai_multibarcodes_capture.R;
55

66
public enum ECameraResolution {
7-
MP_1(R.string.camera_resolution_1mp, R.string.camera_resolution_1mp_description),
8-
MP_2(R.string.camera_resolution_2mp, R.string.camera_resolution_2mp_description),
9-
MP_4(R.string.camera_resolution_4mp, R.string.camera_resolution_4mp_description),
10-
MP_8(R.string.camera_resolution_8mp, R.string.camera_resolution_8mp_description);
7+
MP_1(R.string.camera_resolution_1mp, R.string.camera_resolution_1mp_description,1280,720),
8+
MP_2(R.string.camera_resolution_2mp, R.string.camera_resolution_2mp_description,1920,1080),
9+
MP_4(R.string.camera_resolution_4mp, R.string.camera_resolution_4mp_description,2688,1512),
10+
MP_8(R.string.camera_resolution_8mp, R.string.camera_resolution_8mp_description,3840,2160);
1111

1212
private final int shortDescriptionResId;
1313
private final int longDescriptionResId;
14+
private final int width, height;
1415

15-
ECameraResolution(int shortDescriptionResId, int longDescriptionResId) {
16+
ECameraResolution(int shortDescriptionResId, int longDescriptionResId, int width, int height) {
1617
this.shortDescriptionResId = shortDescriptionResId;
1718
this.longDescriptionResId = longDescriptionResId;
19+
this.width = width;
20+
this.height = height;
21+
}
22+
23+
public int getWidth()
24+
{
25+
return this.width;
26+
}
27+
28+
public int getHeight()
29+
{
30+
return height;
1831
}
1932

2033
public static ECameraResolution fromString(String shortDescription, Context context) {

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/helpers/EInferenceType.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.zebra.ai_multibarcodes_capture.helpers;
22

33
import android.content.Context;
4+
5+
import com.zebra.ai.vision.detector.InferencerOptions;
46
import com.zebra.ai_multibarcodes_capture.R;
57

68
public enum EInferenceType {
@@ -41,6 +43,21 @@ public String toString(Context context) {
4143
return context.getString(shortDescriptionResId);
4244
}
4345

46+
public int toInferencerOptions()
47+
{
48+
switch(this)
49+
{
50+
case DSP:
51+
return InferencerOptions.DSP;
52+
case CPU:
53+
return InferencerOptions.CPU;
54+
case GPU:
55+
return InferencerOptions.GPU;
56+
default:
57+
return InferencerOptions.CPU;
58+
}
59+
}
60+
4461
public String getDescription(Context context) {
4562
if (context == null) {
4663
return "";

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/helpers/EModelInputSize.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import com.zebra.ai_multibarcodes_capture.R;
55

66
public enum EModelInputSize {
7-
SMALL(R.string.resolution_small, R.string.resolution_small_description),
8-
MEDIUM(R.string.resolution_medium, R.string.resolution_medium_description),
9-
LARGE(R.string.resolution_large, R.string.resolution_large_description);
7+
SMALL(R.string.resolution_small, R.string.resolution_small_description, 640, 640),
8+
MEDIUM(R.string.resolution_medium, R.string.resolution_medium_description,1280,1280),
9+
LARGE(R.string.resolution_large, R.string.resolution_large_description,1600,1600);
1010

1111
private final int shortDescriptionResId;
1212
private final int longDescriptionResId;
13+
private final int width, height;
1314

14-
EModelInputSize(int shortDescriptionResId, int longDescriptionResId) {
15+
EModelInputSize(int shortDescriptionResId, int longDescriptionResId, int width, int height) {
1516
this.shortDescriptionResId = shortDescriptionResId;
1617
this.longDescriptionResId = longDescriptionResId;
18+
this.width = width;
19+
this.height = height;
1720
}
1821

1922
public static EModelInputSize fromString(String shortDescription, Context context) {
@@ -41,6 +44,16 @@ public String toString(Context context) {
4144
return context.getString(shortDescriptionResId);
4245
}
4346

47+
public int getWidth()
48+
{
49+
return this.width;
50+
}
51+
52+
public int getHeight()
53+
{
54+
return height;
55+
}
56+
4457
public String getDescription(Context context) {
4558
if (context == null) {
4659
return "";

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/java/CameraXLivePreviewActivity.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.content.Context;
66
import android.content.Intent;
77
import android.content.IntentFilter;
8+
import android.content.SharedPreferences;
89
import android.content.pm.ActivityInfo;
910
import android.graphics.Rect;
1011
import android.graphics.RectF;
@@ -44,6 +45,7 @@
4445
import com.zebra.ai_multibarcodes_capture.R;
4546
import com.zebra.ai_multibarcodes_capture.databinding.ActivityCameraXlivePreviewBinding;
4647
import com.zebra.ai_multibarcodes_capture.helpers.Constants;
48+
import com.zebra.ai_multibarcodes_capture.helpers.ECameraResolution;
4749
import com.zebra.ai_multibarcodes_capture.helpers.LocaleHelper;
4850
import com.zebra.ai_multibarcodes_capture.helpers.LogUtils;
4951
import com.zebra.ai_multibarcodes_capture.helpers.PreferencesHelper;
@@ -143,7 +145,7 @@ public void run() {
143145
private EntityViewController entityViewController;
144146
private EntityViewGraphic entityViewGraphic;
145147
private boolean isIconStyleEnable = false;
146-
private final Size selectedSize = new Size(1920, 1080);
148+
private Size selectedSize;
147149

148150
// Store pending viewfinder resize data to apply once analyzer is ready
149151
private android.graphics.Matrix pendingTransformMatrix = null;
@@ -171,6 +173,12 @@ protected void onCreate(Bundle savedInstanceState) {
171173
Intent intent = getIntent();
172174
captureFilePath = intent.getStringExtra(Constants.CAPTURE_FILE_PATH);
173175

176+
// Initialize selectedSize from shared preferences
177+
SharedPreferences sharedPreferences = getSharedPreferences(getPackageName(), Context.MODE_PRIVATE);
178+
String cameraResolutionString = sharedPreferences.getString(Constants.SHARED_PREFERENCES_CAMERA_RESOLUTION, Constants.SHARED_PREFERENCES_CAMERA_RESOLUTION_DEFAULT);
179+
ECameraResolution cameraResolution = ECameraResolution.valueOf(cameraResolutionString);
180+
selectedSize = new Size(cameraResolution.getWidth(), cameraResolution.getHeight());
181+
174182
binding = ActivityCameraXlivePreviewBinding.inflate(getLayoutInflater());
175183
cameraSelector = new CameraSelector.Builder().requireLensFacing(lensFacing).build();
176184
setContentView(binding.getRoot());

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/java/analyzers/barcodetracker/BarcodeTracker.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.zebra.ai.vision.detector.AIVisionSDKLicenseException;
1313
import com.zebra.ai.vision.detector.BarcodeDecoder;
1414
import com.zebra.ai.vision.detector.InferencerOptions;
15+
import com.zebra.ai_multibarcodes_capture.helpers.EInferenceType;
16+
import com.zebra.ai_multibarcodes_capture.helpers.EModelInputSize;
1517
import com.zebra.ai_multibarcodes_capture.helpers.LogUtils;
1618

1719
import java.util.List;
@@ -93,13 +95,22 @@ public void initializeBarcodeDecoder(Context context) {
9395
try {
9496
BarcodeDecoder.Settings decoderSettings = new BarcodeDecoder.Settings(mavenModelName);
9597
Integer[] rpo = new Integer[1];
96-
rpo[0] = InferencerOptions.DSP;
98+
99+
// Retrieve inference type from shared preferences
100+
SharedPreferences sharedPreferences = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE);
101+
String inferenceTypeString = sharedPreferences.getString(SHARED_PREFERENCES_INFERENCE_TYPE, SHARED_PREFERENCES_INFERENCE_TYPE_DEFAULT);
102+
EInferenceType inferenceType = EInferenceType.valueOf(inferenceTypeString);
103+
rpo[0] = inferenceType.toInferencerOptions();
104+
105+
// Retrieve model input size from shared preferences
106+
String modelInputSizeString = sharedPreferences.getString(SHARED_PREFERENCES_MODEL_INPUT_SIZE, SHARED_PREFERENCES_MODEL_INPUT_SIZE_DEFAULT);
107+
EModelInputSize modelInputSize = EModelInputSize.valueOf(modelInputSizeString);
97108

98109
setAvailableSymbologiesFromPreferences(context, decoderSettings);
99110

100111
decoderSettings.detectorSetting.inferencerOptions.runtimeProcessorOrder = rpo;
101-
decoderSettings.detectorSetting.inferencerOptions.defaultDims.height = 640;
102-
decoderSettings.detectorSetting.inferencerOptions.defaultDims.width = 640;
112+
decoderSettings.detectorSetting.inferencerOptions.defaultDims.height = modelInputSize.getHeight();
113+
decoderSettings.detectorSetting.inferencerOptions.defaultDims.width = modelInputSize.getWidth();
103114

104115
long m_Start = System.currentTimeMillis();
105116
BarcodeDecoder.getBarcodeDecoder(decoderSettings, executor).thenAccept(decoderInstance -> {

AI_MutliBarcodes_Capture/src/main/java/com/zebra/ai_multibarcodes_capture/settings/SettingsActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ private void loadBarcodesSymbologies(SharedPreferences sharedPreferences) {
339339
}
340340

341341
private void loadModelInputSize(SharedPreferences sharedPreferences) {
342-
String modelInputSize = sharedPreferences.getString("SHARED_PREFERENCES_MODEL_INPUT_SIZE", "MEDIUM");
342+
String modelInputSize = sharedPreferences.getString(SHARED_PREFERENCES_MODEL_INPUT_SIZE, SHARED_PREFERENCES_MODEL_INPUT_SIZE_DEFAULT);
343343

344344
// Set the radio button based on saved preference
345345
if ("SMALL".equals(modelInputSize)) {
@@ -353,7 +353,7 @@ private void loadModelInputSize(SharedPreferences sharedPreferences) {
353353
}
354354

355355
private void loadCameraResolution(SharedPreferences sharedPreferences) {
356-
String cameraResolution = sharedPreferences.getString("SHARED_PREFERENCES_CAMERA_RESOLUTION", "MP_2");
356+
String cameraResolution = sharedPreferences.getString(SHARED_PREFERENCES_CAMERA_RESOLUTION, SHARED_PREFERENCES_CAMERA_RESOLUTION_DEFAULT);
357357

358358
// Set the radio button based on saved preference
359359
if ("MP_1".equals(cameraResolution)) {
@@ -369,7 +369,7 @@ private void loadCameraResolution(SharedPreferences sharedPreferences) {
369369
}
370370

371371
private void loadInferenceType(SharedPreferences sharedPreferences) {
372-
String inferenceType = sharedPreferences.getString("SHARED_PREFERENCES_INFERENCE_TYPE", "DSP");
372+
String inferenceType = sharedPreferences.getString(SHARED_PREFERENCES_INFERENCE_TYPE, SHARED_PREFERENCES_INFERENCE_TYPE_DEFAULT);
373373

374374
// Set the radio button based on saved preference
375375
if ("GPU".equals(inferenceType)) {
@@ -574,7 +574,7 @@ private void saveModelInputSize(SharedPreferences.Editor editor) {
574574
modelInputSize = "LARGE";
575575
}
576576

577-
editor.putString("SHARED_PREFERENCES_MODEL_INPUT_SIZE", modelInputSize);
577+
editor.putString(SHARED_PREFERENCES_MODEL_INPUT_SIZE, modelInputSize);
578578
}
579579

580580
private void saveCameraResolution(SharedPreferences.Editor editor) {
@@ -588,7 +588,7 @@ private void saveCameraResolution(SharedPreferences.Editor editor) {
588588
cameraResolution = "MP_8";
589589
}
590590

591-
editor.putString("SHARED_PREFERENCES_CAMERA_RESOLUTION", cameraResolution);
591+
editor.putString(SHARED_PREFERENCES_CAMERA_RESOLUTION, cameraResolution);
592592
}
593593

594594
private void saveInferenceType(SharedPreferences.Editor editor) {
@@ -600,7 +600,7 @@ private void saveInferenceType(SharedPreferences.Editor editor) {
600600
inferenceType = "CPU";
601601
}
602602

603-
editor.putString("SHARED_PREFERENCES_INFERENCE_TYPE", inferenceType);
603+
editor.putString(SHARED_PREFERENCES_INFERENCE_TYPE, inferenceType);
604604
}
605605

606606
private String getSelectedExtension()

0 commit comments

Comments
 (0)