Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mirror the target control of ObjectNavFragment if front facing camera is used #386

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class ObjectNavFragment extends CameraFragment {

private Detector detector;

private boolean mirrorControl;
private Matrix frameToCropTransform;
private Bitmap croppedBitmap;
private int sensorOrientation;
Expand Down Expand Up @@ -146,6 +147,8 @@ public void onNothingSelected(AdapterView<?> parent) {}

binding.cameraToggle.setOnClickListener(v -> toggleCamera());

binding.mirrorControl.setOnClickListener(v -> mirrorControl());

List<String> models =
getModelNames(f -> f.type.equals(Model.TYPE.DETECTOR) && f.pathType != Model.PATH_TYPE.URL);
initModelSpinner(binding.modelSpinner, models, preferencesManager.getObjectNavModel());
Expand Down Expand Up @@ -228,6 +231,10 @@ public void onNothingSelected(AdapterView<?> parent) {}
});
}

private void mirrorControl() {
mirrorControl = !mirrorControl;
}

private void updateCropImageInfo() {
// Timber.i("%s x %s",getPreviewSize().getWidth(), getPreviewSize().getHeight());
// Timber.i("%s x %s",getMaxAnalyseImageSize().getWidth(),
Expand Down Expand Up @@ -477,7 +484,12 @@ protected void processFrame(Bitmap bitmap, ImageProxy image) {
}

tracker.trackResults(mappedRecognitions, frameNum);
handleDriveCommand(tracker.updateTarget());
Control target = tracker.updateTarget();
if (mirrorControl) {
handleDriveCommand(target.mirror());
} else {
handleDriveCommand(target);
}
binding.trackingOverlay.postInvalidate();
}

Expand Down
4 changes: 4 additions & 0 deletions android/robot/src/main/java/org/openbot/vehicle/Control.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ public float getLeft() {
public float getRight() {
return right;
}

public Control mirror() {
return new Control(this.right, this.left);
}
}
19 changes: 19 additions & 0 deletions android/robot/src/main/res/drawable/ic_mirror_control.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="@color/openBotBlue">
<group
android:scaleX="-1"
android:translateX="12"
android:translateY="12">
<group
android:translateX="-12"
android:translateY="-12">
<path
android:pathData="M15 21h2v-2h-2v2zM19 9h2L21 7h-2v2zM3 5v14c0 1.1 0.9 2 2 2h4v-2L5 19L5 5h4L9 3L5 3c-1.1 0 -2 0.9 -2 2zM19 3v2h2c0 -1.1 -0.9 -2 -2 -2zM11 23h2L13 1h-2v22zM19 17h2v-2h-2v2zM15 5h2L17 3h-2v2zM19 13h2v-2h-2v2zM19 21c1.1 0 2 -0.9 2 -2h-2v2z"
android:fillColor="#FF000000" />
</group>
</group>
</vector>
10 changes: 10 additions & 0 deletions android/robot/src/main/res/drawable/ic_mirror_control_off.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:pathData="M15,21h2v-2h-2v2zM19,9h2L21,7h-2v2zM3,5v14c0,1.1 0.9,2 2,2h4v-2L5,19L5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM11,23h2L13,1h-2v22zM19,17h2v-2h-2v2zM15,5h2L17,3h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2z"
android:fillColor="#FF000000"/>
</vector>
6 changes: 6 additions & 0 deletions android/robot/src/main/res/drawable/mirror_control.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:drawable="@drawable/ic_mirror_control_off" android:state_checked="false" />
<item android:drawable="@drawable/ic_mirror_control" android:state_checked="true" />
<item android:drawable="@drawable/ic_mirror_control_off" />
</selector>
18 changes: 14 additions & 4 deletions android/robot/src/main/res/layout/fragment_object_nav.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
android:id="@+id/usbToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:button="@drawable/usb_toggle"
app:layout_constraintBottom_toBottomOf="@+id/camera_toggle"
app:layout_constraintEnd_toStartOf="@+id/camera_toggle"
Expand All @@ -75,7 +75,7 @@
android:id="@+id/bleToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginEnd="8dp"
android:button="@drawable/ble_toggle"
app:layout_constraintBottom_toBottomOf="@+id/camera_toggle"
app:layout_constraintEnd_toStartOf="@+id/camera_toggle"
Expand All @@ -85,15 +85,25 @@
android:id="@+id/camera_toggle"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="8dp"
android:background="@android:color/transparent"
android:scaleType="center"
android:src="@drawable/ic_cameraswitch"
android:text="@string/camera_facing_back"
app:layout_constraintTop_toTopOf="@+id/autoLinearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/mirrorControl"
app:tint="@color/openBotBlue" />

<CheckBox
android:id="@+id/mirrorControl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:button="@drawable/mirror_control"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="@+id/autoLinearLayout"
app:layout_constraintEnd_toEndOf="parent" />

<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
Expand Down
Loading