예제 #1
0
func (self *FastCutBasedPredictor) XHis(img *cv.BinaryImage) []int {
	h := []int{}
	for x := 0; x < img.Width; x++ {
		h = append(h, 0)
		for y := 0; y < img.Height; y++ {
			h[x] += img.Get(x, y)
		}
	}
	return h
}
예제 #2
0
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
}
예제 #3
0
func FindEndPos(img *cv.BinaryImage, beginX int) int {
	for x := beginX; x < img.Width; x++ {
		sum := 0
		for y := 0; y < img.Height; y++ {
			sum += img.Get(x, y)
		}
		if sum == 0 {
			return x
		}
	}
	return img.Width
}
예제 #4
0
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
}
예제 #5
0
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
}
예제 #6
0
func (self *MaskIndex) FindBestMatchedMasks(img *cv.BinaryImage, chType int, widthWeight int) []*Result {
	h := img.FeatureEncode()
	ids, ok := self.index[h]
	if !ok {
		return nil
	}

	results := ResultSorter{}
	for _, i := range ids {
		mk := self.masks[i]
		if !mk.MatchChType(chType) {
			continue
		}
		sim := mk.Match(img, 0, 0)
		sim *= float64(img.Width)
		sim /= float64(img.Width + widthWeight)
		results = append(results, NewResult(mk.Label, sim))
	}
	sort.Sort(results)
	return results
}
예제 #7
0
func (self *MaskIndex) QueryMask(img *cv.BinaryImage) ([]int, bool) {
	h := img.FeatureEncode()
	ret, ok := self.index[h]
	return ret, ok
}