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

add opencv #3

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

add opencv #3

wants to merge 11 commits into from

Conversation

yinjun622
Copy link

No description provided.

int[] od = o.data;
for (int i = 0; i < o.width; i++) {
// od[i] = (0 << 24) | (od[i] & 0xffffff);
od[i] &= 0xffffff00;

Choose a reason for hiding this comment

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

Isn't this going to zero the saturation score? Surely you want to zero the alpha channel (used for boost)?

Choose a reason for hiding this comment

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

Also, shouldn't you be applying this to the whole image, and not just the first row?

Copy link
Author

Choose a reason for hiding this comment

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

Also, shouldn't you be applying this to the whole image, and not just the first row?

yes, you are right. I fixed that.

this.height = height;
this.data = new int[width * height];
for (int i = 0; i < this.data.length; i++)
data[i] = 0xff000000;

Choose a reason for hiding this comment

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

FYI, this is going to set the alpha channel/boost score to 255 for the whole image by default, so you might want to change this to zero.


CropResult result = CropResult.newInstance(topCrop, crops, output, createCrop(input, topCrop));
if (options.isDebug()) {
Graphics graphics = output.getGraphics();

Choose a reason for hiding this comment

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

As you are updating the alpha channel due to the boost calculation, you might want to drop the alpha channel from debug output (otherwise all pixels where the alpha channel is 0 won't be visible). I use the following to create a new BufferedImage without the alpha channel.

BufferedImage debugOutput = new BufferedImage(output.getWidth(), output.getHeight(), BufferedImage.TYPE_INT_RGB);
// Drop alpha channel from debug output
BandCombineOp filterAlpha = new BandCombineOp(
    // RGBA -> RGB
    new float[][] {
        {1.0f, 0.0f, 0.0f, 0.0f},
        {0.0f, 1.0f, 0.0f, 0.0f},
        {0.0f, 0.0f, 1.0f, 0.0f}
    }, null
);
filterAlpha.filter(output.getRaster(), debugOutput.getRaster());

public Crop[] detectFace(String imagePath) {
Mat image = Imgcodecs.imread(imagePath);
MatOfRect faceDetections = new MatOfRect();
cascadeClassifier.detectMultiScale(image, faceDetections);

Choose a reason for hiding this comment

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

Doesn't this classifier use a grey scale image?

@dpapworth
Copy link

Coincidentally I have also been working on this code recently to incorporate face detection using different OpenCV algorithms (Haar Cascade and DNN). I've also updated the code to closer match the current smartcrop.js algorithm. I will submit this as a PR when I get the chance.

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.

2 participants