func (self *Mask) FromString(line string) { tks := strings.Split(line, "\t") self.Label = tks[0] width, _ := strconv.Atoi(tks[1]) height, _ := strconv.Atoi(tks[2]) self.Img = cv.NewBinaryImage(width, height) for i := 3; i < len(tks); i++ { kv := strings.Split(tks[i], ":") x, _ := strconv.Atoi(kv[0]) y, _ := strconv.Atoi(kv[1]) self.Img.Open(x, y) } }
func (self *FastCutBasedPredictor) CutMatrixByRect(img *cv.BinaryImage, left, top, right, bottom int) *cv.BinaryImage { if right <= left || bottom <= top { return nil } ret := cv.NewBinaryImage(right-left, bottom-top) for x := left; x < right && x < img.Width; x++ { for y := top; y < bottom && y < img.Height; y++ { if img.IsOpen(x, y) { ret.Open(x-left, y-top) } } } return ret }