Created
February 2, 2016 15:19
-
-
Save secondarykey/f2cef43eb4830ae29705 to your computer and use it in GitHub Desktop.
gxuiにgo-opencvから動画データを流し込んでみた。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"image" | |
"image/draw" | |
_ "image/jpeg" | |
_ "image/png" | |
"github.com/google/gxui" | |
"github.com/google/gxui/drivers/gl" | |
"github.com/google/gxui/themes/dark" | |
"github.com/lazywei/go-opencv/opencv" | |
) | |
func appMain(driver gxui.Driver) { | |
filename := "matrix2.mp4" | |
capt := opencv.NewFileCapture(filename) | |
if capt == nil { | |
panic("can not open video") | |
} | |
defer capt.Release() | |
w := int(capt.GetProperty(opencv.CV_CAP_PROP_FRAME_WIDTH)) | |
h := int(capt.GetProperty(opencv.CV_CAP_PROP_FRAME_HEIGHT)) | |
theme := dark.CreateTheme(driver) | |
imgWd := theme.CreateImage() | |
window := theme.CreateWindow(w, h, "movie viewer") | |
window.SetScale(1.0) | |
window.AddChild(imgWd) | |
rect := image.Rect(0, 0, w, h) | |
rgba := image.NewRGBA(rect) | |
cvImage := capt.QueryFrame() | |
draw.Draw(rgba, rect, cvImage.ToImage(), image.ZP, draw.Src) | |
texture := driver.CreateTexture(rgba, 1) | |
imgWd.SetTexture(texture) | |
window.OnClose(driver.Terminate) | |
} | |
func main() { | |
gl.StartDriver(appMain) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment