Skip to content

Commit 576e97f

Browse files
committed
fix mnnsr
1 parent 7471542 commit 576e97f

File tree

1 file changed

+9
-26
lines changed
  • RealSR-NCNN-Android-CLI/MNN-SR/src/main/jni

1 file changed

+9
-26
lines changed

RealSR-NCNN-Android-CLI/MNN-SR/src/main/jni/mnnsr.cpp

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ int MNNSR::process(const cv::Mat &inimage, cv::Mat &outimage, const cv::Mat &mas
279279

280280
if (!inMask.empty()) {
281281
int x0 = xi * tileWidth, x = xi == xtiles - 1 ? inWidth - xi * tileWidth :
282-
(xi + 1) * tileWidth, y0 = yi * tileHeight, y =
283-
yi == ytiles - 1 ? inHeight - yi * tileHeight : (yi + 1) * tileHeight;
282+
tileWidth, y0 = yi * tileHeight, y =
283+
yi == ytiles - 1 ? inHeight - yi * tileHeight : tileHeight;
284284
cv::Mat maskTile = inMask(cv::Rect(x0, y0, x, y));
285285

286286
// 判断maskTile是否全部为0
@@ -813,9 +813,6 @@ int MNNSR::decensor(const cv::Mat &inimage, cv::Mat &outimage) {
813813
}
814814
} // End if extrema_indices.size() >= 2
815815

816-
fprintf(stderr, "decensor: Detected Mosaic Resolution is: %d\n", MosaicResolutionOfImage);
817-
818-
819816
// --- 4. ESRGAN Processing ---
820817
// This part uses the detected MosaicResolutionOfImage.
821818
// Keeping the original decensor's approach of downscaling the whole image,
@@ -841,9 +838,8 @@ int MNNSR::decensor(const cv::Mat &inimage, cv::Mat &outimage) {
841838
Sx = std::max(1, Sx);
842839
Sy = std::max(1, Sy);
843840

844-
fprintf(stderr,
845-
"decensor: Resizing full input to (%d, %d) for processing. pre_scale=%.3f, loops=%d\n",
846-
Sx, Sy, pre_scale, loops);
841+
fprintf(stderr, "decensor: Mosaic Resolution: %d, pre_scale=%.3f, loops=%d\n",
842+
MosaicResolutionOfImage, pre_scale, loops);
847843

848844
cv::Mat shrinkedI;
849845
// Use INTER_AREA for downsampling, INTER_CUBIC for upsampling (later resize)
@@ -852,38 +848,25 @@ int MNNSR::decensor(const cv::Mat &inimage, cv::Mat &outimage) {
852848
cv::Mat esr_output_shrunken_scaled = shrinkedI; // Start the loop with the downscaled image
853849

854850
for (int i = 0; i < loops; i++) {
855-
fprintf(stderr, "decensor: processing SR loop %d/%d, input: %d*%d\n",
856-
i + 1, loops, esr_output_shrunken_scaled.rows, esr_output_shrunken_scaled.cols);
857-
858-
// Prepare output buffer for the current SR pass
859851
cv::Mat current_esr_output(esr_output_shrunken_scaled.rows * scale,
860852
esr_output_shrunken_scaled.cols * scale,
861853
CV_8UC3);
862854

863-
// Call MNNSR::process on the intermediate result
864-
// We pass the detected card_mask. The process function uses it to skip tiles.
855+
fprintf(stderr, "decensor: processing loop %d/%d, %d*%d -> %d*%d\n",
856+
i + 1, loops, esr_output_shrunken_scaled.rows, esr_output_shrunken_scaled.cols,
857+
current_esr_output.rows, current_esr_output.cols
858+
);
865859
if (process(esr_output_shrunken_scaled, current_esr_output, card_mask) != 0) {
866860
fprintf(stderr, "decensor error: MNNSR::process failed during SR loop %d.\n", i + 1);
867861
inimage.copyTo(outimage); // Fallback
868862
return -1;
869863
}
870-
871-
// The output of this pass becomes the input for the next pass
872-
// or the final result if this is the last pass.
873-
esr_output_shrunken_scaled = current_esr_output;
864+
current_esr_output.copyTo(esr_output_shrunken_scaled);
874865
}
875866

876867
fprintf(stderr, "decensor: Combining processed image with original...\n");
877-
878-
// The final result `esr_output_shrunken_scaled` is now total_model_upscale times
879-
// the initial `shrinkedI` size. We need to resize it back to the original image size.
880-
// Use INTER_CUBIC for upsampling or potentially INTER_LANCZOS4 for better quality if needed.
881868
cv::resize(esr_output_shrunken_scaled, processed_region_esr, inimage.size(), 0, 0,
882869
cv::INTER_CUBIC);
883-
884-
// Combine the processed ESRGAN output with the original image using the full card_mask
885-
// Regions in card_mask that are 255 will take pixels from processed_region_esr.
886-
// Regions in card_mask that are 0 will keep pixels from the original image.
887870
outimage = inimage.clone(); // Start with the original image content
888871

889872
// Ensure mask is strictly 0 or 255 if needed by copyTo, though CV_8U mask usually works.

0 commit comments

Comments
 (0)