for (auto it = begin(bboxes); it != end(bboxes); ++it) { Rect rec(it->at(0) - padding, it->at(1) - padding, it->at(2) - it->at(0) + 2*padding, it->at(3) - it->at(1) + 2*padding); Mat face = src(rec); // take the ROI of box on the frame
Mat blob; blob = blobFromImage(face, 1, Size(227, 227), MODEL_MEAN_VALUES, false); genderNet.setInput(blob); // string gender_preds; vector<float> genderPreds = genderNet.forward(); // printing gender here // find max element index // distance function does the argmax() work in C++ int max_index_gender = std::distance(genderPreds.begin(), max_element(genderPreds.begin(), genderPreds.end())); string gender = genderList[max_index_gender]; cout <"Gender: " /* // Uncomment if you want to iterate through the gender_preds vector for(auto it=begin(gender_preds); it != end(gender_preds); ++it) { cout < } */
ageNet.setInput(blob); vector<float> agePreds = ageNet.forward(); /* // uncomment below code if you want to iterate through the age_preds * vector cout < for(auto it = age_preds.begin(); it != age_preds.end(); ++it) { cout < } */
// finding maximum indicd in the age_preds vector int max_indice_age = std::distance(agePreds.begin(), max_element(agePreds.begin(), agePreds.end())); string age = ageList[max_indice_age]; cout <"Age: " string label = gender + ", " + age; // label cv::putText(dst, label, Point(it->at(0), it->at(1) -15), cv::FONT_HERSHEY_SIMPLEX, 1, Scalar(0, 255, 0), 4, cv::LINE_AA); } }
val faceProto = "${FileUtil.loadPath}opencv_face_detector.pbtxt" val faceModel = "${FileUtil.loadPath}opencv_face_detector_uint8.pb" val ageProto = "${FileUtil.loadPath}age_deploy.prototxt" val ageModel = "${FileUtil.loadPath}age_net.caffemodel" val genderProto = "${FileUtil.loadPath}gender_deploy.prototxt" val genderModel = "${FileUtil.loadPath}gender_net.caffemodel"