Beispiel #1
0
func (d *FreenectDevice) RGBAFrame() *image.RGBA {
	data, _ := d.RawRGBFrame(FREENECT_VIDEO_RGB)

	r := image.Rect(0, 0, 640, 480)
	img := image.NewRGBA(r)

	for row := 0; row < 480; row++ {
		for col := 0; col < 640; col++ {
			targetPos := C.int(row*640*4 + col*4)
			sourcePos := C.int(row*640*3 + col*3)

			img.Pix[targetPos] = uint8(C.get_byte(data, sourcePos))
			img.Pix[targetPos+1] = uint8(C.get_byte(data, sourcePos+1))
			img.Pix[targetPos+2] = uint8(C.get_byte(data, sourcePos+2))
			img.Pix[targetPos+3] = 1
		}
	}

	img.Stride = 640 * 4

	return img
}
Beispiel #2
0
func (d *FreenectDevice) DepthFrame() *image.RGBA {
	data, _ := d.RawDepthFrame(FREENECT_DEPTH_REGISTERED)

	r := image.Rect(0, 0, 640, 480)
	img := image.NewRGBA(r)

	for row := 0; row < 480; row++ {
		for col := 0; col < 640; col++ {
			targetPos := C.int(row*640*4 + col*4)
			sourcePos := C.int(row*640*2 + col*2)

			val := uint8(C.get_byte(data, sourcePos))
			img.Pix[targetPos] = val
			img.Pix[targetPos+1] = val
			img.Pix[targetPos+2] = val
			img.Pix[targetPos+3] = 1
		}
	}

	img.Stride = 640 * 4

	return img
}