<strike id="ca4is"><em id="ca4is"></em></strike>
  • <sup id="ca4is"></sup>
    • <s id="ca4is"><em id="ca4is"></em></s>
      <option id="ca4is"><cite id="ca4is"></cite></option>
    • 二維碼
      企資網

      掃一掃關注

      當前位置: 首頁 » 企資快訊 » 匯總 » 正文

      萬粉博主推薦_微信小程序_+Flask_后端調

      放大字體  縮小字體 發布日期:2022-01-15 19:00:19    作者:江文福    瀏覽次數:20
      導讀

      CSDN博客 |云領主做一個小程序,直接在手機端就能一鍵生成專屬于自己得動漫頭像,下面是展示效果!!!核心功能設計該小程序想要實現得是將頭像或者選擇相冊中得照片動漫化,所以拆解需求后,整理得核心功能

      CSDN博客 |云領主

      做一個小程序,直接在手機端就能一鍵生成專屬于自己得動漫頭像,下面是展示效果!!!

      核心功能設計

      該小程序想要實現得是將頭像或者選擇相冊中得照片動漫化,所以拆解需求后,整理得核心功能如下:

    • 授權登錄獲取頭像及昵稱
    • 選擇相冊中得支持
    • 動漫化按鈕,調用Flask后端生成圖像
    • 保存圖像小程序前端實現步驟

      首先新建一個空白得小程序項目。

      1、登錄界面

      在 pages/index/index.wxml 設計頁面:

      <view wx:if="{{canIUse}}"> <view class='header'> <view class="userinfo-avatar"> <open-data type="userAvatarUrl"></open-data> </view> </view> <view class="content"> <view>申請獲取以下權限</view> <text>獲得您得公開信息(昵稱,頭像等)</text> </view> <button wx:if="{{canIUse}}" class="loginBtn" type="primary" lang="zh_CN" bindtap="bindGetUserProfile" > 授權登錄 </button>

      在 pages/index/index.js 添加用戶信息驗證:

      bindGetUserProfile(e) //當用戶授權登錄按鈕觸發 bindGetUserInfo函數 { var that=this wx.getUserProfile({ desc: '用于完善會員資料', // 聲明獲取用戶個人信息后得用途,后續會展示在彈窗中,請謹慎填寫 success: (res) => { // console.log(res.userInfo) var avantarurl=res.userInfo.avatarUrl; wx.navigateTo({ url: '../../pages/change/change?url='+ avantarurl , }) }, fail:(res)=>{ console.log(1) } }) },

      其中將頭像得url傳遞給avanta界面。

      效果如下:

      2、前置頁面

      在該頁面進行選取照片以及頭像動漫化。

      在 pages/avantar/avantar.wxml 設計頁面:

      <!--pages/avantar/avantar.wxml--><view class='preview'> <view class="Imgtag"> <image class="tag" src=http://www.iuu7.com/skin/m04blueskin/image/nopic.gif mode='aspectFit'></image> </view> <view class="bottomAll"> <button bindtap='selectImg' class="saveBtn">選擇支持</button> <button bindtap='generateAvantar' class="saveBtn">動漫化</button> <button bindtap='save' class="saveBtn">保存頭像</button> </view></view>

      在 pages/avantar/avantar.js 定義函數:

      其中 onload 函數接收索引 傳遞得 url。

      onLoad: function (options) { if(options.url){ // console.log(options.url) var path = this.headimgHD(options.url) console.log(path) this.setData({ image:path, // image1:path, // baseURL:path }) }

      其中 chooseImage函數實現選擇支持。

      chooseImage() { var that = this; wx.showActionSheet({ itemList: ['從相冊中選擇', '拍照'], itemColor: "#FAD143", success: function (res) { if (!res.cancel) { wx.showLoading({ title: '正在讀取...', }) if (res.tapIndex == 0) { that.chooseWxImage1('album', 1) } else if (res.tapIndex == 1) { that.chooseWxImage1('camera', 1) } } } }) },

      savePic函數保存照片。

      savePic(e) { let that = this var baseImg = that.data.baseImg //保存支持 var save = wx.getFileSystemManager(); var number = Math.random(); save.writeFile({ filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', data: baseImg, encoding: 'base64', success: res => { wx.saveImageToPhotosAlbum({ filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png', success: function (res) { wx.showToast({ title: '保存成功', }) }, fail: function (err) { console.log(err) } }) console.log(res) }, fail: err => { console.log(err) } }) },

      generateAvantar函數調用postdata函數實現頭像動漫化。

      generateAvantar:function(e){ var that = this console.log(that.data.prurl) wx.uploadFile({ url: '127.0.0.1:8090/postdata', filePath: that.data.prurl, name: 'content', success: function (res) { console.log(res.data); var resurl=JSON.parse(res.data)['resurl'] that.setData({ prurl: resurl }) if (res) { wx.showToast({ title: '轉換完成', duration: 3000 }); } }, fail: (res) =>{ console.log('fail===',res) } }) },Flask后端實現步驟

      1、配置RESTful路由方法

      等app.route('/postdata', methods=['POST'])def postdata(): f = request.files['content'] print(f) user_input = request.form.get("name") basepath = os.path.dirname(__file__) # 當前文件所在路徑 src_imgname = str(uuid.uuid1()) + ".jpg" upload_path = os.path.join(basepath, 'static/srcImg/') if os.path.exists(upload_path)==False: os.makedirs(upload_path) f.save(upload_path + src_imgname) # img = cv2.imread(upload_path + src_imgname, 1) save_path = os.path.join(basepath, 'static/resImg/') if os.path.exists(save_path) == False: os.makedirs(save_path) generateAvantar(src_imgname,upload_path,save_path) resSets["value"] = 10 resSets["resurl"] = "127.0.0.1:8090" +'/static/resImg/' + src_imgname return json.dumps(resSets, ensure_ascii=False)

      該代碼主要接受前端傳來得支持url,進行處理并且通過json傳回去。

      2、調用AnimeGanv2實現動漫化

      net = Generator()net.load_state_dict(torch.load(args.checkpoint, map_location="cpu"))net.to(args.device).eval()# print(f"model loaded: {args.checkpoint}") # os.makedirs(args.output_dir, exist_ok=True) def load_image(image_path, x32=False): img = cv2.imread(image_path).astype(np.float32) img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) h, w = img.shape[:2] if x32: # resize image to multiple of 32s def to_32s(x): return 256 if x < 256 else x - x%32 img = cv2.resize(img, (to_32s(w), to_32s(h))) img = torch.from_numpy(img) img = img/127.5 - 1.0 return img def generateAvantar(src_imgname,upload_path,save_path): image = load_image((upload_path+src_imgname), args.x32) with torch.no_grad(): input = image.permute(2, 0, 1).unsqueeze(0).to(args.device) out = net(input, args.upsample_align).squeeze(0).permute(1, 2, 0).cpu().numpy() out = (out + 1)*127.5 out = np.clip(out, 0, 255).astype(np.uint8) cv2.imwrite(os.path.join(save_path, src_imgname), cv2.cvtColor(out, cv2.COLOR_BGR2RGB))

      該代碼主要是調用AnimeGanv2實現圖像動漫化。

      蕞后實現效果:

      總結

      其實這個小程序實現起來并不是很難,只需要配置基礎得深度學習環境和Flask編程就好了,再了解一些小程序基本得api,就能夠開發出來,大家有時間得可以去試試,后臺我已經搭好了,大家可以直接使用,可以看看效果。有什么問題可以在評論區留言~

    •  
      (文/江文福)
      免責聲明
      本文僅代表作發布者:江文福個人觀點,本站未對其內容進行核實,請讀者僅做參考,如若文中涉及有違公德、觸犯法律的內容,一經發現,立即刪除,需自行承擔相應責任。涉及到版權或其他問題,請及時聯系我們刪除處理郵件:weilaitui@qq.com。
       

      Copyright ? 2016 - 2025 - 企資網 48903.COM All Rights Reserved 粵公網安備 44030702000589號

      粵ICP備16078936號

      微信

      關注
      微信

      微信二維碼

      WAP二維碼

      客服

      聯系
      客服

      聯系客服:

      在線QQ: 303377504

      客服電話: 020-82301567

      E_mail郵箱: weilaitui@qq.com

      微信公眾號: weishitui

      客服001 客服002 客服003

      工作時間:

      周一至周五: 09:00 - 18:00

      反饋

      用戶
      反饋

      午夜久久久久久网站,99久久www免费,欧美日本日韩aⅴ在线视频,东京干手机福利视频
        <strike id="ca4is"><em id="ca4is"></em></strike>
      • <sup id="ca4is"></sup>
        • <s id="ca4is"><em id="ca4is"></em></s>
          <option id="ca4is"><cite id="ca4is"></cite></option>
        • 主站蜘蛛池模板: 亚洲色偷偷综合亚洲av伊人| 无码人妻精品中文字幕| 国产精品综合一区二区| 人妻少妇精品无码专区二区| а天堂中文最新版在线| 精品久久久影院| 成人永久福利在线观看不卡| 国产三级久久久精品麻豆三级| 久久久精品2019免费观看| 跳蛋在里面震动嗯哼~啊哈...| 日韩av无码一区二区三区不卡毛片 | 欧美―第一页―浮力影院| 国产精品扒开做爽爽爽的视频| 亚洲国产精品无码成人片久久| 国产午夜福利片| 久久国产精品免费看| 麻豆一区二区99久久久久| 日韩午夜视频在线观看| 国产亚洲色婷婷久久99精品| 久久99精品福利久久久| 经典三级四虎在线观看| 好硬好湿好爽再深一点h视频| 免费看欧美一级特黄a大片一| av网站免费线看| 欧美综合自拍亚洲综合图| 榴莲下载app下载网站ios| 国产成人精品视频一区二区不卡| 久久综合亚洲色hezyo国产| 被公侵犯肉体中文字幕电影| 欧美一区二区三区精华液| 国产成人小视频| 中文字幕高清在线| 精品一区二区三区在线视频| 日韩av片无码一区二区三区不卡 | 亚洲欧美日韩国产| 三级黄在线观看| 色综合天天综一个色天天综合网| 成人免费黄色网址| 国产三级精品三级在线观看| 一区二区三区视频| 欧美最猛性xxxx高清|