Skip to content

Commit 33824f7

Browse files
committed
update mnn-sr and readme
1 parent 0650139 commit 33824f7

File tree

9 files changed

+315
-261
lines changed

9 files changed

+315
-261
lines changed

README.md

Lines changed: 2 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -56,83 +56,11 @@ Another way to convert models:
5656

5757
![](chainner-pth2ncnn.png)
5858

59-
## How to build RealSR-NCNN-Android-CLI
60-
### step1
61-
https://github.com/Tencent/ncnn/releases
62-
download ncnn-yyyymmdd-android-vulkan-shared.zip.
63-
https://github.com/webmproject/libwebp
64-
download the source of libwebp.
65-
https://opencv.org/releases/
66-
download opencv-android-sdk.
67-
68-
### step2
69-
extract `ncnn-yyyymmdd-android-vulkan-shared.zip` into `../3rdparty/ncnn-android-vulkan-shared`
70-
extract the source of libwebp into `../3rdparty/libwebp`
71-
extract `opencv-version-android-sdk` into `../3rdparty/opencv-android-sdk`
72-
```
73-
RealSR-NCNN-Android
74-
├─3rdparty
75-
│ ├─opencv-android-sdk
76-
│ │ └─sdk
77-
│ ├─libwebp
78-
│ └─ncnn-android-vulkan-shared
79-
│ └─arm64-v8a
80-
├─RealSR-NCNN-Android-CLI
81-
│ ├─Anime4k
82-
│ ├─RealCUGAN
83-
│ ├─Waifu2x
84-
│ ├─RealSR
85-
│ ├─SRMD
86-
│ └─ReSize
87-
└─RealSR-NCNN-Android-GUI
88-
```
89-
90-
### step3
91-
Open this project with Android Studio, rebuild it and the build result in `RealSR-NCNN-Android-CLI\*\build\intermediates\cmake\release\obj\arm64-v8a` or `RealSR-NCNN-Android-CLI\*\build\intermediates\cmake\debug\obj\arm64-v8a` could copy to the GUI project automatilly.
92-
Click `3rdparty/copy_cli_build_result.bat` and it could copy the other files to GUI project.
93-
94-
95-
## How to use RealSR-NCNN-Android-CLI
96-
### Download models
97-
You could download `assets.zip` from github release page and unzip it to get models, or download models from https://github.com/tumuyan/realsr-models .
98-
99-
### Example Command
100-
Make sure the elf file has execute permission. Then input command
101-
102-
```shell
103-
./realsr-ncnn -i input.jpg -o output.jpg
104-
```
105-
106-
### Full Usages
107-
The usage of others program is same as realsr-ncnn.
108-
```console
109-
Usage: realsr-ncnn -i infile -o outfile [options]...
110-
111-
-h show this help
112-
-v verbose output
113-
-i input-path input image path (jpg/png/webp) or directory
114-
-o output-path output image path (jpg/png/webp) or directory
115-
-s scale upscale ratio (4, default=4)
116-
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
117-
-m model-path realsr model path (default=models-DF2K_JPEG)
118-
-g gpu-id gpu device to use (default=0) can be 0,1,2 for multi-gpu, -1 use cpu
119-
-j load:proc:save thread count for load/proc/save (default=1:2:2) can be 1:2,2,2:2 for multi-gpu
120-
-x enable tta mode
121-
-f format output image format (jpg/png/webp, default=ext/png)
122-
```
123-
124-
- `input-path` and `output-path` accept either file path or directory path
125-
- `scale` = scale level, 4 = upscale 4x
126-
- `tile-size` = tile size, use smaller value to reduce GPU memory usage, default selects automatically
127-
- `load:proc:save` = thread count for the three stages (image decoding + realsr upscaling + image encoding), using larger values may increase GPU usage and consume more GPU memory. You can tune this configuration with "4:4:4" for many small-size images, and "2:2:2" for large-size images. The default setting usually works fine for most situations. If you find that your GPU is hungry, try increasing thread count to achieve faster processing.
128-
- `format` = the format of the image to be output, png is better supported, however webp generally yields smaller file sizes, both are losslessly encoded
129-
130-
If you encounter crash or error, try to upgrade your derive
131-
13259
## How to build RealSR-NCNN-Android-GUI
133-
Download `assets.zip` from github release page, the zip file contains models & elf files. Unzip and put them to this folder, then build it with Android Studio.
60+
Build `RealSR-NCNN-Android-CLI` by yourself or download `assets.zip` from github release page, the zip file contains models & elf files. Unzip and put them to this folder, then build it with Android Studio.
13461
The direct download link for current version: https://github.com/tumuyan/RealSR-NCNN-Android/releases/download/1.10.0/assets.zip
13562

63+
13664
```
13765
RealSR-NCNN-Android-GUI\app\src\main\assets\
13866
└─realsr

README_CHS.md

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -75,72 +75,6 @@ models-Real-ESRGAN-AnimeSharp // 目录需要用 models- 开头
7575

7676
![](chainner-pth2ncnn.png)
7777

78-
## 如何编译 RealSR-NCNN-Android-CLI
79-
### step1
80-
https://github.com/Tencent/ncnn/releases
81-
下载 `ncnn-yyyymmdd-android-vulkan-shared.zip` 或者你自己编译ncnn为so文件
82-
https://github.com/webmproject/libwebp
83-
下载libwebp的源码
84-
https://opencv.org/releases/
85-
下载opencv-android-sdk
86-
87-
### step2
88-
解压 `ncnn-yyyymmdd-android-vulkan-shared.zip``../3rdparty/ncnn-android-vulkan-shared`
89-
解压libwebp源码到`../3rdparty/libwebp`
90-
解压 `opencv-version-android-sdk``../3rdparty/opencv-android-sdk`
91-
92-
```
93-
RealSR-NCNN-Android
94-
├─3rdparty
95-
96-
│ ├─opencv-android-sdk
97-
│ │ └─sdk
98-
│ ├─libwebp
99-
│ └─ncnn-android-vulkan-shared
100-
│ └─arm64-v8a
101-
├─RealSR-NCNN-Android-CLI
102-
│ ├─Anime4k
103-
│ ├─RealCUGAN
104-
│ ├─Waifu2x
105-
│ ├─RealSR
106-
│ ├─SRMD
107-
│ └─ReSize
108-
└─RealSR-NCNN-Android-GUI
109-
```
110-
111-
### step3
112-
用 Android Studio 打开工程, rebuild 然后你就可以在 `RealSR-NCNN-Android-CLI\*\build\intermediates\cmake\release\obj\arm64-v8a``RealSR-NCNN-Android-CLI\*\build\intermediates\cmake\debug\obj\arm64-v8a` 找到编译好的二进制文件,这些文件会被编译脚本自动复制到 GUI 工程目录中。
113-
点击 `3rdparty/copy_cli_build_result.bat` 可以更新其他库文件的二进制文件到 GUI 工程目录中
114-
115-
## 如何使用 RealSR-NCNN-Android-CLI
116-
### 下载模型
117-
你可以从 github release 页面下载 `assets.zip`, 或者从 https://github.com/tumuyan/realsr-models 下载所需模型,需要注意不同程序需要用对应的模型
118-
119-
### 命令范例
120-
确认程序有执行权限,然后输入命令:
121-
```shell
122-
./realsr-ncnn -i input.jpg -o output.jpg
123-
```
124-
125-
### 完整用法
126-
仅以 realsr-ncnn 为例说明,其他程序使用方法完全相同,故不重复说明
127-
```console
128-
用法: realsr-ncnn -i 输入的图片路径 -o 输出的图片路径 [其他可选参数]...
129-
130-
-h 显示帮助
131-
-v 显示更多输出内容
132-
-i input-path 输入的图片路径(jpg/png/webp路径或者目录路径)
133-
-o output-path 输出的图片路径(jpg/png/webp路径或者目录路径)
134-
-s scale 缩放系数(默认4,即放大4倍)
135-
-t tile-size tile size (>=32/0=auto, default=0) can be 0,0,0 for multi-gpu
136-
-m model-path 模型路径 (默认模型 models-Real-ESRGAN-anime)
137-
-g gpu-id gpu,-1使用CPU,默认0 多GPU可选 0,1,2
138-
-j load:proc:save 解码/处理/保存的线程数 (默认1:2:2) 多GPU可以设 1:2,2,2:2
139-
-x 开启tta模式
140-
-f format 输出格式(jpg/png/webp, 默认ext/png)
141-
142-
```
143-
14478
## 如何编译 RealSR-NCNN-Android-GUI
14579
从 github release 页面下载 `assets.zip` , 其中包含了模型和CLI程序, 解压并放置到如下路径, 然后使用 Android Studio 进行编译。
14680
当前版本的下载连接为 https://github.com/tumuyan/RealSR-NCNN-Android/releases/download/1.10.0/assets.zip

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

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ void *load(void *args) {
266266
// 判断 alpha 通道是否为单一颜色
267267
if (countNonZero(alphaChannel != alphaChannel.at<uchar>(0, 0)) == 0) {
268268
fprintf(stderr, "ignore alpha channel, %s\n", imagepath.c_str());
269+
c = 3;
269270
} else {
270271
v.inalpha = alphaChannel;
271-
c = 3;
272272
}
273273
merge(channels.data(), 3, inimage);
274274
v.inimage = inimage;
@@ -407,24 +407,6 @@ void *save(void *args) {
407407

408408
high_resolution_clock::time_point begin = high_resolution_clock::now();
409409

410-
// free input pixel data
411-
{
412-
unsigned char *pixeldata = (unsigned char *) v.inimage.data;
413-
414-
415-
fprintf(stderr, "save result...\n");
416-
417-
if (v.webp == 1) {
418-
free(pixeldata);
419-
} else {
420-
#if _WIN32
421-
free(pixeldata);
422-
#else
423-
stbi_image_free(pixeldata);
424-
#endif
425-
}
426-
}
427-
428410
int success = 0;
429411

430412
path_t ext = get_file_extension(v.outpath);
@@ -446,15 +428,27 @@ void *save(void *args) {
446428
} else {
447429
if (!v.inalpha.empty()) {
448430

431+
fprintf(stderr, "get alpha\n");
449432
// 放大 alpha 通道
450433
cv::Mat scaledAlphaChannel;
451434
cv::resize(v.inalpha, scaledAlphaChannel, cv::Size(), v.scale, v.scale,
452435
cv::INTER_LINEAR);
453436
// 将放大的 alpha 通道赋值给输出图像的 alpha 通道
454437
std::vector<cv::Mat> outChannels;
455438
cv::split(v.outimage, outChannels);
439+
440+
fprintf(stderr, "copy alpha\n");
456441
scaledAlphaChannel.copyTo(outChannels[3]); // 更新 alpha 通道
457-
cv::merge(outChannels, v.outimage); // 合并回输出图像
442+
443+
cv::Mat outputImageWithAlpha(v.outimage.rows, v.outimage.cols, CV_8UC4);
444+
445+
fprintf(stderr, "merge alpha\n");
446+
cv::merge(outChannels, outputImageWithAlpha); // 合并回输出图像
447+
448+
fprintf(stderr, "merge finishe\n");
449+
v.outimage = outputImageWithAlpha;
450+
451+
fprintf(stderr, "merge alpha done\n");
458452
}
459453

460454
#if _WIN32

0 commit comments

Comments
 (0)