Exemplo n.º 1
0
func videoProcessor() {
	var src = path.Join(path.Dir(TEST_FILE)) + "/" + TEST_FILE

	var cap = modules.NewVideoCapture(src)
	var processor = modules.NewVideoProcessor(cap, modules.NewVideoWriter(uint32(opencv.FOURCC('m', 'p', '4', 'v')), 10.0, cap.Size))

	processor.TestInit()
	processor.Run()
}
Exemplo n.º 2
0
func TrackEyes(srcFile, destFile string) {
	var video = opencv.NewFileCapture(srcFile)

	var fourcc = opencv.FOURCC('m', 'p', '4', 'v')
	var fps = float32(video.GetProperty(opencv.CV_CAP_PROP_FPS))
	var size = opencv.Size{int(video.GetProperty(opencv.CV_CAP_PROP_FRAME_WIDTH)),
		int(video.GetProperty(opencv.CV_CAP_PROP_FRAME_HEIGHT))}

	if video == nil {
		panic("no file found with name: " + srcFile)
	}
	defer video.Release()

	win := opencv.NewWindow("Go-OpenCV Webcam")
	defer win.Destroy()

	_, currentfile, _, _ := runtime.Caller(0)
	var cascade = path.Join(path.Dir(currentfile), "/../cascades/haarcascade_eye_tree_eyeglasses.xml")
	var eyeMarker = NewEyeMarker(cascade)

	var imgs = []*opencv.IplImage{}
	var imgs2 = []*opencv.IplImage{}

	for {
		if video.GrabFrame() {
			img := video.RetrieveFrame(1)
			if img != nil {

				var copy = opencv.CreateImage(img.Width(), img.Height(), img.Depth(), img.Channels())
				opencv.Copy(img.Clone(), copy, nil)

				var markedImg = eyeMarker.MarkEyes(copy)

				imgs = append(imgs, markedImg)
				//win.ShowImage(imgs[len(imgs)-1])
			} else {
				fmt.Println("Image ins nil")
			}
		} else {
			break
		}
		key := opencv.WaitKey(10)

		if key == 27 {
			os.Exit(0)
		}
	}

	for i := 0; i < len(imgs2); i++ {
		win.ShowImage(imgs2[i])
	}
	log.Print("before write")
	NewVideoWriter(uint32(fourcc), fps, size).SaveAsVideo(imgs, "test.avi")
	os.Exit(0)
}
func CaptureFrames() {
	var cam = opencv.NewCameraCapture(0)
	defer cam.Release()

	frames := []*opencv.IplImage{}
	//var writter = opencv.NewVideoWriter("test.avi", int(opencv.FOURCC('D','I','V','3')),20, 50, 50, 1)

	win := opencv.NewWindow("Go-OpenCV Webcam123")
	defer win.Destroy()
	for framesCounter := 0; framesCounter <= 25; framesCounter++ {
		log.Print(framesCounter)
		if cam.GrabFrame() || framesCounter > 25 {
			//            var frame = cam.RetrieveFrame(1)
			//            var img = ProcessImage(frame, 50)
			//            frames = append(frames, img)

			var frame = cam.RetrieveFrame(1)
			win.ShowImage(frame)
			//            var img3 = frame.ToImage()

			var imageHeader = opencv.CreateImage(frame.Width(), frame.Height(), frame.Depth(), frame.Channels())

			for i := 0; i < frame.Width(); i++ {
				for j := 0; j < frame.Height(); j++ {

					scalar := frame.Get2D(i, j)
					var bgra = scalar.Val()
					var newscalar = opencv.NewScalar(bgra[0], bgra[1], bgra[2], 1)
					imageHeader.Set2D(i, j, newscalar)

				}
			}
			//            var img3Opencv = opencv.FromImage(img3)

			var copy = opencv.CreateImage(frame.Width(), frame.Height(), frame.Depth(), frame.Channels())
			opencv.Copy(frame, copy, nil)
			//            frames = append(frames, img3Opencv)

			//win.ShowImage(imageHeader)

		}
	}

	var videoWritter = NewVideoWriter(opencv.FOURCC('D', 'I', 'V', '3'), 20, opencv.Size{frames[0].Width(), frames[0].Height()})
	videoWritter.SaveAsVideo(frames, "test.avi")

}
Exemplo n.º 4
0
func ProcessImageTest() {

	log.Print("Try to open webcam.")
	cap := opencv.NewCameraCapture(0)
	if cap == nil {
		panic("can not open camera")
	}

	log.Print("webcame opened.")

	var outputFileName = "testvideo.mpeg"
	var width = 640
	var height = 480
	var fps = 20.0
	var fourcc = opencv.FOURCC('m', 'p', '4', 'v')
	var noOfCapturedFrames = 100

	cap.SetProperty(opencv.CV_CAP_PROP_FRAME_WIDTH, float64(width))
	cap.SetProperty(opencv.CV_CAP_PROP_FRAME_HEIGHT, float64(height))
	cap.SetProperty(opencv.CV_CAP_PROP_FPS, fps)

	log.Print("capturing ", noOfCapturedFrames, " frames and save them to the following file: ", outputFileName)
	log.Print("width: ", width)
	log.Print("height: ", height)
	log.Print("fps: ", fps)
	log.Print("fourcc: ", fourcc)

	var frames []*opencv.IplImage

	for len(frames) < noOfCapturedFrames {
		if cap.GrabFrame() {
			img := cap.RetrieveFrame(1)
			if img != nil {

				var frame = cap.RetrieveFrame(1)
				var copy = opencv.CreateImage(int(width), int(height), frame.Depth(), frame.Channels())
				defer copy.Release()
				opencv.Copy(frame, copy, nil)

				frames = append(frames, copy)

			} else {
				fmt.Println("Image ins nil")
			}
		}
	}

	cap.Release()
	win := opencv.NewWindow("Go-OpenCV Webcam")
	defer win.Destroy()
	for i := 0; i < len(frames); i++ {
		log.Print("displaying frame no: ", i)
		win.ShowImage(frames[i])
		key := opencv.WaitKey(10)
		if key != 0 {
			log.Print(key)
		}
	}

	log.Print("start writing frames to file.")
	var videoWritter = NewVideoWriter(fourcc, float32(fps), opencv.Size{int(width), int(height)})
	videoWritter.SaveAsVideo(frames, outputFileName)

	log.Print("created file with name: ", outputFileName)
	os.Exit(0)
}