Skip to content

Commit

Permalink
Code refactoring and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
esimov committed Apr 24, 2024
1 parent d8bf889 commit bdceadb
Show file tree
Hide file tree
Showing 9 changed files with 446 additions and 405 deletions.
6 changes: 3 additions & 3 deletions carver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, err

dets := []pigo.Detection{}

if p.PigoFaceDetector != nil && p.FaceDetect && detAttempts < maxFaceDetAttempts {
if p.FaceDetector != nil && p.FaceDetect && detAttempts < maxFaceDetAttempts {
var ratio float64

if width < height {
Expand Down Expand Up @@ -108,10 +108,10 @@ func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, err
}
// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
dets = p.PigoFaceDetector.RunCascade(cParams, p.FaceAngle)
dets = p.FaceDetector.RunCascade(cParams, p.FaceAngle)

// Calculate the intersection over union (IoU) of two clusters.
dets = p.PigoFaceDetector.ClusterDetections(dets, 0.1)
dets = p.FaceDetector.ClusterDetections(dets, 0.1)

if len(dets) == 0 {
// Retry detecting faces for a certain amount of time.
Expand Down
18 changes: 9 additions & 9 deletions carver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func TestCarver_ShouldDetectFace(t *testing.T) {
}
defer f.Close()

p.PigoFaceDetector, err = p.PigoFaceDetector.Unpack(cascadeFile)
p.FaceDetector, err = p.FaceDetector.Unpack(cascadeFile)
if err != nil {
t.Fatalf("error unpacking the cascade file: %v", err)
}
Expand Down Expand Up @@ -282,10 +282,10 @@ func TestCarver_ShouldDetectFace(t *testing.T) {

// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
faces := p.PigoFaceDetector.RunCascade(cParams, p.FaceAngle)
faces := p.FaceDetector.RunCascade(cParams, p.FaceAngle)

// Calculate the intersection over union (IoU) of two clusters.
faces = p.PigoFaceDetector.ClusterDetections(faces, 0.2)
faces = p.FaceDetector.ClusterDetections(faces, 0.2)

assert.Equal(1, len(faces))
}
Expand All @@ -301,7 +301,7 @@ func TestCarver_ShouldNotRemoveFaceZone(t *testing.T) {
}
defer f.Close()

p.PigoFaceDetector, err = p.PigoFaceDetector.Unpack(cascadeFile)
p.FaceDetector, err = p.FaceDetector.Unpack(cascadeFile)
if err != nil {
t.Fatalf("error unpacking the cascade file: %v", err)
}
Expand Down Expand Up @@ -336,10 +336,10 @@ func TestCarver_ShouldNotRemoveFaceZone(t *testing.T) {

// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
faces := p.PigoFaceDetector.RunCascade(cParams, p.FaceAngle)
faces := p.FaceDetector.RunCascade(cParams, p.FaceAngle)

// Calculate the intersection over union (IoU) of two clusters.
faces = p.PigoFaceDetector.ClusterDetections(faces, 0.2)
faces = p.FaceDetector.ClusterDetections(faces, 0.2)

// Range over all the detected faces and draw a white rectangle mask over each of them.
// We need to trick the sobel detector to consider them as important image parts.
Expand Down Expand Up @@ -378,7 +378,7 @@ func TestCarver_ShouldNotResizeWithFaceDistorsion(t *testing.T) {
}
defer f.Close()

p.PigoFaceDetector, err = p.PigoFaceDetector.Unpack(cascadeFile)
p.FaceDetector, err = p.FaceDetector.Unpack(cascadeFile)
if err != nil {
t.Fatalf("error unpacking the cascade file: %v", err)
}
Expand Down Expand Up @@ -409,10 +409,10 @@ func TestCarver_ShouldNotResizeWithFaceDistorsion(t *testing.T) {

// Run the classifier over the obtained leaf nodes and return the detection results.
// The result contains quadruplets representing the row, column, scale and detection score.
faces := p.PigoFaceDetector.RunCascade(cParams, p.FaceAngle)
faces := p.FaceDetector.RunCascade(cParams, p.FaceAngle)

// Calculate the intersection over union (IoU) of two clusters.
faces = p.PigoFaceDetector.ClusterDetections(faces, 0.2)
faces = p.FaceDetector.ClusterDetections(faces, 0.2)

for _, face := range faces {
if p.NewHeight < face.Scale {
Expand Down
Loading

0 comments on commit bdceadb

Please sign in to comment.