func ProcessRoi(img *opencv.IplImage, gradeOfCanny int) *opencv.IplImage {

	var roi = img.GetROI()

	w := roi.Width()
	h := roi.Height()

	// Create the output image
	cedge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 3)
	//defer cedge.Release()

	// Convert to grayscale
	gray := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	edge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	//newimage := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	defer gray.Release()
	defer edge.Release()

	opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)

	opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0)
	opencv.Not(gray, edge)

	// Run the edge detector on grayscale
	opencv.Canny(gray, edge, float64(gradeOfCanny), float64(gradeOfCanny*3), 3)

	opencv.Zero(cedge)
	// copy edge points
	opencv.Copy(img, cedge, edge)

	return cedge

}
示例#2
0
func ProcessImage(img *opencv.IplImage, win *opencv.Window, pos int) error {
	w := img.Width()
	h := img.Height()

	// Create the output image
	cedge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 3)
	defer cedge.Release()

	// Convert to grayscale
	gray := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	edge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	defer gray.Release()
	defer edge.Release()

	opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)

	opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0)
	opencv.Not(gray, edge)

	// Run the edge detector on grayscale
	opencv.Canny(gray, edge, float64(pos), float64(pos*3), 3)

	opencv.Zero(cedge)
	// copy edge points
	opencv.Copy(img, cedge, edge)

	win.ShowImage(img)
	return nil
}
示例#3
0
func (d *Detector) Detect() *opencv.IplImage {
	opencv.Copy(d.currentFrame, d.previousFrame, nil)
	opencv.Copy(d.nextFrame, d.currentFrame, nil)
	opencv.CvtColor(d.params.QueryFrame(), d.nextFrame, opencv.CV_BGR2GRAY)

	opencv.AbsDiff(d.previousFrame, d.nextFrame, d.d1)
	opencv.AbsDiff(d.nextFrame, d.currentFrame, d.d2)
	opencv.BitwiseAnd(d.d1, d.d2, d.motion, nil)
	opencv.Threshold(d.motion, d.motion, 35, 255, opencv.CV_THRESH_BINARY)

	_, sdev := opencv.MeanStdDev(d.motion, nil)
	if sdev.Val()[0] <= d.params.DevThreshold {
		d.phase = 0
		return nil
	}

	d.phase++
	if d.phase < d.params.PhaseThreshold {
		return nil
	}

	d.phase = 0
	return d.params.QueryFrame()
}
func HoughCirclesWithParams(img *opencv.IplImage, dp float64, min_dist float64, param_1 float64, param_2 float64, min_radius int, maxradius int) []opencv.CircleStruct {
	var gray = opencv.CreateImage(img.Width(), img.Height(), opencv.IPL_DEPTH_8U, 1)
	opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)
	return opencv.HoughCircles(gray, dp, min_dist, param_1, param_2, 1, 500)
}
func HoughCircles1(img *opencv.IplImage) []opencv.CircleStruct {
	var gray = opencv.CreateImage(img.Width(), img.Height(), opencv.IPL_DEPTH_8U, 1)
	opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)
	return opencv.HoughCircles(gray, 15, 100, 75, 5, 25, 500)
}
示例#6
0
文件: edge.go 项目: nfillot/go-opencv
func main() {
	filename := "../images/lena.jpg"
	if len(os.Args) == 2 {
		filename = os.Args[1]
	}

	image := opencv.LoadImage(filename)
	if image == nil {
		panic("LoadImage fail")
	}
	defer image.Release()

	w := image.Width()
	h := image.Height()

	// Create the output image
	cedge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 3)
	defer cedge.Release()

	// Convert to grayscale
	gray := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	edge := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	defer gray.Release()
	defer edge.Release()

	opencv.CvtColor(image, gray, opencv.CV_BGR2GRAY)

	win := opencv.NewWindow("Edge")
	defer win.Destroy()

	win.SetMouseCallback(func(event, x, y, flags int, param ...interface{}) {
		fmt.Printf("event = %d, x = %d, y = %d, flags = %d\n",
			event, x, y, flags,
		)
	})

	win.CreateTrackbar("Thresh", 1, 100, func(pos int, param ...interface{}) {
		edge_thresh := pos

		opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0)
		opencv.Not(gray, edge)

		// Run the edge detector on grayscale
		opencv.Canny(gray, edge, float64(edge_thresh), float64(edge_thresh*3), 3)

		opencv.Zero(cedge)
		// copy edge points
		opencv.Copy(image, cedge, edge)

		win.ShowImage(cedge)

		fmt.Printf("pos = %d\n", pos)
	})
	win.ShowImage(image)

	for {
		key := opencv.WaitKey(20)
		if key == 27 {
			os.Exit(0)
		}
	}

	os.Exit(0)
}
示例#7
0
func cloneGreyscale(im *opencv.IplImage) *opencv.IplImage {
	w, h := im.Width(), im.Height()
	g := opencv.CreateImage(w, h, opencv.IPL_DEPTH_8U, 1)
	opencv.CvtColor(im, g, opencv.CV_BGR2GRAY)
	return g
}