I have a frameLayout in xml:
<FrameLayout
android:layout_width="150px"
android:layout_height="200px"
android:id="@+id/preview">
</FrameLayout>
This preview is for displaying camera view:
mPreview = new CameraSurfacePreview(MainActivity.this, cameraObj,...);
preview.addView(mPreview2);
....
It successfully displaying face from the front camera. And I have the face rectangle x and y coordinates. How can I display a bounding box of face on the frameLayout?
Thank you.
well, you could use a ShapeDrawable, and set it's layout parameters to be the size and location you need, and add it to the FrameLayout along with your CameraSurfacePreview.
It's not all the difficult. First create a ShapeDrawable with the properties you want. Then set it as the background of a standard View object, and add the view with the layout parameters to size it how you want. So if you want the
ShapeDrawable sd = new ShapeDrawable(new RectShape());
sd.getPaint().setColor(0xFFFFFFFF);
sd.getPaint().setStyle(Paint.Style.STROKE);
sd.getPaint().setStrokeWidth(1);
View shapeView = new View(context);
shapeView.setBackground(sd);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(100, 100);
params.setMargins(left, top, 0, 0);
frameLayout.addView(shapeView, params);
In this particular case, i've made it a 100x100 view, so the shape will auto size to the view. and i've set it up so that it's offset from the top corner by the values left and top.
There's lots of ways to do this, but this seems the simplest. Of course you could do all this in XML too. There's lots of tutorials out there on how to do this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With