diff options
author | Jack <jackdeng@gmail.com> | 2015-09-23 19:54:07 -0700 |
---|---|---|
committer | Jack <jackdeng@gmail.com> | 2015-09-23 19:54:07 -0700 |
commit | f43d35507827216071896cae83544fef1c4c35eb (patch) | |
tree | 0cb6c86ff618a0ecd756e81f38bec2ed2c6986c7 /Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go | |
parent | 396a535f1001526cde60e77f8fc5e571bf4d882b (diff) | |
download | chat-f43d35507827216071896cae83544fef1c4c35eb.tar.gz chat-f43d35507827216071896cae83544fef1c4c35eb.tar.bz2 chat-f43d35507827216071896cae83544fef1c4c35eb.zip |
godep save
Diffstat (limited to 'Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go')
-rw-r--r-- | Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go | 125 |
1 files changed, 0 insertions, 125 deletions
diff --git a/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go b/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go deleted file mode 100644 index 51ded1a1c..000000000 --- a/Godeps/_workspace/src/code.google.com/p/graphics-go/graphics/detect/opencv_parser.go +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright 2011 The Graphics-Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package detect - -import ( - "bytes" - "encoding/xml" - "errors" - "fmt" - "image" - "io" - "io/ioutil" - "strconv" - "strings" -) - -type xmlFeature struct { - Rects []string `xml:"grp>feature>rects>grp"` - Tilted int `xml:"grp>feature>tilted"` - Threshold float64 `xml:"grp>threshold"` - Left float64 `xml:"grp>left_val"` - Right float64 `xml:"grp>right_val"` -} - -type xmlStages struct { - Trees []xmlFeature `xml:"trees>grp"` - Stage_threshold float64 `xml:"stage_threshold"` - Parent int `xml:"parent"` - Next int `xml:"next"` -} - -type opencv_storage struct { - Any struct { - XMLName xml.Name - Type string `xml:"type_id,attr"` - Size string `xml:"size"` - Stages []xmlStages `xml:"stages>grp"` - } `xml:",any"` -} - -func buildFeature(r string) (f Feature, err error) { - var x, y, w, h int - var weight float64 - _, err = fmt.Sscanf(r, "%d %d %d %d %f", &x, &y, &w, &h, &weight) - if err != nil { - return - } - f.Rect = image.Rect(x, y, x+w, y+h) - f.Weight = weight - return -} - -func buildCascade(s *opencv_storage) (c *Cascade, name string, err error) { - if s.Any.Type != "opencv-haar-classifier" { - err = fmt.Errorf("got %s want opencv-haar-classifier", s.Any.Type) - return - } - name = s.Any.XMLName.Local - - c = &Cascade{} - sizes := strings.Split(s.Any.Size, " ") - w, err := strconv.Atoi(sizes[0]) - if err != nil { - return nil, "", err - } - h, err := strconv.Atoi(sizes[1]) - if err != nil { - return nil, "", err - } - c.Size = image.Pt(w, h) - c.Stage = []CascadeStage{} - - for _, stage := range s.Any.Stages { - cs := CascadeStage{ - Classifier: []Classifier{}, - Threshold: stage.Stage_threshold, - } - for _, tree := range stage.Trees { - if tree.Tilted != 0 { - err = errors.New("Cascade does not support tilted features") - return - } - - cls := Classifier{ - Feature: []Feature{}, - Threshold: tree.Threshold, - Left: tree.Left, - Right: tree.Right, - } - - for _, rect := range tree.Rects { - f, err := buildFeature(rect) - if err != nil { - return nil, "", err - } - cls.Feature = append(cls.Feature, f) - } - - cs.Classifier = append(cs.Classifier, cls) - } - c.Stage = append(c.Stage, cs) - } - - return -} - -// ParseOpenCV produces a detection Cascade from an OpenCV XML file. -func ParseOpenCV(r io.Reader) (cascade *Cascade, name string, err error) { - // BUG(crawshaw): tag-based parsing doesn't seem to work with <_> - buf, err := ioutil.ReadAll(r) - if err != nil { - return - } - buf = bytes.Replace(buf, []byte("<_>"), []byte("<grp>"), -1) - buf = bytes.Replace(buf, []byte("</_>"), []byte("</grp>"), -1) - - s := &opencv_storage{} - err = xml.Unmarshal(buf, s) - if err != nil { - return - } - return buildCascade(s) -} |