-
-
Notifications
You must be signed in to change notification settings - Fork 386
Expand file tree
/
Copy pathcarver_benchmark_test.go
More file actions
39 lines (31 loc) · 697 Bytes
/
carver_benchmark_test.go
File metadata and controls
39 lines (31 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package caire
import (
"image"
"os"
"path/filepath"
"testing"
)
func Benchmark_Carver(b *testing.B) {
sampleImg := filepath.Join("./testdata", "sample.jpg")
f, err := os.Open(sampleImg)
if err != nil {
b.Fatalf("could not load sample image: %v", err)
}
defer f.Close()
src, _, err := image.Decode(f)
if err != nil {
b.Fatalf("error decoding image: %v", err)
}
b.ResetTimer()
img := imgToNRGBA(src)
width, height := img.Bounds().Max.X, img.Bounds().Max.Y
c := NewCarver(width, height)
for i := 0; i < b.N; i++ {
_, err := c.ComputeSeams(p, img)
if err != nil {
b.FailNow()
}
seams := c.FindLowestEnergySeams(p)
img = c.RemoveSeam(img, seams, p.Debug)
}
}