Skip to content

added callbacks for face detection result in activity #13

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MiRobotic
Copy link

while using face detection, developer may need to do something when face detected in camera. hence i added callbacks for face detection process in main activity. if you find this helpful then you can accept this pull request.

thanks.

Copy link
Owner

@husaynhakeem husaynhakeem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the pull request! Appreciate the help.
A few changes and it'll be good to merge.

@@ -46,6 +47,7 @@ class FaceBoundsOverlay @JvmOverloads constructor(ctx: Context, attrs: Attribute
canvas.drawId(faceBounds.id.toString(), faceBounds.box.center())
canvas.drawBounds(faceBounds.box)
}
Log.e("faces", "draw ${facesBounds.size}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a log message here makes sense, but instead of an error log message, it should be an info or debug message, so Log.d or Log.i. Also, could you add a static log tag to the class, something like:

companion object {
    private const val TAG = "FaceBoundsOverlay"
}

Then use it for the logging.

Log.d(TAG, "Drawing ${facesBounds.size}")

mainExecutor.execute { faceBoundsOverlay.updateFaces(faceBounds) }
mainExecutor.execute {
faceBoundsOverlay.updateFaces(faceBounds)
onFaceDetectionResultListener?.onSuccess(faceBounds)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!


override fun onSuccess(faceBounds: List<FaceBounds>) {
super.onSuccess(faceBounds)
Log.e(TAG,"total faces ${faceBounds.size}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't an error, it shouldn't use Log.e, instead an info or debug log should be used.

Also, please make sure to format the file after you're done (a space is missing before the log message).

super.onSuccess(faceBounds)
Log.e(TAG,"total faces ${faceBounds.size}")
for (face in faceBounds) {
Log.d(TAG, "face ${face.id} ${face.box.width()} ${face.box.height()}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One little change here, could you format the log message to be

face ${face.id} [${face.box.width()}, ${face.box.height()}]

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val lensFacing =
savedInstanceState?.getSerializable(KEY_LENS_FACING) as Facing? ?: Facing.BACK
val lensFacing = Facing.FRONT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lensFacing is saved in onSaveInstanceState(). Please revert setting it here to use the saved instance state.

viewfinder.facing = lensFacing
viewfinder.rotation = 180f
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you rotating the viewfinder?

viewfinder.addFrameProcessor {
faceDetector.process(
Frame(
data = it.data,
rotation = it.rotation,
size = Size(it.size.width, it.size.height),
format = it.format,
lensFacing = if (viewfinder.facing == Facing.BACK) LensFacing.BACK else LensFacing.FRONT
lensFacing = LensFacing.FRONT
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you set the value of the frame's lensFacing parameter to the variable lensFacing?

)
)
}

toggleCameraButton.setOnClickListener {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert removing these lines.

}

//111.375 338.5481
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line and the one below it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants