本文整理汇总了Golang中github.com/lazywei/go-opencv/opencv.NewWindow函数的典型用法代码示例。如果您正苦于以下问题:Golang NewWindow函数的具体用法?Golang NewWindow怎么用?Golang NewWindow使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewWindow函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: loop
func loop(path string, paint, crosshair bool) {
pictureFiles = GetFileNames(path)
// images := make([][]byte, len(pictureFiles))
faceDetector := gofaces.NewFaceDetector()
// for i := 0; i < len(pictureFiles); i++ {
// }
fmt.Println("Pictures: ", len(pictureFiles))
for i := 0; i < len(pictureFiles); i++ {
fmt.Println("Processing picture: ", pictureFiles[i])
img := gofaces.GetNormalizedByteVectorFromFile(pictureFiles[i])
faces := faceDetector.Detect(img)
if len(faces) > 0 {
if paint {
img = gofaces.PaintFace(img, faces[0])
}
if faces[0].Eyes() > 1 {
img = gofaces.AlignFaceInImage(img, faces[0])
}
if crosshair {
img = gofaces.Crosshair(img)
}
cropface := gofaces.CropOutFace(img, faces[0])
win := opencv.NewWindow("Face Detected")
win.ShowImage(opencv.DecodeImageMem(cropface))
opencv.WaitKey(0)
win.Destroy()
} else {
win := opencv.NewWindow("No face found")
win.ShowImage(opencv.DecodeImageMem(img))
opencv.WaitKey(0)
win.Destroy()
}
}
}
示例2: main
func main() {
_, currentfile, _, _ := runtime.Caller(0)
filename := path.Join(path.Dir(currentfile), "./images/gopher.png")
if len(os.Args) == 2 {
filename = os.Args[1]
}
image := opencv.LoadImage(filename)
if image == nil {
panic("LoadImage fail")
}
defer image.Release()
win := opencv.NewWindow("Go-OpenCV")
defer win.Destroy()
win.SetMouseCallback(func(event, x, y, flags int) {
fmt.Printf("event = %d, x = %d, y = %d, flags = %d\n",
event, x, y, flags,
)
})
win.CreateTrackbar("Thresh", 1, 100, func(pos int) {
fmt.Printf("pos = %d\n", pos)
})
win.ShowImage(image)
opencv.WaitKey(0)
}
示例3: main
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()
win := opencv.NewWindow("Go-OpenCV")
defer win.Destroy()
win.SetMouseCallback(func(event, x, y, flags int) {
fmt.Printf("event = %d, x = %d, y = %d, flags = %d\n",
event, x, y, flags,
)
})
win.CreateTrackbar("Thresh", 1, 100, func(pos int) {
fmt.Printf("pos = %d\n", pos)
})
win.ShowImage(image)
opencv.WaitKey(0)
}
示例4: main
func main() {
var edge_threshold int
win := opencv.NewWindow("Go-OpenCV Webcam")
defer win.Destroy()
cap := opencv.NewCameraCapture(0)
if cap == nil {
panic("can not open camera")
}
defer cap.Release()
win.CreateTrackbar("Thresh", 1, 100, func(pos int, param ...interface{}) {
edge_threshold = pos
})
fmt.Println("Press ESC to quit")
for {
if cap.GrabFrame() {
img := cap.RetrieveFrame(1)
if img != nil {
ProcessImage(img, win, edge_threshold)
} else {
fmt.Println("Image ins nil")
}
}
key := opencv.WaitKey(10)
if key == 27 {
os.Exit(0)
}
}
}
示例5: NewWindowDriver
// NewWindowDriver creates a new window driver with specified name.
// It adds an start function to initialize window
func NewWindowDriver(name string) *WindowDriver {
return &WindowDriver{
name: name,
start: func(w *WindowDriver) {
w.window = cv.NewWindow(w.Name(), cv.CV_WINDOW_NORMAL)
},
}
}
示例6: TrackEyes
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)
}
示例7: Calibrate
func (v *View) Calibrate() {
win := opencv.NewWindow("Calibration")
defer win.Destroy()
overfunc := func(s string, index int) (string, int, func(pos int, param ...interface{})) {
var ours string
ours = fmt.Sprintf("%s%d", s, index)
var myf func(pos int, param ...interface{})
var pix int
switch s {
case "Top":
myf = func(pos int, param ...interface{}) {
v.Calibration.Circles[index].TopTangent = pos
}
pix = 1943
case "Left":
myf = func(pos int, param ...interface{}) {
v.Calibration.Circles[index].LeftTangent = pos
}
pix = 2591
case "Right":
myf = func(pos int, param ...interface{}) {
v.Calibration.Circles[index].RightTangent = pos
}
pix = 2591
case "Bottom":
myf = func(pos int, param ...interface{}) {
v.Calibration.Circles[index].BottomTangent = pos
}
pix = 1943
default:
panic("None of them???")
}
return ours, pix, myf
}
for i := 0; i < 7; i++ {
tours, tpix, tmyf := overfunc("Top", i)
lours, lpix, lmyf := overfunc("Left", i)
rours, rpix, rmyf := overfunc("Right", i)
bours, bpix, bmyf := overfunc("Bottom", i)
win.CreateTrackbar(tours, 0, tpix, tmyf)
win.CreateTrackbar(lours, 0, lpix, lmyf)
win.CreateTrackbar(rours, 0, rpix, rmyf)
win.CreateTrackbar(bours, 0, bpix, bmyf)
}
//win.CreateTrackbar("Left5", 0, 2591, func(pos int, param ...interface{}) {
// v.Calibration.Circles[5].LeftTangent = pos
//})
}
示例8: CaptureFrames
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")
}
示例9: debug
func debug(path string) {
faceDetector := gofaces.NewFaceDetector()
picture := gofaces.GetNormalizedByteVectorFromFile(path)
image := opencv.DecodeImageMem(picture)
faceAreas := faceDetector.DetectFaces(image)
faces := faceDetector.DetectFacialFeatures(image, faceAreas)
picture = gofaces.PaintFaces(picture, faces)
win := opencv.NewWindow("Debug Face Detection")
defer win.Destroy()
win.ShowImage(opencv.DecodeImageMem(picture))
opencv.WaitKey(0)
}
示例10: one
func one(path string, paint bool) {
faceDetector := gofaces.NewFaceDetector()
picture := gofaces.GetNormalizedByteVectorFromFile(path)
faces := faceDetector.Detect(picture)
if paint {
picture = gofaces.PaintFace(picture, faces[0])
}
picture = gofaces.AlignFaceInImage(picture, faces[0])
picture = gofaces.CropOutFace(picture, faces[0])
win := opencv.NewWindow("Face Detection")
defer win.Destroy()
win.ShowImage(opencv.DecodeImageMem(picture))
opencv.WaitKey(0)
}
示例11: main
func main() {
_, currentfile, _, _ := runtime.Caller(0)
image := opencv.LoadImage(path.Join(path.Dir(currentfile), "../images/lena.jpg"))
cascade := opencv.LoadHaarClassifierCascade(path.Join(path.Dir(currentfile), "haarcascade_frontalface_alt.xml"))
faces := cascade.DetectObjects(image)
for _, value := range faces {
opencv.Rectangle(image,
opencv.Point{value.X() + value.Width(), value.Y()},
opencv.Point{value.X(), value.Y() + value.Height()},
opencv.ScalarAll(255.0), 1, 1, 0)
}
win := opencv.NewWindow("Face Detection")
win.ShowImage(image)
opencv.WaitKey(0)
}
示例12: main
func main() {
win := opencv.NewWindow("Go-OpenCV Webcam Face Detection")
defer win.Destroy()
cap := opencv.NewCameraCapture(0)
if cap == nil {
panic("cannot open camera")
}
defer cap.Release()
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
cascade := opencv.LoadHaarClassifierCascade(path.Join(cwd, "haarcascade_frontalface_alt.xml"))
fmt.Println("Press ESC to quit")
for {
if cap.GrabFrame() {
img := cap.RetrieveFrame(1)
if img != nil {
faces := cascade.DetectObjects(img)
for _, value := range faces {
opencv.Circle(img,
opencv.Point{
value.X() + (value.Width() / 2),
value.Y() + (value.Height() / 2),
},
value.Width()/2,
opencv.ScalarAll(255.0), 1, 1, 0)
}
win.ShowImage(img)
} else {
fmt.Println("nil image")
}
}
key := opencv.WaitKey(1)
if key == 27 {
os.Exit(0)
}
}
}
示例13: MarkRoi
func MarkRoi() {
//
// 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))};
//
// log.Print("fourcc: ", fourcc)
// log.Print("fps: ", fps)
// log.Print("size: ", size)
//
// defer video.Release()
win := opencv.NewWindow("Go-OpenCV Webcam")
defer win.Destroy()
win2 := opencv.NewWindow("rect cam: ")
win2.Move(400, 0)
defer win2.Destroy()
_, currentfile, _, _ := runtime.Caller(0)
var cascade = path.Join(path.Dir(currentfile), "/../cascades/haarcascade_eye_tree_eyeglasses.xml")
var eyeMarker = NewEyeMarker(cascade)
var cap = NewVideoCapture(path.Join(path.Dir(currentfile), "/../eyevid1.mp4"))
//var cap = NewVideoCapture("")
var rois []*opencv.Rect
for {
var frame = cap.GetFrame()
if frame == nil {
break
}
img := frame
var copy = opencv.CreateImage(img.Width(), img.Height(), opencv.IPL_DEPTH_8U, 3)
opencv.Copy(img, copy, nil)
rois = eyeMarker.MarkEyesRects(copy)
if len(rois) > 0 {
log.Print(rois[0])
copy.SetROI(*rois[0])
copy = ProcessRoi(copy, 25)
//var gray = opencv.CreateImage(copy.Width(),copy.Height(),opencv.IPL_DEPTH_8U,1)
//copy.SetROI(*rois[0])
var circels = HoughCircles1(copy)
log.Print(circels)
for i := 0; i < len(circels); i++ {
var center = opencv.Point{rois[0].X() + int(circels[i].X), rois[0].Y() + int(circels[0].Y)}
//var center = opencv.Point{int(circels[i].X),int(circels[0].Y)}
opencv.Circle(img, center, int(circels[i].R), opencv.NewScalar(255, 0, 0, 1), 1, 1, 0)
//src *IplImage, dp float64, min_dist float64, param1 float64, param2 float64, min_radius int, max_radius int
}
copy.ResetROI()
}
win.ShowImage(img)
win2.ShowImage(copy)
key := opencv.WaitKey(10)
if key == 27 {
os.Exit(0)
}
}
os.Exit(0)
}
示例14: main
func main() {
filename := "../images/fruits.jpg"
if len(os.Args) == 2 {
filename = os.Args[1]
}
img0 := opencv.LoadImage(filename)
if img0 == nil {
panic("LoadImage fail")
}
defer img0.Release()
fmt.Print("Hot keys: \n",
"\tESC - quit the program\n",
"\tr - restore the original image\n",
"\ti or ENTER - run inpainting algorithm\n",
"\t\t(before running it, paint something on the image)\n",
)
img := img0.Clone()
inpainted := img0.Clone()
inpaint_mask := opencv.CreateImage(img0.Width(), img0.Height(), 8, 1)
opencv.Zero(inpaint_mask)
//opencv.Zero( inpainted )
win := opencv.NewWindow("image")
defer win.Destroy()
prev_pt := opencv.Point{-1, -1}
win.SetMouseCallback(func(event, x, y, flags int, param ...interface{}) {
if img == nil {
os.Exit(0)
}
if event == opencv.CV_EVENT_LBUTTONUP ||
(flags&opencv.CV_EVENT_FLAG_LBUTTON) == 0 {
prev_pt = opencv.Point{-1, -1}
} else if event == opencv.CV_EVENT_LBUTTONDOWN {
prev_pt = opencv.Point{x, y}
} else if event == opencv.CV_EVENT_MOUSEMOVE &&
(flags&opencv.CV_EVENT_FLAG_LBUTTON) != 0 {
pt := opencv.Point{x, y}
if prev_pt.X < 0 {
prev_pt = pt
}
rgb := opencv.ScalarAll(255.0)
opencv.Line(inpaint_mask, prev_pt, pt, rgb, 5, 8, 0)
opencv.Line(img, prev_pt, pt, rgb, 5, 8, 0)
prev_pt = pt
win.ShowImage(img)
}
})
win.ShowImage(img)
opencv.WaitKey(0)
win2 := opencv.NewWindow("inpainted image")
defer win2.Destroy()
win2.ShowImage(inpainted)
for {
key := opencv.WaitKey(20)
if key == 27 {
os.Exit(0)
} else if key == 'r' {
opencv.Zero(inpaint_mask)
opencv.Copy(img0, img, nil)
win.ShowImage(img)
} else if key == 'i' || key == '\n' {
opencv.Inpaint(img, inpaint_mask, inpainted, 3,
opencv.CV_INPAINT_TELEA,
)
win2.ShowImage(inpainted)
}
}
os.Exit(0)
}
示例15: main
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)
}