isDetectTask = true;
_pFace_detection_result = nullptr;
_pBuffer = new unsigned char[DETECT_BUFFER_SIZE];
+
+ _xDownSizeRatio = 0.5f;
+ _yDownSizeRatio = 0.5f;
+ _xInvRatio = 1.0f / _xDownSizeRatio;
+ _yInvRatio = 1.0f / _yDownSizeRatio;
}
break;
case TaskType::FACE_LANDMARK_DETECTION:
if (ret != MEDIA_VISION_ERROR_NONE)
throw runtime_error("Fail to get face landmark detection bound box.");
+ landmark.x *= _yInvRatio;
+ landmark.y *= _yInvRatio;
landmark.x += roi_left;
landmark.y += roi_right;
landmarks.push_back(landmark);
}
ImageDataType &data = dynamic_cast<ImageDataType &>(input);
- cv::Mat cvData(cv::Size(data.width, data.height), CV_MAKE_TYPE(CV_8U, data.byte_per_pixel), data.ptr);
+ // cv::Mat cvData(cv::Size(data.width, data.height), CV_MAKE_TYPE(CV_8U, data.byte_per_pixel), data.ptr);
+ cv::Mat cvData_(cv::Size(data.width, data.height), CV_MAKE_TYPE(CV_8U, data.byte_per_pixel), data.ptr);
+ // resize cvData then do inference then back to results.
+ cv::Mat cvData;
+ cv::resize(cvData_, cvData, cv::Size(static_cast<int>(cvData_.cols * _xDownSizeRatio), static_cast<int>(cvData_.rows * _yDownSizeRatio)));
_result._rects.clear();
_result._landmarks.clear();
if (isDetectTask) {
partial.reset();
- _pFace_detection_result = facedetect_cnn(_pBuffer, data.ptr, data.width, data.height, (int)(data.width*data.byte_per_pixel));
+ // _pFace_detection_result = facedetect_cnn(_pBuffer, data.ptr, data.width, data.height, (int)(data.width*data.byte_per_pixel));
+ _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());
for(int i = 0; i < (_pFace_detection_result ? *_pFace_detection_result : 0); i++) {
- Rect rect;
+
short * p = ((short*)(_pFace_detection_result + 1)) + 16*i;
// int confidence = p[0];
- rect.left = static_cast<int>(p[1]);
- rect.top = static_cast<int>(p[2]);
- rect.right = rect.left + static_cast<int>(p[3]);
- rect.bottom = rect.top + static_cast<int>(p[4]);
-
- _result._rects.push_back(rect);
+ 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(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)).clone();
+ cv::Mat roiCvData = cvData(cv::Rect(x, y, w, h)).clone();
Points landmarks;
partial.reset();
- getLandmarks(roiCvData, landmarks, rect.left, rect.top);
+ getLandmarks(roiCvData, landmarks, static_cast<int>(x * _xInvRatio), static_cast<int>(y * _yInvRatio));
SINGLEO_LOGD("PrivateFaceService (Landmark) takes %d ms", partial.check_ms());
_result._landmarks.push_back(landmarks);
}
+
+ Rect rect = { .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) };
+
+ _result._rects.push_back(rect);
}
} else if (isLandmarkDetectTask) {
Points landmarks;
SINGLEO_LOGD("PrivateFaceService takes %d ms", timer.check_ms());
int id = 0;
for (auto &rect : _result._rects) {
- cv::rectangle(cvData, cv::Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), cv::Scalar(0, 255, 0), 2);
+ cv::rectangle(cvData_, cv::Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top), cv::Scalar(0, 255, 0), 2);
auto &points = _result._landmarks[id];
for (auto &point : points)
- cv::circle(cvData, cv::Point(point.x, point.y), 2, cv::Scalar(255, 255, 0), 2);
+ cv::circle(cvData_, cv::Point(point.x, point.y), 2, cv::Scalar(255, 255, 0), 2);
id++;
}
- cv::cvtColor(cvData, cvData, cv::COLOR_RGB2BGR);
+ cv::cvtColor(cvData_, cvData_, cv::COLOR_RGB2BGR);
+ cv::imwrite("dump_privateFace.jpg", cvData_);
}
FaceResult& PrivateInferenceFaceService::result()