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

Optional face detection with gocv #35

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

Conversation

svkoskin
Copy link

I restored face detection features using another set of bindings for OpenCV, called gocv. It should still be possible to build smartcrop without having OpenCV installed. I have no particular interest in maintaining or supporting a fork, so if there is any chance for this to get merged, I'd appreciate it 😸

@muesli
Copy link
Owner

muesli commented Apr 18, 2018

This looks fairly promising, thanks! Will try it out, see how it goes and provide feedback here.

smartcrop.go Outdated
@@ -54,7 +54,7 @@ var (

const (
detailWeight = 0.2
skinBias = 0.01
skinBias = 0.9
Copy link
Owner

Choose a reason for hiding this comment

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

This probably isn't the best idea, as it changes the current behavior (without face detection). We should introduce a separate bias here, maybe.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, that's a valid concern. I ended up with this since now the score function does not know whether skin or face was detected. Would it be useful to be able to override these values, or are the same values useful for all use cases? If it is useful some kind of API for providing overrides could solve this problem.

Copy link
Owner

Choose a reason for hiding this comment

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

Maybe each Detector should contain & provide its own bias, which the user could then manipulate, e.g. by manually initializing a Detector.

gocv/face.go Outdated
height := face.Dy()

if d.DebugMode == true {
log.Printf("Face: x: %d y: %d w: %d h: %d\n", x, y, width, height)
Copy link
Owner

Choose a reason for hiding this comment

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

We should think about injecting the Logger here.

Copy link
Author

Choose a reason for hiding this comment

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

Yes that seems smart

smartcrop.go Outdated
return &smartcropAnalyzer{Resizer: resizer, logger: logger}

// Set default detectors here
detectors := []Detector{
Copy link
Owner

Choose a reason for hiding this comment

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

This is a nice idea, but requires a bit more restructuring, I think. For example, if you initialize smartcrop with only the FaceDetector, the debug output looks a bit funky.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, when this goes public the interface needs to be a bit stricter. I witnessed that by unintentionally changing the order of detectors, and got my detected face overwritten by the artist formerly known as edgeDetect. I'll try to figure something out.

@svkoskin
Copy link
Author

Thanks for your feedback, I'll try to resolve the issues.

@muesli
Copy link
Owner

muesli commented May 9, 2018

@svkoskin If there's anything I can do to help, let me know!

This reverts commit a3a40ff.
smartcropAnalyzer will soon have the configuraed detectors as its members, and a method can use them without having to pass them as parameters
EdgeDetector's results are handled a bit differently in the scoring phase, so introduce a new interface and a field for it
Revert skin bias to the value in master branch that users are depending on. This reverts commit e15f810.
@svkoskin
Copy link
Author

svkoskin commented Jun 8, 2018

@muesli As usual, I have had a bit limited time for actually implementing the fixes. Detaching bias seemed to require quite a big refactoring, but I added providing bias and weights to Detector's responsibilities. Making detections [][]uint8-based made it a bit easier to detach things from each other. Nevertheless, without attaching the face detector this should now return same crops as the version in master.

@muesli
Copy link
Owner

muesli commented Sep 9, 2018

I have not forgotten about this! Just need to find some time to fix up the CI and integrate all your changes - sorry it's been taking so long!

@Nazdroth
Copy link

Any update on this?

@muesli
Copy link
Owner

muesli commented Apr 1, 2020

@Nazdroth I'm currently attempting to migrate the CI stuff over to GitHub actions for a bunch of my projects - this among them. This should hopefully make it easier to fix up the CI with the required dependencies. As @svkoskin mentioned themselves, this probably still requires a bit of work inside smartcrop to decouple the bias and weighting process.

Other than that still a fantastic PR, I just need to find the time to tie up the loose ends. Actually looking forward to that, though!

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

Successfully merging this pull request may close these issues.

None yet

3 participants