Skip to content
Open
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 @@ -75,6 +75,10 @@ class Camera2BasicFragment : Fragment(), FragmentCompat.OnRequestPermissionsResu
private var classifier: ImageClassifier? = null
private var layoutBottom: ViewGroup? = null
private var radiogroup: RadioGroup? = null
private var switchCamera: RadioGroup? = null
private var backCamera: Boolean? = true
private var cameraWidth: Int? = null
private var cameraHeight: Int? = null
/**
* [TextureView.SurfaceTextureListener] handles several lifecycle events on a [ ].
*/
Expand All @@ -85,6 +89,8 @@ class Camera2BasicFragment : Fragment(), FragmentCompat.OnRequestPermissionsResu
width: Int,
height: Int
) {
cameraWidth = width
cameraHeight = height
openCamera(width, height)
}

Expand Down Expand Up @@ -273,6 +279,7 @@ class Camera2BasicFragment : Fragment(), FragmentCompat.OnRequestPermissionsResu
drawView = view.findViewById(R.id.drawview)
layoutBottom = view.findViewById(R.id.layout_bottom)
radiogroup = view.findViewById(R.id.radiogroup);
switchCamera = view.findViewById(R.id.radiogroup_switch_camera);

radiogroup!!.setOnCheckedChangeListener { group, checkedId ->
if(checkedId==R.id.radio_cpu){
Expand All @@ -281,6 +288,18 @@ class Camera2BasicFragment : Fragment(), FragmentCompat.OnRequestPermissionsResu
startBackgroundThread(Runnable { classifier!!.initTflite(true) })
}
}

switchCamera!!.setOnCheckedChangeListener { group, checkedId ->
if(checkedId==R.id.radio_back){
backCamera = true
closeCamera()
openCamera(cameraWidth!!, cameraHeight!!)
} else {
backCamera = false
closeCamera()
openCamera(cameraWidth!!, cameraHeight!!)
}
}
}

/**
Expand Down Expand Up @@ -351,7 +370,11 @@ class Camera2BasicFragment : Fragment(), FragmentCompat.OnRequestPermissionsResu

// We don't use a front facing camera in this sample.
val facing = characteristics.get(CameraCharacteristics.LENS_FACING)
if (facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
if(backCamera!! && facing != null && facing == CameraCharacteristics.LENS_FACING_FRONT) {
continue
}

if(!backCamera!! && facing != null && facing == CameraCharacteristics.LENS_FACING_BACK){
continue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,51 @@
android:textStyle="bold"
tools:text="asd"/>

<RadioGroup
android:id="@+id/radiogroup"
<android.support.constraint.ConstraintLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton android:id="@+id/radio_gpu"
android:textColor="@color/black"
android:layout_height="wrap_content">
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="GPU"/>
<RadioButton android:id="@+id/radio_cpu"
android:textColor="@color/black"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf = "parent"
app:layout_constraintStart_toStartOf="parent">
<RadioButton android:id="@+id/radio_gpu"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="GPU"/>
<RadioButton android:id="@+id/radio_cpu"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CPU"/>
</RadioGroup>

<RadioGroup
android:id="@+id/radiogroup_switch_camera"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CPU"/>
</RadioGroup>
android:orientation="horizontal"
android:layout_marginStart="20dp"
app:layout_constraintStart_toEndOf="@+id/radiogroup"
app:layout_constraintBottom_toBottomOf="parent">
<RadioButton android:id="@+id/radio_back"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Back"/>
<RadioButton android:id="@+id/radio_front"
android:textColor="@color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Front"/>
</RadioGroup>
</android.support.constraint.ConstraintLayout>
</FrameLayout>