forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opencv: Switchover to use GoCV and OpenCV 3.3
Signed-off-by: deadprogram <[email protected]>
- Loading branch information
1 parent
e333001
commit 3113178
Showing
12 changed files
with
156 additions
and
69 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
package opencv | ||
|
||
import cv "github.com/lazywei/go-opencv/opencv" | ||
import ( | ||
"github.com/hybridgroup/gocv" | ||
) | ||
|
||
type testCapture struct{} | ||
|
||
func (c *testCapture) RetrieveFrame(i int) *cv.IplImage { | ||
return &cv.IplImage{} | ||
} | ||
|
||
func (c *testCapture) GrabFrame() bool { | ||
func (c *testCapture) Read(img gocv.Mat) bool { | ||
return true | ||
} | ||
|
||
type testWindow struct{} | ||
|
||
func (w *testWindow) ShowImage(i *cv.IplImage) { return } | ||
func (w *testWindow) ShowImage(img gocv.Mat) { return } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,35 @@ | ||
package opencv | ||
|
||
import ( | ||
cv "github.com/lazywei/go-opencv/opencv" | ||
"image" | ||
"image/color" | ||
|
||
"github.com/hybridgroup/gocv" | ||
) | ||
|
||
var classifier *gocv.CascadeClassifier | ||
|
||
// loadHaarClassifierCascade returns open cv HaarCascade loaded | ||
func loadHaarClassifierCascade(haar string) *cv.HaarCascade { | ||
return cv.LoadHaarClassifierCascade(haar) | ||
func loadCascadeClassifier(haar string) *gocv.CascadeClassifier { | ||
if classifier != nil { | ||
return classifier | ||
} | ||
|
||
c := gocv.NewCascadeClassifier() | ||
c.Load(haar) | ||
classifier = &c | ||
return classifier | ||
} | ||
|
||
// DetectFaces loads Haar cascade to detect face objects in image | ||
func DetectFaces(haar string, image *cv.IplImage) []*cv.Rect { | ||
return loadHaarClassifierCascade(haar).DetectObjects(image) | ||
func DetectFaces(haar string, img gocv.Mat) []image.Rectangle { | ||
return loadCascadeClassifier(haar).DetectMultiScale(img) | ||
} | ||
|
||
// DrawRectangles uses Rect array values to return image with rectangles drawn. | ||
func DrawRectangles(image *cv.IplImage, rect []*cv.Rect, r int, g int, b int, thickness int) *cv.IplImage { | ||
for _, value := range rect { | ||
cv.Rectangle(image, | ||
cv.Point{value.X() + value.Width(), value.Y()}, | ||
cv.Point{value.X(), value.Y() + value.Height()}, | ||
cv.NewScalar(float64(b), float64(g), float64(r), 0), thickness, 1, 0) | ||
func DrawRectangles(img gocv.Mat, rects []image.Rectangle, r int, g int, b int, thickness int) { | ||
for _, rect := range rects { | ||
gocv.Rectangle(img, rect, color.RGBA{uint8(r), uint8(g), uint8(b), 0}, thickness) | ||
} | ||
return image | ||
return | ||
} |
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
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
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
Oops, something went wrong.