Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update API #43

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open

Update API #43

wants to merge 36 commits into from

Conversation

Danile71
Copy link
Collaborator

@Danile71 Danile71 commented Feb 12, 2020

  • 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
Copy link
Collaborator Author

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

* if you want use 'gocv' - build -tags gocv
This reverts commit 2169ac8.
This reverts commit 0ecff40.
This reverts commit afd8030.
This reverts commit e394049.
This reverts commit dc77bcd.
@Danile71 Danile71 requested a review from Kagami February 13, 2020 13:20
@Danile71 Danile71 changed the title DNM Update API Update API Feb 18, 2020
@tpoxa
Copy link

tpoxa commented Mar 22, 2020

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

@Danile71
Copy link
Collaborator Author

@tpoxa, Hi!) I am now checking changes and after I'll merge it.
If you have some ideas, send it to danile71@gmail.com

@tpoxa
Copy link

tpoxa commented Mar 28, 2020

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
Copy link

tpoxa commented Mar 28, 2020

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

@silverark
Copy link

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

@ghost
Copy link

ghost commented Sep 13, 2020

@Danile71
Can u fix the github merge conflicts.

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

@agorman
Copy link

agorman commented Feb 24, 2021

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

@instabledesign
Copy link

any news about this one ?

@ghost
Copy link

ghost commented Nov 9, 2021

any news about this one ?

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants