opencv_parser_test.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2011 The Graphics-Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package detect
  5. import (
  6. "image"
  7. "os"
  8. "reflect"
  9. "testing"
  10. )
  11. var (
  12. classifier0 = Classifier{
  13. Feature: []Feature{
  14. Feature{Rect: image.Rect(0, 0, 3, 4), Weight: -1},
  15. Feature{Rect: image.Rect(3, 4, 5, 6), Weight: 3.1},
  16. },
  17. Threshold: 0.03,
  18. Left: 0.01,
  19. Right: 0.8,
  20. }
  21. classifier1 = Classifier{
  22. Feature: []Feature{
  23. Feature{Rect: image.Rect(3, 7, 17, 11), Weight: -3.2},
  24. Feature{Rect: image.Rect(3, 9, 17, 11), Weight: 2.},
  25. },
  26. Threshold: 0.11,
  27. Left: 0.03,
  28. Right: 0.83,
  29. }
  30. classifier2 = Classifier{
  31. Feature: []Feature{
  32. Feature{Rect: image.Rect(1, 1, 3, 3), Weight: -1.},
  33. Feature{Rect: image.Rect(3, 3, 5, 5), Weight: 2.5},
  34. },
  35. Threshold: 0.07,
  36. Left: 0.2,
  37. Right: 0.4,
  38. }
  39. cascade = Cascade{
  40. Stage: []CascadeStage{
  41. CascadeStage{
  42. Classifier: []Classifier{classifier0, classifier1},
  43. Threshold: 0.82,
  44. },
  45. CascadeStage{
  46. Classifier: []Classifier{classifier2},
  47. Threshold: 0.22,
  48. },
  49. },
  50. Size: image.Pt(20, 20),
  51. }
  52. )
  53. func TestParseOpenCV(t *testing.T) {
  54. file, err := os.Open("../../testdata/opencv.xml")
  55. if err != nil {
  56. t.Fatal(err)
  57. }
  58. defer file.Close()
  59. cascadeFile, name, err := ParseOpenCV(file)
  60. if err != nil {
  61. t.Fatal(err)
  62. }
  63. if name != "name_of_cascade" {
  64. t.Fatalf("name: got %s want name_of_cascade", name)
  65. }
  66. if !reflect.DeepEqual(cascade, *cascadeFile) {
  67. t.Errorf("got\n %v want\n %v", *cascadeFile, cascade)
  68. }
  69. }