improved jellyfin support
This commit is contained in:
@@ -129,6 +129,13 @@ static FaceResult process(const std::string& path,
|
||||
|
||||
std::vector<DetectedFace> faces = detect(img);
|
||||
|
||||
if (faces.empty()) {
|
||||
cv::Mat enhanced = enhance_for_retry(img);
|
||||
faces = detect(enhanced);
|
||||
if (!faces.empty())
|
||||
img = enhanced;
|
||||
}
|
||||
|
||||
if (faces.empty()) {
|
||||
res.error = "no face detected";
|
||||
return res;
|
||||
|
||||
@@ -66,6 +66,12 @@ public:
|
||||
}
|
||||
|
||||
std::vector<DetectedFace> faces = detector_->detect(img);
|
||||
if (faces.empty()) {
|
||||
cv::Mat enhanced = enhance_for_retry(img);
|
||||
faces = detector_->detect(enhanced);
|
||||
if (!faces.empty())
|
||||
img = enhanced;
|
||||
}
|
||||
if (faces.empty()) {
|
||||
res.error = "no face detected";
|
||||
return res;
|
||||
|
||||
@@ -24,6 +24,28 @@ inline cv::Mat align_face(const cv::Mat& img,
|
||||
return crop;
|
||||
}
|
||||
|
||||
// ── enhance_for_retry ────────────────────────────────────────────────────────
|
||||
// Used when initial face detection finds nothing. Pads the image by 50%
|
||||
// (border-replicated, so the detector doesn't see a hard edge) and applies
|
||||
// CLAHE to boost local contrast, giving the detector a second try.
|
||||
inline cv::Mat enhance_for_retry(const cv::Mat& img) {
|
||||
cv::Mat padded;
|
||||
const int pad_x = img.cols / 4;
|
||||
const int pad_y = img.rows / 4;
|
||||
cv::copyMakeBorder(img, padded, pad_y, pad_y, pad_x, pad_x, cv::BORDER_REPLICATE);
|
||||
|
||||
cv::Mat lab;
|
||||
cv::cvtColor(padded, lab, cv::COLOR_BGR2Lab);
|
||||
std::vector<cv::Mat> channels;
|
||||
cv::split(lab, channels);
|
||||
cv::createCLAHE(2.0, cv::Size(8, 8))->apply(channels[0], channels[0]);
|
||||
cv::merge(channels, lab);
|
||||
|
||||
cv::Mat out;
|
||||
cv::cvtColor(lab, out, cv::COLOR_Lab2BGR);
|
||||
return out;
|
||||
}
|
||||
|
||||
// ── l2_normalise ──────────────────────────────────────────────────────────────
|
||||
inline Embedding l2_normalise(const float* row) {
|
||||
float norm = 0.f;
|
||||
|
||||
Reference in New Issue
Block a user