有用户反馈人像动漫化后的图片失真:

所以看了下阿里云有无人像增强的api,搜索后还真有:

文档地址:
help.aliyun.com/zh/viapi/de...
我想的是:在调用人像动漫化接口之前先将上传的人像图片再调用一次人像增强后再调用动漫化接口,这样就可以将清晰度提高一些了。
先试试效果:


下面这个案例就更明显了:

看起来确实是清晰了一些,还是有点效果。
那就用起来,看看这个接口的SDK,也挺简单的,还是同步请求:

就一个参数:

不过限制还挺高,图片不能超过3M、像素还不能超过2048X2048,现在的手机随便拍一张照片都肯定超过了2048:

还在想大像素图片怎么办的时候,突然又发现阿里云oss支持图片缩放,只需要在oss地址后面加个参数即可:

用一下:

体验不错。
人像动漫化接口像素最大2000*2000:

所以人像增强接口的最大像素也得是2000*2000。
我想达到的效果就是:如果图片的像素超过20002000,则宽高最大不得超过2000像素,超过则等比缩放,如果长或者宽超过了2000,那么宽高中较大值需缩放为2000,如:宽高为2200 2100,缩放后:20001909,宽高换一下:21002200,缩放后:1909*2000。OK,压缩比确认下来了,我们先对接人像增强。
简单把让人像增强接口接进来,因为有了对接人像动漫化的经验,所以对接人像增强还是比较快捷的:

我把调用人像增强的操作放到上传图片后,这样就能立刻看到人像增强的效果了:

页面效果还是比较明显的:

在调用最终的人像动漫化之前就将人像增强了,这样传给人像动漫化接口的图片就会更清晰,出的图效果也会更好。
由于篇幅有限,本文完成了在调用人像动漫化接口之前先增强图片质量的需求,关于图片大小的调整将放到下文修改。
小程序名:《一方云知》。欢迎大家使用。
这篇文章就到这里啦!如果你对文章内容有疑问或想要深入讨论,欢迎在评论区留言,我会尽力回答。同时,如果你觉得这篇文章对你有帮助,不妨点个赞并分享给其他同学,让更多人受益。
想要了解更多相关知识,可以查看我以往的文章,其中有许多精彩内容。记得关注我,获取及时更新,我们可以一起学习、讨论技术,共同进步。
感谢你的阅读与支持,期待在未来的文章中与你再次相遇!