Skip to content

Commit

Permalink
[Android] Refine the mask detection demo (PaddlePaddle#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
hong19860320 committed Apr 4, 2020
1 parent 25b5040 commit 583ce60
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ void FaceDetector::Postprocess(const cv::Mat &rgbaImage,
}
}

void FaceDetector::Predict(const cv::Mat &rgbImage, std::vector<Face> *faces,
void FaceDetector::Predict(const cv::Mat &rgbaImage, std::vector<Face> *faces,
double *preprocessTime, double *predictTime,
double *postprocessTime) {
auto t = GetCurrentTime();

t = GetCurrentTime();
Preprocess(rgbImage);
Preprocess(rgbaImage);
*preprocessTime = GetElapsedTime(t);
LOGD("Face detector postprocess costs %f ms", *preprocessTime);

Expand All @@ -94,7 +94,7 @@ void FaceDetector::Predict(const cv::Mat &rgbImage, std::vector<Face> *faces,
LOGD("Face detector predict costs %f ms", *predictTime);

t = GetCurrentTime();
Postprocess(rgbImage, faces);
Postprocess(rgbaImage, faces);
*postprocessTime = GetElapsedTime(t);
LOGD("Face detector postprocess costs %f ms", *postprocessTime);
}
Expand All @@ -116,7 +116,7 @@ MaskClassifier::MaskClassifier(const std::string &modelDir,
config);
}

void MaskClassifier::Preprocess(const cv::Mat &rgbImage,
void MaskClassifier::Preprocess(const cv::Mat &rgbaImage,
const std::vector<Face> &faces) {
// Prepare input tensor
auto inputTensor = predictor_->GetInput(0);
Expand Down Expand Up @@ -145,8 +145,8 @@ void MaskClassifier::Preprocess(const cv::Mat &rgbImage,
}
}
cv::Mat resizedRGBAImage(
rgbImage, cv::Rect(cx - w / 2, cy - h / 2, w, h) &
cv::Rect(0, 0, rgbImage.cols - 1, rgbImage.rows - 1));
rgbaImage, cv::Rect(cx - w / 2, cy - h / 2, w, h) &
cv::Rect(0, 0, rgbaImage.cols - 1, rgbaImage.rows - 1));
cv::resize(resizedRGBAImage, resizedRGBAImage,
cv::Size(inputShape[3], inputShape[2]), 0.0f, 0.0f,
cv::INTER_CUBIC);
Expand Down Expand Up @@ -180,13 +180,13 @@ void MaskClassifier::Postprocess(std::vector<Face> *faces) {
}
}

void MaskClassifier::Predict(const cv::Mat &rgbImage, std::vector<Face> *faces,
void MaskClassifier::Predict(const cv::Mat &rgbaImage, std::vector<Face> *faces,
double *preprocessTime, double *predictTime,
double *postprocessTime) {
auto t = GetCurrentTime();

t = GetCurrentTime();
Preprocess(rgbImage, *faces);
Preprocess(rgbaImage, *faces);
*preprocessTime = GetElapsedTime(t);
LOGD("Mask classifier postprocess costs %f ms", *preprocessTime);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ class FaceDetector {
const std::vector<float> &inputStd,
float scoreThreshold);

void Predict(const cv::Mat &rgbImage, std::vector<Face> *faces,
void Predict(const cv::Mat &rgbaImage, std::vector<Face> *faces,
double *preprocessTime, double *predictTime,
double *postprocessTime);

private:
void Preprocess(const cv::Mat &rgbImage);
void Postprocess(const cv::Mat &rgbImage, std::vector<Face> *faces);
void Preprocess(const cv::Mat &rgbaImage);
void Postprocess(const cv::Mat &rgbaImage, std::vector<Face> *faces);

private:
float inputScale_;
Expand All @@ -70,7 +70,7 @@ class MaskClassifier {
double *postprocessTime);

private:
void Preprocess(const cv::Mat &rgbImage, const std::vector<Face> &faces);
void Preprocess(const cv::Mat &rgbaImage, const std::vector<Face> &faces);
void Postprocess(std::vector<Face> *faces);

private:
Expand Down

0 comments on commit 583ce60

Please sign in to comment.