コード例 #1
0
ファイル: guess.go プロジェクト: finallybiubiu/captcha
func Guess(link string) {
	img := captcha.LoadImage(link)
	/*
		decoder := &captcha.Decoder{
			ImageProcessors: []cv.ImageProcessor {
					&cv.MeanShift{K:1},
				},
			BiColorProcessor: &cv.PeakAverageBasedBiColor{},
			BinaryImageProcessors: []cv.BinaryImageProcessor{
				&cv.RemoveBinaryImageBorder{},
				&cv.RemoveIsolatePoints{},
				&cv.BoundBinaryImage{XMinOpen: 2, YMinOpen : 5},
				&cv.RemoveXAxis{K : 2},
				&cv.ScaleBinaryImage{Height : captcha.SCALE_HEIGHT},
			},
			BinaryImagePredictor: &captcha.BinaryImageConnectedComponentPredictor{Dx : 1, Dy : 1},
		}
	*/
	decoder := &captcha.Decoder{
		BiColorProcessor: &cv.PeakAverageBasedBiColor{},
		BinaryImageProcessors: []cv.BinaryImageProcessor{
			&cv.RemoveBinaryImageBorder{},
			&cv.RemoveIsolatePoints{},
			//&cv.Thining{},
			&cv.BoundBinaryImage{XMinOpen: 0, YMinOpen: 0},
			//&cv.RemoveXAxis{K : 1},
			&cv.ScaleBinaryImage{Height: captcha.SCALE_HEIGHT},
		},
		BinaryImagePredictor: &captcha.FastCutBasedPredictor{},
	}

	masks := captcha.LoadMasks("./masks")
	results := decoder.Predict(img, masks, captcha.NUMBER)

}
コード例 #2
0
ファイル: captcha.go プロジェクト: finallybiubiu/captcha
func TestAll(folder string) {
	imgs := captcha.LoadTestImages(folder)
	log.Println("test images", len(imgs))
	masks := captcha.LoadMasks("./masks")
	hit := 0.0
	total := 0.0
	for _, img := range imgs {
		predictor := captcha.NewMetaPredictor()
		log.Println(img.Path)
		ok := false
		for {
			copyImg := captcha.CopyImage(img.Img)
			results := predictor.Predict(copyImg, masks, img.ChType)
			if results == nil {
				break
			}
			for _, result := range results {
				log.Println(">>>>>>>>>", result.Label, img.Label)
				if result.Label == img.Label {
					log.Println("--------- ok")
					hit += 1.0
					ok = true
					break
				}
			}
			if ok {
				break
			}
		}
		if !ok {
			captcha.SaveImage(img.Img, "./failed/"+img.Label)
		}
		total += 1.0
		fmt.Println()
	}
	log.Println("hit ratio", hit/total)
}