-
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.
- Loading branch information
Showing
5 changed files
with
24,436 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/PyMarcus/go_imagerecognizer | ||
|
||
go 1.20 | ||
|
||
require gocv.io/x/gocv v0.33.0 // indirect |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/hybridgroup/mjpeg v0.0.0-20140228234708-4680f319790e/go.mod h1:eagM805MRKrioHYuU7iKLUyFPVKqVV6um5DAvCkUtXs= | ||
github.com/pascaldekloe/goe v0.1.0/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= | ||
gocv.io/x/gocv v0.33.0 h1:WDtaBrq92AKrhepYzEktydDzNSm3t5k7ciawZK4rns8= | ||
gocv.io/x/gocv v0.33.0/go.mod h1:oc6FvfYqfBp99p+yOEzs9tbYF9gOrAQSeL/dyIPefJU= |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package main | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
"log" | ||
|
||
"gocv.io/x/gocv" | ||
) | ||
|
||
/* | ||
INSTALATION: | ||
1)go install gocv.io/x/gocv | ||
2)export CGO_CPPFLAGS="-I/usr/local/include" | ||
3)export CGO_LDFLAGS="-L/usr/local/lib -lopencv_core -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d" | ||
4)sudo pacman -S opencv python-opencv | ||
*/ | ||
func applyGrayScale(img *gocv.Mat) *gocv.Mat{ | ||
log.Println("Applyng gray scale...") | ||
grayImg := gocv.NewMat() | ||
gocv.CvtColor(*img, &grayImg, gocv.ColorBGRToGray) | ||
return &grayImg | ||
} | ||
|
||
func faceRecognition(img *gocv.Mat){ | ||
log.Println("Performing face detection...") | ||
|
||
trainedXMLfile := "./trained_model/frontal.xml" | ||
|
||
classifier := gocv.NewCascadeClassifier() | ||
defer classifier.Close() | ||
|
||
if !classifier.Load(trainedXMLfile){ | ||
log.Fatalln("Error to load classifier") | ||
} | ||
|
||
rects := classifier.DetectMultiScale(*img) | ||
drawRectanglesAroundDetectedFaces(rects, img) | ||
|
||
} | ||
|
||
func drawRectanglesAroundDetectedFaces(rect []image.Rectangle, img *gocv.Mat){ | ||
for _, r := range rect{ | ||
gocv.Rectangle(img, r, color.RGBA{255, 0, 0, 0}, 2) | ||
} | ||
} | ||
|
||
func showImageDetected(img *gocv.Mat){ | ||
window := gocv.NewWindow("Face detection") | ||
defer window.Close() | ||
window.IMShow(*img) | ||
|
||
// wait for a press key | ||
window.WaitKey(0) | ||
} | ||
|
||
func main(){ | ||
log.Println("starting recognition...") | ||
img := gocv.IMRead("./face.jpg", gocv.IMReadColor) | ||
if img.Empty() { | ||
log.Fatalln("error to open image") | ||
} | ||
defer img.Close() | ||
|
||
log.Println("Image has been found!") | ||
|
||
defer applyGrayScale(&img).Close() | ||
|
||
faceRecognition(&img) | ||
|
||
showImageDetected(&img) | ||
|
||
} | ||
|
Oops, something went wrong.