• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang opencv.IplImage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/lazywei/go-opencv/opencv.IplImage的典型用法代码示例。如果您正苦于以下问题:Golang IplImage类的具体用法?Golang IplImage怎么用?Golang IplImage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了IplImage类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: ProcessRoi

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

}
开发者ID:mstein11,项目名称:opencv-examples,代码行数:33,代码来源:captureFramesToFile.go


示例2: ProcessImage

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
}
开发者ID:mstein11,项目名称:opencv-examples,代码行数:29,代码来源:webcam.go


示例3: main

func main() {
	_, currentfile, _, _ := runtime.Caller(0)
	cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")

	window := opencv.NewWindowDriver()
	camera := opencv.NewCameraDriver(0)

	work := func() {
		var image *cv.IplImage

		camera.On(opencv.Frame, func(data interface{}) {
			image = data.(*cv.IplImage)
		})

		gobot.Every(500*time.Millisecond, func() {
			if image != nil {
				i := image.Clone()
				faces := opencv.DetectFaces(cascade, i)
				i = opencv.DrawRectangles(i, faces, 0, 255, 0, 5)
				window.ShowImage(i)
			}

		})
	}

	robot := gobot.NewRobot("faceBot",
		[]gobot.Connection{},
		[]gobot.Device{window, camera},
		work,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:33,代码来源:opencv_face_detect.go


示例4: ToByteBuffer

func ToByteBuffer(image *opencv.IplImage) []byte {

	buf := new(bytes.Buffer)

	err := jpeg.Encode(buf, image.ToImage(), nil)
	if err != nil {
		panic(err)
	}
	return buf.Bytes()
}
开发者ID:postfix,项目名称:gofaces,代码行数:10,代码来源:detector.go


示例5: DetectGlasses

func (detector *FaceDetector) DetectGlasses(image *opencv.IplImage, roi pixelArea) (leftEyes, rightEyes pixelCoords) {

	var topFace opencv.Rect
	var eyes pixelCoords

	topFace.Init(roi.X(), roi.Y()+int(float64(roi.Height())*0.20), roi.Width(), int(float64(roi.Height())/2))

	image.SetROI(topFace)
	for _, eye := range detector.glassesCascade.DetectObjects(image) {
		leftEyes = append(leftEyes, pixelCoord{
			x:      eye.X() + topFaceLeft.X(),
			y:      eye.Y() + topFaceLeft.Y(),
			width:  eye.Width(),
			height: eye.Height(),
		})
	}

	fmt.Println(len(leftEyes), " left eyes found")

	image.SetROI(topFaceRight)
	for _, eye := range detector.glassesCascade.DetectObjects(image) {
		rightEyes = append(rightEyes, pixelCoord{
			x:      eye.X() + topFaceRight.X(),
			y:      eye.Y() + topFaceRight.Y(),
			width:  eye.Width(),
			height: eye.Height(),
		})
	}
	fmt.Println(len(rightEyes), " right eyes found")

	image.ResetROI()
	return
}
开发者ID:postfix,项目名称:gofaces,代码行数:33,代码来源:detector.go


示例6: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	_, currentfile, _, _ := runtime.Caller(0)
	cascade := path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml")
	window := opencv.NewWindowDriver()
	camera := opencv.NewCameraDriver("tcp://192.168.1.1:5555")
	ardroneAdaptor := ardrone.NewAdaptor()
	drone := ardrone.NewDriver(ardroneAdaptor)

	work := func() {
		detect := false
		drone.TakeOff()
		var image *cv.IplImage
		camera.On(opencv.Frame, func(data interface{}) {
			image = data.(*cv.IplImage)
			if !detect {
				window.ShowImage(image)
			}
		})
		drone.On(ardrone.Flying, func(data interface{}) {
			gobot.After(1*time.Second, func() { drone.Up(0.2) })
			gobot.After(2*time.Second, func() { drone.Hover() })
			gobot.After(5*time.Second, func() {
				detect = true
				gobot.Every(300*time.Millisecond, func() {
					drone.Hover()
					i := image
					faces := opencv.DetectFaces(cascade, i)
					biggest := 0
					var face *cv.Rect
					for _, f := range faces {
						if f.Width() > biggest {
							biggest = f.Width()
							face = f
						}
					}
					if face != nil {
						opencv.DrawRectangles(i, []*cv.Rect{face}, 0, 255, 0, 5)
						centerX := float64(image.Width()) * 0.5
						turn := -(float64(face.X()) - centerX) / centerX
						fmt.Println("turning:", turn)
						if turn < 0 {
							drone.Clockwise(math.Abs(turn * 0.4))
						} else {
							drone.CounterClockwise(math.Abs(turn * 0.4))
						}
					}
					window.ShowImage(i)
				})
				gobot.After(20*time.Second, func() { drone.Land() })
			})
		})
	}

	robot := gobot.NewRobot("face",
		[]gobot.Connection{ardroneAdaptor},
		[]gobot.Device{window, camera, drone},
		work,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:63,代码来源:ardrone_face_tracking.go


示例7: DetectFacialFeatures

func (detector *FaceDetector) DetectFacialFeatures(image *opencv.IplImage, faceCoords []pixelCoord) faces {

	var faces = make(faces, 0)

	for _, faceCoord := range faceCoords {

		//Lets find us some eyes
		leftEyes, rightEyes := detector.DetectEyes(image, &faceCoord)

		if len(leftEyes) == 0 || len(rightEyes) == 0 {

			//No eyes found, lets flop the picture and check again
			fmt.Println("Flopping Picture to look for eyes")

			floppedImage := opencv.DecodeImageMem(FlopImage(ToByteBuffer(image)))
			floppedFaceCoords := faceCoord

			floppedFaceCoords.Flop(pixelCoord{width: image.Width(), height: image.Height()})

			floppedLeftEyes, floppedRightEyes := detector.DetectEyes(floppedImage, &floppedFaceCoords)

			if len(leftEyes) == 0 {
				floppedRightEyes.FlopEmAll(pixelCoord{width: image.Width(), height: image.Height()})
				leftEyes = append(leftEyes, floppedRightEyes...)
			}

			if len(rightEyes) == 0 {
				floppedLeftEyes.FlopEmAll(pixelCoord{width: image.Width(), height: image.Height()})
				leftEyes = append(rightEyes, floppedLeftEyes...)
			}
		}

		leftEye, rightEye := FindBestEyes(leftEyes, rightEyes)
		faces = append(faces, face{
			coord:     faceCoord,
			eye_left:  leftEye,
			eye_right: rightEye,
		})
	}

	fmt.Println(faces)
	return faces
}
开发者ID:postfix,项目名称:gofaces,代码行数:43,代码来源:detector.go


示例8: ToImage

func ToImage(img *opencv.IplImage) image.Image {
	out := image.NewNRGBA(image.Rect(0, 0, img.Width(), img.Height()))
	if img.Depth() != opencv.IPL_DEPTH_8U {
		return nil // TODO return error
	}

	for y := 0; y < img.Height(); y++ {
		for x := 0; x < img.Width(); x++ {
			s := img.Get2D(x, y).Val()
			b, g, r, a := s[2], s[1], s[0], s[3]

			c := color.NRGBA{uint8(b), uint8(g), uint8(r), uint8(a)}
			out.Set(x, y, c)
		}
	}

	return out
}
开发者ID:mstein11,项目名称:opencv-examples,代码行数:18,代码来源:captureFramesToFile.go


示例9: HoughCirclesWithParams

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)
}
开发者ID:mstein11,项目名称:opencv-examples,代码行数:5,代码来源:captureFramesToFile.go


示例10: HoughCircles1

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)
}
开发者ID:mstein11,项目名称:opencv-examples,代码行数:5,代码来源:captureFramesToFile.go


示例11: cloneGreyscale

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
}
开发者ID:death,项目名称:motionwatch,代码行数:6,代码来源:detector.go



注:本文中的github.com/lazywei/go-opencv/opencv.IplImage类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang db.Count函数代码示例发布时间:2022-05-23
下一篇:
Golang opencv.NewWindow函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap