_pFace_detection_result = facedetect_cnn(_pBuffer, cvData.data, cvData.cols, cvData.rows, (int)(cvData.cols * cvData.channels()));
SINGLEO_LOGD("PrivateFaceService (Detection) takes %d ms", partial.check_ms());
+ int maxConfidence = 0;
+ int maxX, maxY, maxW, maxH;
+ bool isFaceDetected = false;
for(int i = 0; i < (_pFace_detection_result ? *_pFace_detection_result : 0); i++) {
short * p = ((short*)(_pFace_detection_result + 1)) + 16*i;
int confidence = p[0];
- if (confidence < 90)
+ if (confidence < 30 || maxConfidence >= confidence)
continue;
- int x = static_cast<int>(p[1]);
- int y = static_cast<int>(p[2]);
- int w = static_cast<int>(p[3]);
- int h = static_cast<int>(p[4]);
-
- if (isLandmarkDetectTask) {
- cv::Mat roiCvData = cvData(cv::Rect(x, y, w, h)).clone();
-
- Points landmarks;
- partial.reset();
- getLandmarks(roiCvData, landmarks, static_cast<int>(x * _xInvRatio), static_cast<int>(y * _yInvRatio));
- SINGLEO_LOGD("PrivateFaceService (Landmark) takes %d ms", partial.check_ms());
- if (!_filterLandmarks->isInit()) {
- SINGLEO_LOGD("%zd landmarks are detected", landmarks.size());
- _filterLandmarks->init(landmarks);
- _isSkipLandmarkDetectTask = true;
- } else {
- landmarks = _filterLandmarks->update(landmarks);
- _isSkipLandmarkDetectTask = true;
- }
-
- _result._landmarks.push_back(landmarks);
- }
-
- vector<Rect> rects = { { .left = static_cast<int>(x * _xInvRatio),
- .right = static_cast<int>( (x + w) * _xInvRatio),
- .top = static_cast<int>( y * _yInvRatio),
- .bottom = static_cast<int>( (y + h) * _yInvRatio) }};
+ maxConfidence = confidence;
+ maxX = static_cast<int>(p[1]);
+ maxY = static_cast<int>(p[2]);
+ maxW = static_cast<int>(p[3]);
+ maxH = static_cast<int>(p[4]);
+ isFaceDetected = true;
+ }
+ if (!isFaceDetected)
+ return;
- if (!_filterFaceRegion->isInit()) {
- _filterFaceRegion->init(rects);
- _isSkipDetectTask = true;
+ if (isLandmarkDetectTask) {
+ cv::Mat roiCvData = cvData(cv::Rect(maxX, maxY, maxW, maxH)).clone();
+
+ Points landmarks;
+ partial.reset();
+ getLandmarks(roiCvData, landmarks, static_cast<int>(maxX * _xInvRatio), static_cast<int>(maxY * _yInvRatio));
+ SINGLEO_LOGD("PrivateFaceService (Landmark) takes %d ms", partial.check_ms());
+ if (!_filterLandmarks->isInit()) {
+ SINGLEO_LOGD("%zd landmarks are detected", landmarks.size());
+ _filterLandmarks->init(landmarks);
+ _isSkipLandmarkDetectTask = true;
} else {
- rects = _filterFaceRegion->update(rects);
- _isSkipDetectTask = true;
+ landmarks = _filterLandmarks->update(landmarks);
+ _isSkipLandmarkDetectTask = true;
}
- _result._rects = rects;
- break;
+
+ _result._landmarks.push_back(landmarks);
+ }
+
+ vector<Rect> rects = { { .left = static_cast<int>( maxX * _xInvRatio ),
+ .right = static_cast<int>( (maxX + maxW) * _xInvRatio ),
+ .top = static_cast<int>( maxY * _yInvRatio ),
+ .bottom = static_cast<int>( (maxY + maxH) * _yInvRatio) }};
+
+ if (!_filterFaceRegion->isInit()) {
+ _filterFaceRegion->init(rects);
+ _isSkipDetectTask = true;
+ } else {
+ rects = _filterFaceRegion->update(rects);
+ _isSkipDetectTask = true;
}
+ _result._rects = rects;
} else if (isLandmarkDetectTask) {
Points landmarks;
getLandmarks(cvData, landmarks);