go-face icon indicating copy to clipboard operation
go-face copied to clipboard

Update API

Open Danile71 opened this issue 5 years ago • 10 comments

  • Big update
  • Add support opencv (cv::Mat)
  • Add gender support
  • Add age support
const cnn = "testdata/mmod_human_face_detector.dat"
const shape = "testdata/shape_predictor_68_face_landmarks.dat"
const descr = "testdata/dlib_face_recognition_resnet_model_v1.dat"
const gender = "testdata/dnn_gender_classifier_v1.dat"
const age = "testdata/dnn_age_predictor_v1.dat"

var green = color.RGBA{0, 255, 0, 0}
var thickness = 2

func main() {
	deviceID := "0"
	recognizer, err := face.NewRecognizer()
	if err != nil {
		fmt.Println(err)
		return
	}
	webcam, err := gocv.OpenVideoCapture(deviceID)
	if err != nil {
		fmt.Printf("Error opening video capture device: %v\n", deviceID)
		return
	}
	defer webcam.Close()

	webcam.Set(gocv.VideoCaptureFrameWidth, 320)
	webcam.Set(gocv.VideoCaptureFrameHeight, 240)

	window := gocv.NewWindow("Capture Window")
	defer window.Close()

	img := gocv.NewMat()
	defer img.Close()

	recognizer.SetCNNModel(cnn)
	recognizer.SetDescriptorModel(descr)
	recognizer.SetShapeModel(shape)
	recognizer.SetGenderModel(gender)
	recognizer.SetAgeModel(age)

	recognizer.SetSize(150)
	recognizer.SetPadding(0.25)
	recognizer.SetMinImageSize(200000)
	recognizer.SetJittering(0)

	fmt.Printf("Start reading device: %v\n", deviceID)
	for {
		if ok := webcam.Read(&img); !ok {
			fmt.Printf("Device closed: %v\n", deviceID)
			return
		}

		if img.Empty() {
			continue
		}

		start := time.Now()

		faces, err := recognizer.DetectFromMatCNN(img)
		if err != nil {
			fmt.Println(err)
			continue
		}

		for _, f := range faces {
			gocv.Rectangle(&img, f.Rectangle, green, thickness)
			recognizer.Recognize(&f)
			face.RenderFaceDetections(&img, f.Shapes, green, thickness)
			recognizer.GetGender(&f)
			recognizer.GetAge(&f)
			fmt.Println(f.Gender, f.Age)
			f.Close()
		}

		fmt.Println(time.Since(start))

		window.IMShow(img)
		if window.WaitKey(1) == 27 {
			break
		}
	}
}


go build -tags gocv

Danile71 avatar Feb 12 '20 13:02 Danile71

Снимок экрана в 2020-02-12 16-27-22 screen)

Danile71 avatar Feb 12 '20 13:02 Danile71

Sounds great! Does anybody going to approve this merge request?

tpoxa avatar Mar 22 '20 20:03 tpoxa

@tpoxa, Hi!) I am now checking changes and after I'll merge it. If you have some ideas, send it to [email protected]

Danile71 avatar Mar 22 '20 21:03 Danile71

Hi @Danile71 I decided to try your new API approach. I use the same docker environment to build library as for Kagami's Your branch fails to build with next error:

 wrapper.cc: In function 'facesret* facerec_detect_from_buffer(facerec*, unsigned char*, int, int)':
 wrapper.cc:103:39: error: no matching function for call to 'load_jpeg(image_t&, unsigned char*&, size_t)'
    load_jpeg(img, img_data, size_t(len));
                                        ^
 In file included from wrapper.cc:5:
 /usr/include/dlib/image_loader/jpeg_loader.h:91:10: note: candidate: 'template<class image_type> void dlib::load_jpeg(image_type&, const string&)'
      void load_jpeg (
           ^~~~~~~~~
 /usr/include/dlib/image_loader/jpeg_loader.h:91:10: note:   template argument deduction/substitution failed:
 wrapper.cc:103:39: note:   candidate expects 2 arguments, 3 provided
    load_jpeg(img, img_data, size_t(len));
                                        ^

Are there any new dependencies/requirements?

tpoxa avatar Mar 28 '20 09:03 tpoxa

Looks like Dlib version >=19.18 now is required...

tpoxa avatar Mar 28 '20 09:03 tpoxa

This looks great. I was about to write some of this myself. Is there an ETA on it being merged?

silverark avatar Aug 24 '20 21:08 silverark

@Danile71 Can u fix the github merge conflicts.

Please send me a msg; I might have a project for u.

ghost avatar Sep 13 '20 21:09 ghost

This looks great, especially recognizer.DetectFromMatCNN which would be amazing! I'm looking forward to the merge.

agorman avatar Feb 24 '21 02:02 agorman

any news about this one ?

instabledesign avatar Nov 09 '21 20:11 instabledesign

any news about this one ?

This repo has been abandoned, just use C++ version of it.

ghost avatar Nov 09 '21 23:11 ghost