Fix indentions.

This commit is contained in:
Bert Chang 2014-01-16 11:46:19 +08:00
parent 41ec01563c
commit d511e25516
5 changed files with 57 additions and 57 deletions

View file

@ -7,15 +7,15 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path"
"runtime" "runtime"
//"github.com/lazywei/go-opencv/opencv" //"github.com/lazywei/go-opencv/opencv"
"../opencv" // can be used in forks, comment in real application "../opencv" // can be used in forks, comment in real application
) )
func main() { func main() {
_, currentfile, _, _ := runtime.Caller(0) _, currentfile, _, _ := runtime.Caller(0)
filename := path.Join(path.Dir(currentfile), "../images/lena.jpg") filename := path.Join(path.Dir(currentfile), "../images/lena.jpg")
if len(os.Args) == 2 { if len(os.Args) == 2 {
filename = os.Args[1] filename = os.Args[1]
@ -79,5 +79,3 @@ func main() {
os.Exit(0) os.Exit(0)
} }

View file

@ -7,15 +7,15 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path"
"runtime" "runtime"
//"github.com/lazywei/go-opencv/opencv" //"github.com/lazywei/go-opencv/opencv"
"../opencv" // can be used in forks, comment in real application "../opencv" // can be used in forks, comment in real application
) )
func main() { func main() {
_, currentfile, _, _ := runtime.Caller(0) _, currentfile, _, _ := runtime.Caller(0)
filename := path.Join(path.Dir(currentfile), "../images/lena.jpg") filename := path.Join(path.Dir(currentfile), "../images/lena.jpg")
if len(os.Args) == 2 { if len(os.Args) == 2 {
filename = os.Args[1] filename = os.Args[1]
@ -43,5 +43,3 @@ func main() {
opencv.WaitKey(0) opencv.WaitKey(0)
} }

View file

@ -7,15 +7,15 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path" "path"
"runtime" "runtime"
//"github.com/lazywei/go-opencv/opencv" //"github.com/lazywei/go-opencv/opencv"
"../opencv" // can be used in forks, comment in real application "../opencv" // can be used in forks, comment in real application
) )
func main() { func main() {
_, currentfile, _, _ := runtime.Caller(0) _, currentfile, _, _ := runtime.Caller(0)
filename := path.Join(path.Dir(currentfile), "../images/fruits.jpg") filename := path.Join(path.Dir(currentfile), "../images/fruits.jpg")
if len(os.Args) == 2 { if len(os.Args) == 2 {
filename = os.Args[1] filename = os.Args[1]
@ -94,5 +94,3 @@ func main() {
} }
os.Exit(0) os.Exit(0)
} }

View file

@ -7,10 +7,8 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"runtime"
//"github.com/lazywei/go-opencv/opencv" //"github.com/lazywei/go-opencv/opencv"
"../opencv" // can be used in forks, comment in real application "../opencv" // can be used in forks, comment in real application
) )
@ -58,18 +56,26 @@ func main() {
for { for {
if !stop { if !stop {
img := cap.QueryFrame() img := cap.QueryFrame()
if img == nil { break } if img == nil {
break
}
frame_pos := int(cap.GetProperty(opencv.CV_CAP_PROP_POS_FRAMES)) frame_pos := int(cap.GetProperty(opencv.CV_CAP_PROP_POS_FRAMES))
if frame_pos >= frames { break } if frame_pos >= frames {
break
}
win.SetTrackbarPos("Seek", frame_pos) win.SetTrackbarPos("Seek", frame_pos)
win.ShowImage(img) win.ShowImage(img)
key := opencv.WaitKey(1000/fps) key := opencv.WaitKey(1000 / fps)
if key == 27 { os.Exit(0) } if key == 27 {
os.Exit(0)
}
} else { } else {
key := opencv.WaitKey(20) key := opencv.WaitKey(20)
if key == 27 { os.Exit(0) } if key == 27 {
os.Exit(0)
}
} }
} }

View file

@ -1,12 +1,12 @@
package main package main
import ( import (
"fmt" "fmt"
"os" "os"
//"path" //"path"
//"runtime" //"runtime"
//"github.com/lazywei/go-opencv/opencv" //"github.com/lazywei/go-opencv/opencv"
"../opencv" // can be used in forks, comment in real application "../opencv" // can be used in forks, comment in real application
) )
@ -14,29 +14,29 @@ func main() {
win := opencv.NewWindow("Go-OpenCV Webcam") win := opencv.NewWindow("Go-OpenCV Webcam")
defer win.Destroy() defer win.Destroy()
cap := opencv.NewCameraCapture(0) cap := opencv.NewCameraCapture(0)
if cap == nil { if cap == nil {
panic("can not open camera") panic("can not open camera")
} }
defer cap.Release() defer cap.Release()
win.CreateTrackbar("Thresh", 1, 100, func(pos int, param ...interface{}) { win.CreateTrackbar("Thresh", 1, 100, func(pos int, param ...interface{}) {
for { for {
if cap.GrabFrame() { if cap.GrabFrame() {
img := cap.RetrieveFrame(1) img := cap.RetrieveFrame(1)
if img != nil { if img != nil {
ProcessImage(img, win, pos) ProcessImage(img, win, pos)
} else { } else {
fmt.Println("Image ins nil") fmt.Println("Image ins nil")
} }
} }
if key := opencv.WaitKey(10); key == 27 { if key := opencv.WaitKey(10); key == 27 {
os.Exit(0) os.Exit(0)
} }
} }
}) })
opencv.WaitKey(0) opencv.WaitKey(0)
} }
func ProcessImage(img *opencv.IplImage, win *opencv.Window, pos int) error { func ProcessImage(img *opencv.IplImage, win *opencv.Window, pos int) error {
@ -55,16 +55,16 @@ func ProcessImage(img *opencv.IplImage, win *opencv.Window, pos int) error {
opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY) opencv.CvtColor(img, gray, opencv.CV_BGR2GRAY)
opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0) opencv.Smooth(gray, edge, opencv.CV_BLUR, 3, 3, 0, 0)
opencv.Not(gray, edge) opencv.Not(gray, edge)
// Run the edge detector on grayscale // Run the edge detector on grayscale
opencv.Canny(gray, edge, float64(pos), float64(pos*3), 3) opencv.Canny(gray, edge, float64(pos), float64(pos*3), 3)
opencv.Zero(cedge) opencv.Zero(cedge)
// copy edge points // copy edge points
opencv.Copy(img, cedge, edge) opencv.Copy(img, cedge, edge)
win.ShowImage(cedge) win.ShowImage(cedge)
return nil return nil
} }