ArchieMeng / ncnn-android-waifu2x-demo

The initial working version of Waifu2x ncnn with core Waifu2x JNI
Apache License 2.0
12 stars 0 forks source link

The ncnn::mat output is not written to the bitmap after processing. #3

Open laverne01 opened 2 months ago

laverne01 commented 2 months ago

I am having trouble understanding your code, specifically at line 137 in the file waifu2x_jni.cpp (waifu2x->process(in, out);). It seems that after the model processes, the ncnn::Mat out is not being written to out_bitmap. Is that the case? I hope you can explain this to me. Thank you.

ArchieMeng commented 1 month ago

Good question. Please refer to this commit https://github.com/ArchieMeng/ncnn-android-waifu2x-demo/commit/440d3b4e5ad85b38bba17a925626c50a60c58133 . The ncnn::Mat share the raw image buffer with the Android Bitmaps, and then there is no need to copy back.

laverne01 commented 1 month ago

Thank you for your explanation. I tried copying data from ncnn::Mat out to an Android bitmap using the function out.to_android_bitmap(env, out_bitmap, ncnn::Mat::PIXEL_RGB2RGBA) to make the code cleaner to read. However, it seems there's some error with this function that I can't identify. Could you help me with this?

ArchieMeng commented 1 month ago

It is because the difference in pixel storage format. In ncnn::Mat, it may use floating numbers while Android bitmap uses int. However, don't you think the current process function is enough readable? Is there any parts that you still cannot understand and need comments?

laverne01 commented 1 month ago

Thank you. After some time struggling, I now understand your code, and it executes and runs wonderfully. Thank you for these great explanations.