func FindBeginPos(img *cv.BinaryImage, beginX int) (int, int) { for x := beginX; x < img.Width; x++ { for y := 0; y < img.Height; y++ { if img.IsOpen(x, y) { return x, y } } } return img.Width - 1, img.Height - 1 }
func (self *Mask) Match(src *cv.BinaryImage, srcLeft int, srcTop int) float64 { ret := 0.0 for x := srcLeft; x < srcLeft+self.Img.Width && x < src.Width; x++ { for y := srcTop; y < srcTop+self.Img.Height && y < src.Height; y++ { if src.IsOpen(x, y) && self.Img.IsOpen(x-srcLeft, y-srcTop) { ret += 1.0 } } } ret *= 2.0 ret /= float64(self.Img.FrontSize() + src.FrontSize() + 1) return ret }
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 }