2021-05-31 15:40:52 +02:00
|
|
|
package entity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-09-05 11:05:33 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/crop"
|
2021-09-03 16:14:09 +02:00
|
|
|
|
2021-05-31 15:40:52 +02:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-09-03 16:14:09 +02:00
|
|
|
var cropArea1 = crop.Area{Name: "face", X: 0.308333, Y: 0.206944, W: 0.355556, H: 0.355556}
|
2021-09-20 22:19:54 +02:00
|
|
|
var cropArea2 = crop.Area{Name: "face", X: 0.208313, Y: 0.156914, W: 0.655556, H: 0.655556}
|
2021-09-03 16:14:09 +02:00
|
|
|
var cropArea3 = crop.Area{Name: "face", X: 0.998133, Y: 0.816944, W: 0.0001, H: 0.0001}
|
|
|
|
var cropArea4 = crop.Area{Name: "face", X: 0.298133, Y: 0.216944, W: 0.255556, H: 0.155556}
|
|
|
|
|
2021-05-31 15:40:52 +02:00
|
|
|
func TestMarkers_Contains(t *testing.T) {
|
2021-09-06 05:13:53 +02:00
|
|
|
t.Run("Examples", func(t *testing.T) {
|
2021-09-20 16:17:10 +02:00
|
|
|
m1 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea1, "lt9k3pw1wowuy1c1", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m2 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea2, "lt9k3pw1wowuy1c2", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m3 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea3, "lt9k3pw1wowuy1c3", SrcImage, MarkerFace, 100, 65)
|
2021-09-06 05:13:53 +02:00
|
|
|
|
2021-09-20 22:19:54 +02:00
|
|
|
assert.Equal(t, 29, m1.OverlapPercent(m2))
|
|
|
|
assert.Equal(t, 100, m2.OverlapPercent(m1))
|
2021-09-06 05:13:53 +02:00
|
|
|
|
2021-09-20 22:19:54 +02:00
|
|
|
m := Markers{m2}
|
|
|
|
|
|
|
|
assert.True(t, m.Contains(m1))
|
2021-09-06 05:13:53 +02:00
|
|
|
assert.False(t, m.Contains(m3))
|
|
|
|
})
|
|
|
|
t.Run("Conflicting", func(t *testing.T) {
|
2021-09-22 19:33:41 +02:00
|
|
|
file := File{FileUID: "", FileHash: "cca7c46a4d39e933c30805e546028fe3eab361b5"}
|
2021-09-06 05:13:53 +02:00
|
|
|
|
|
|
|
markers := Markers{
|
2021-09-20 16:17:10 +02:00
|
|
|
*NewMarker(file, crop.Area{Name: "subj-1", X: 0.549479, Y: 0.179688, W: 0.393229, H: 0.294922}, "jqyzmgbquh1msz6o", SrcImage, MarkerFace, 100, 65),
|
|
|
|
*NewMarker(file, crop.Area{Name: "subj-2", X: 0.0833333, Y: 0.321289, W: 0.476562, H: 0.357422}, "jqyzml91cf2yyfi7", SrcImage, MarkerFace, 100, 65),
|
2021-09-06 05:13:53 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 16:17:10 +02:00
|
|
|
conflicting := *NewMarker(file, crop.Area{Name: "subj-2", X: 0.190104, Y: 0.40918, W: 0.31901, H: 0.239258}, "jqyzml91cf2yyfi7", SrcImage, MarkerFace, 100, 65)
|
2021-09-06 05:13:53 +02:00
|
|
|
|
|
|
|
assert.True(t, markers.Contains(conflicting))
|
|
|
|
})
|
|
|
|
t.Run("SameFace", func(t *testing.T) {
|
|
|
|
file := File{FileHash: "a6c46e43b83fc02309b1c49e1ed7273f1f414610"}
|
|
|
|
|
|
|
|
markers := Markers{
|
2021-09-20 16:17:10 +02:00
|
|
|
*NewMarker(file, crop.Area{Name: "subj-1", X: 0.388021, Y: 0.365234, W: 0.179688, H: 0.134766}, "jqyzmgbquh1msz6o", SrcImage, MarkerFace, 100, 65),
|
2021-09-06 05:13:53 +02:00
|
|
|
}
|
|
|
|
|
2021-09-20 16:17:10 +02:00
|
|
|
conflicting := *NewMarker(file, crop.Area{Name: "subj-1", X: 0.34375, Y: 0.291992, W: 0.266927, H: 0.200195}, "jqyzmgbquh1msz6o", SrcImage, MarkerFace, 100, 65)
|
2021-09-06 05:13:53 +02:00
|
|
|
|
|
|
|
assert.True(t, markers.Contains(conflicting))
|
|
|
|
})
|
|
|
|
t.Run("NoFace", func(t *testing.T) {
|
2021-09-22 19:33:41 +02:00
|
|
|
file := File{FileUID: "fqzuh672i9btq6gu", FileHash: "243cdbe99b865607f98a951e748d528bc22f3143"}
|
2021-09-06 05:13:53 +02:00
|
|
|
|
|
|
|
markers := Markers{
|
2021-09-20 16:17:10 +02:00
|
|
|
*NewMarker(file, crop.Area{Name: "no-face", X: 0.322656, Y: 0.3, W: 0.180469, H: 0.240625}, "jqyzmgbquh1msz6o", SrcImage, MarkerFace, 100, 65),
|
2021-09-06 05:13:53 +02:00
|
|
|
}
|
2021-05-31 15:40:52 +02:00
|
|
|
|
2021-09-20 16:17:10 +02:00
|
|
|
conflicting := *NewMarker(file, crop.Area{Name: "face", X: 0.325, Y: 0.0510417, W: 0.136719, H: 0.182292}, "jqyzmgbquh1msz6o", SrcImage, MarkerFace, 100, 65)
|
2021-05-31 15:40:52 +02:00
|
|
|
|
2021-09-06 05:13:53 +02:00
|
|
|
assert.False(t, markers.Contains(conflicting))
|
|
|
|
})
|
2021-05-31 15:40:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-23 23:46:17 +02:00
|
|
|
func TestMarkers_DetectedFaceCount(t *testing.T) {
|
2021-09-20 16:17:10 +02:00
|
|
|
m1 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea1, "lt9k3pw1wowuy1c1", SrcImage, MarkerFace, 100, 65)
|
2021-09-23 23:46:17 +02:00
|
|
|
m2 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea4, "lt9k3pw1wowuy1c2", SrcManual, MarkerFace, 100, 65)
|
|
|
|
m3 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea3, "lt9k3pw1wowuy1c3", SrcManual, MarkerFace, 100, 65)
|
2021-05-31 15:40:52 +02:00
|
|
|
m3.MarkerInvalid = true
|
|
|
|
|
|
|
|
m := Markers{m1, m2, m3}
|
|
|
|
|
2021-09-23 23:46:17 +02:00
|
|
|
assert.Equal(t, 1, m.DetectedFaceCount())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMarkers_ValidFaceCount(t *testing.T) {
|
|
|
|
m1 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea1, "lt9k3pw1wowuy1c1", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m2 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea4, "lt9k3pw1wowuy1c2", SrcManual, MarkerFace, 100, 65)
|
|
|
|
m3 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea3, "lt9k3pw1wowuy1c3", SrcManual, MarkerFace, 100, 65)
|
|
|
|
m3.MarkerInvalid = true
|
|
|
|
|
|
|
|
m := Markers{m1, m2, m3}
|
|
|
|
|
|
|
|
assert.Equal(t, 2, m.ValidFaceCount())
|
2021-05-31 15:40:52 +02:00
|
|
|
}
|
2021-09-02 14:23:40 +02:00
|
|
|
|
|
|
|
func TestMarkers_SubjectNames(t *testing.T) {
|
|
|
|
m1 := MarkerFixtures.Get("1000003-3")
|
|
|
|
m2 := MarkerFixtures.Get("1000003-4")
|
|
|
|
m3 := MarkerFixtures.Get("1000003-5")
|
|
|
|
|
|
|
|
m1.MarkerInvalid = true
|
|
|
|
|
|
|
|
m := Markers{m1, m2, m3}
|
|
|
|
|
|
|
|
assert.Equal(t, []string{"Jens Mander", "Corn McCornface"}, m.SubjectNames())
|
|
|
|
}
|
2021-09-23 23:46:17 +02:00
|
|
|
|
|
|
|
func TestMarkers_Labels(t *testing.T) {
|
|
|
|
t.Run("None", func(t *testing.T) {
|
|
|
|
m := Markers{}
|
|
|
|
|
|
|
|
result := m.Labels()
|
|
|
|
|
|
|
|
if len(result) > 0 {
|
|
|
|
t.Fatalf("unexpected result: %#v", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("One", func(t *testing.T) {
|
|
|
|
m1 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea1, "lt9k3pw1wowuy1c1", SrcImage, MarkerFace, 100, 12)
|
|
|
|
m2 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea4, "lt9k3pw1wowuy1c2", SrcImage, MarkerFace, 100, 300)
|
|
|
|
|
|
|
|
m2.MarkerInvalid = true
|
|
|
|
|
|
|
|
m := Markers{m1, m2}
|
|
|
|
|
|
|
|
result := m.Labels()
|
|
|
|
|
|
|
|
if len(result) == 1 {
|
|
|
|
t.Logf("labels: %#v", result)
|
|
|
|
|
|
|
|
assert.Equal(t, "portrait", result[0].Name)
|
|
|
|
assert.Equal(t, SrcImage, result[0].Source)
|
|
|
|
assert.Equal(t, 45, result[0].Uncertainty)
|
|
|
|
assert.Equal(t, 0, result[0].Priority)
|
|
|
|
assert.Len(t, result[0].Categories, 1)
|
|
|
|
|
|
|
|
if len(result[0].Categories) == 1 {
|
|
|
|
assert.Equal(t, "people", result[0].Categories[0])
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
t.Fatalf("unexpected result: %#v", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
t.Run("Many", func(t *testing.T) {
|
|
|
|
m1 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea1, "lt9k3pw1wowuy1c1", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m2 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea4, "lt9k3pw1wowuy1c2", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m3 := *NewMarker(FileFixtures.Get("exampleFileName.jpg"), cropArea3, "lt9k3pw1wowuy1c3", SrcImage, MarkerFace, 100, 65)
|
|
|
|
m3.MarkerInvalid = true
|
|
|
|
|
|
|
|
m := Markers{m1, m2, m3}
|
|
|
|
|
|
|
|
result := m.Labels()
|
|
|
|
|
|
|
|
if len(result) == 1 {
|
|
|
|
t.Logf("labels: %#v", result)
|
|
|
|
|
|
|
|
assert.Equal(t, "people", result[0].Name)
|
|
|
|
assert.Equal(t, SrcImage, result[0].Source)
|
|
|
|
assert.Equal(t, 25, result[0].Uncertainty)
|
|
|
|
assert.Equal(t, 0, result[0].Priority)
|
|
|
|
assert.Len(t, result[0].Categories, 0)
|
|
|
|
} else {
|
|
|
|
t.Fatalf("unexpected result: %#v", result)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|