github.com/aloncn/graphics-go@v0.0.1/graphics/detect/opencv_parser_test.go (about)

     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  
     5  package detect
     6  
     7  import (
     8  	"image"
     9  	"os"
    10  	"reflect"
    11  	"testing"
    12  )
    13  
    14  var (
    15  	classifier0 = Classifier{
    16  		Feature: []Feature{
    17  			Feature{Rect: image.Rect(0, 0, 3, 4), Weight: -1},
    18  			Feature{Rect: image.Rect(3, 4, 5, 6), Weight: 3.1},
    19  		},
    20  		Threshold: 0.03,
    21  		Left:      0.01,
    22  		Right:     0.8,
    23  	}
    24  	classifier1 = Classifier{
    25  		Feature: []Feature{
    26  			Feature{Rect: image.Rect(3, 7, 17, 11), Weight: -3.2},
    27  			Feature{Rect: image.Rect(3, 9, 17, 11), Weight: 2.},
    28  		},
    29  		Threshold: 0.11,
    30  		Left:      0.03,
    31  		Right:     0.83,
    32  	}
    33  	classifier2 = Classifier{
    34  		Feature: []Feature{
    35  			Feature{Rect: image.Rect(1, 1, 3, 3), Weight: -1.},
    36  			Feature{Rect: image.Rect(3, 3, 5, 5), Weight: 2.5},
    37  		},
    38  		Threshold: 0.07,
    39  		Left:      0.2,
    40  		Right:     0.4,
    41  	}
    42  	cascade = Cascade{
    43  		Stage: []CascadeStage{
    44  			CascadeStage{
    45  				Classifier: []Classifier{classifier0, classifier1},
    46  				Threshold:  0.82,
    47  			},
    48  			CascadeStage{
    49  				Classifier: []Classifier{classifier2},
    50  				Threshold:  0.22,
    51  			},
    52  		},
    53  		Size: image.Pt(20, 20),
    54  	}
    55  )
    56  
    57  func TestParseOpenCV(t *testing.T) {
    58  	file, err := os.Open("../../testdata/opencv.xml")
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  	defer file.Close()
    63  
    64  	cascadeFile, name, err := ParseOpenCV(file)
    65  	if err != nil {
    66  		t.Fatal(err)
    67  	}
    68  	if name != "name_of_cascade" {
    69  		t.Fatalf("name: got %s want name_of_cascade", name)
    70  	}
    71  
    72  	if !reflect.DeepEqual(cascade, *cascadeFile) {
    73  		t.Errorf("got\n %v want\n %v", *cascadeFile, cascade)
    74  	}
    75  }