Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7560bd3
Fixed divide by zero error.
dpapworth Feb 26, 2019
b38d31e
Updated crop algorithm to better match JavaScript version.
dpapworth Feb 27, 2019
a451fd3
Updated down sampling step to match JS.
dpapworth Feb 27, 2019
4ebeba0
Updated edge detection to match JavaScript.
dpapworth Feb 27, 2019
065a405
Update skin detection to match JavaScript.
dpapworth Feb 27, 2019
5741d9f
Updated saturation detection to match JavaScript.
dpapworth Feb 27, 2019
f95e0a1
Fixed scoring and rule of thirds.
dpapworth Feb 27, 2019
b9d4b42
Fixed support for aspect ratios and prescaling.
dpapworth Feb 27, 2019
fdbcc22
Updated SmartCrop to be stateless.
dpapworth Feb 28, 2019
b867b16
Separated scoring from crop calculations.
dpapworth Feb 28, 2019
2731aac
Output multiple aspect ratios.
dpapworth Feb 28, 2019
d5e808a
Added support for boost areas (to support face detection).
dpapworth Feb 28, 2019
9cd37c6
Added support for face detection.
dpapworth Feb 28, 2019
5dabb41
Improved face detection.
dpapworth Mar 1, 2019
bf13c55
Replace Haar cascades with DNN.
dpapworth Mar 1, 2019
d1599f3
Moved face detection to separate class.
dpapworth Mar 4, 2019
4ce76a0
Added HaarCascadeFaceDetector.
dpapworth Mar 4, 2019
d33873c
Fixed boost calculation.
dpapworth Mar 4, 2019
881c8a2
Updated HaarCascadeFaceDetector to use bytedeco classes.
dpapworth Mar 4, 2019
181b22a
Update test output and move debug to test.
dpapworth Mar 5, 2019
0466955
Changed prescale to double to generate correct output size.
dpapworth Mar 5, 2019
487c63d
Updated debug and result images.
dpapworth Mar 5, 2019
210e30e
Remove unused debug image from CropResult.
dpapworth Mar 5, 2019
9b8be33
Removed unused models for Haar Cascade.
dpapworth Mar 5, 2019
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
</properties>

<dependencies>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv-platform</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/github/quadflask/smartcrop/Boost.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.quadflask.smartcrop;

public class Boost {
public int x;
public int y;
public int width;
public int height;
public float weight;
}
11 changes: 3 additions & 8 deletions src/main/java/com/github/quadflask/smartcrop/CropResult.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.github.quadflask.smartcrop;

import java.awt.image.BufferedImage;
import java.util.List;

public class CropResult {
public final Crop topCrop;
public final List<Crop> crops;
public final BufferedImage debugImage;
public final BufferedImage resultImage;

private CropResult(Crop topCrop, List<Crop> crops, BufferedImage debugImage, BufferedImage resultImage) {
private CropResult(Crop topCrop, List<Crop> crops) {
this.topCrop = topCrop;
this.crops = crops;
this.debugImage = debugImage;
this.resultImage = resultImage;
}

static CropResult newInstance(Crop topCrop, List<Crop> crops, BufferedImage debugImage, BufferedImage resultImage) {
return new CropResult(topCrop, crops, debugImage, resultImage);
static CropResult newInstance(Crop topCrop, List<Crop> crops) {
return new CropResult(topCrop, crops);
}
}
90 changes: 74 additions & 16 deletions src/main/java/com/github/quadflask/smartcrop/Options.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.github.quadflask.smartcrop;

import java.awt.image.BufferedImage;
import java.util.Collections;
import java.util.List;

/**
* Created by flask on 2015. 10. 30..
*/
public class Options {
public static final Options DEFAULT = new Options();

private int cropWidth = 100;
private int cropHeight = 100;
private float detailWeight = .2f;
private float[] skinColor = {0.7f, 0.57f, 0.44f};
private float skinBias = .01f;
private float width = 0.0f;
private float height = 0.0f;
private float aspect = 0.0f;
private int cropWidth = 0;
private int cropHeight = 0;
private float detailWeight = 0.2f;
private float[] skinColor = {0.78f, 0.57f, 0.44f};
private float skinBias = 0.01f;
private float skinBrightnessMin = 0.2f;
private float skinBrightnessMax = 1.0f;
private float skinThreshold = 0.8f;
Expand All @@ -21,18 +23,47 @@ public class Options {
private float saturationBrightnessMax = 0.9f;
private float saturationThreshold = 0.4f;
private float saturationBias = 0.2f;
private float saturationWeight = 0.3f;
private float saturationWeight = 0.1f;
// step * minscale rounded down to the next power of two should be good
private int scoreDownSample = 8;
// private int step = 8;
private int step = 8;
private float scaleStep = 0.1f;
private float minScale = 0.8f;
private float maxScale = 1.0f;
private float edgeRadius = 0.4f;
private float edgeWeight = -20f;
private float outsideImportance = -.5f;
private boolean ruleOfThirds = false;
private int bufferedBitmapType = BufferedImage.TYPE_INT_ARGB;
private List<Boost> boost = Collections.emptyList();
private float boostWeight = 100.0f;
private boolean ruleOfThirds = true;
private boolean prescale = false;

public float getWidth() {
return width;
}

public Options width(float width) {
this.width = width;
return this;
}

public float getHeight() {
return height;
}

public Options height(float height) {
this.height = height;
return this;
}

public float getAspect() {
return aspect;
}

public Options aspect(float aspect) {
this.aspect = aspect;
return this;
}

public int getCropWidth() {
return cropWidth;
Expand Down Expand Up @@ -169,6 +200,15 @@ public Options scoreDownSample(int scoreDownSample) {
return this;
}

public int getStep() {
return step;
}

public Options step(int step) {
this.step = step;
return this;
}

public float getScaleStep() {
return scaleStep;
}
Expand Down Expand Up @@ -223,6 +263,24 @@ public Options outsideImportance(float outsideImportance) {
return this;
}

public Options boost(List<Boost> boost) {
this.boost = boost;
return this;
}

public List<Boost> getBoost() {
return boost;
}

public Options boostWeight(float boostWeight) {
this.boostWeight = boostWeight;
return this;
}

public float getBoostWeight() {
return boostWeight;
}

public boolean isRuleOfThirds() {
return ruleOfThirds;
}
Expand All @@ -232,12 +290,12 @@ public Options ruleOfThirds(boolean ruleOfThirds) {
return this;
}

public int getBufferedBitmapType() {
return bufferedBitmapType;
public boolean isPrescale() {
return prescale;
}

public Options bufferedBitmapType(int bufferedBitmapType) {
this.bufferedBitmapType = bufferedBitmapType;
public Options prescale(boolean prescale) {
this.prescale = prescale;
return this;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/github/quadflask/smartcrop/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class Score {
public float detail;
public float saturation;
public float skin;
public float boost;
public float total;
}
Loading