日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

使用百度API进行关键点识别

發(fā)布時(shí)間:2023/12/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用百度API进行关键点识别 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

在使用百度的AI開(kāi)放平臺(tái)時(shí),不熟悉網(wǎng)頁(yè)請(qǐng)求這類(lèi)知識(shí),遇到使用不暢的問(wèn)題,借鑒了網(wǎng)上兩個(gè)人的經(jīng)驗(yàn),最后實(shí)現(xiàn)了更直白的代碼。

主程序:

''' # 人體關(guān)鍵點(diǎn)識(shí)別 ''' import base64 import urllib import urllib.request,sys,base64 import urllib.parse import json import joint import cv2request_url = "https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis" #使用不同的功能時(shí)在百度的相應(yīng)說(shuō)明文檔處替換此處f = open('/home/zhengr/Documents/data/1.jpg', 'rb') image = base64.b64encode(f.read()) image64 = str(image,'utf-8') image_type = "BASE64"params = {'image': image64,'image_type':"BASE64"}params = urllib.parse.urlencode(params).encode("utf-8")access_token = '[24.fdd8df19e52da8ff449e1484aa582f42.2592000.1556250057.282335-15823849]' request_url = request_url + "?access_token=" + access_token #access token是每個(gè)人獲得的,有效期30天?貌似request = urllib.request.urlopen(url=request_url, data=params) # 發(fā)送請(qǐng)求content = request.read() # 將返回結(jié)果讀取出來(lái) print(content) # 顯示返回結(jié)果 result = str(content,'utf-8') res = json.loads(result) print(res['person_info'][0]['body_parts']) ress = res['person_info'][0]['body_parts'] jo = (ress) jo.xunhun('/home/zhengr/Documents/data/1.jpg')

?直接用python執(zhí)行該程序就可以獲得關(guān)鍵點(diǎn)識(shí)別結(jié)果,access token獲得需要的代碼:

#!/bin/bash curl -i -k 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=QMLVBU3QbNA25XxawltynC1R&client_secret=GuwC9U5WTIbvWgo7ryolIB6Yy1e5H5Nx'

  其中的client_id和client_secret分別是注冊(cè)百度平臺(tái)時(shí)獲得的API Key和Secret Key。執(zhí)行以上文件,得到"access_token":"24.fdd8df19e52da8ff449e1484aa582f42.2592000.1556250057.282335-15823849"格式的即為自己的access token。以上代碼中的joint.Joint()是網(wǎng)上的,其代碼如下:

import cv2 import os class Joint(object):__circle_list = []def __init__(self,dic): self.dic = dicdef draw_line(self,img):#nose ---> neckcv2.line(img, (int(self.dic['nose']['x']),int(self.dic['nose']['y'])),(int(self.dic['neck']['x']),int(self.dic['neck']['y'])), (0,255,0), 2)#neck --> left_shouldercv2.line(img, (int(self.dic['neck']['x']),int(self.dic['neck']['y'])),(int(self.dic['left_shoulder']['x']),int(self.dic['left_shoulder']['y'])), (0,255,0), 2) #neck --> right_shouldercv2.line(img, (int(self.dic['neck']['x']),int(self.dic['neck']['y'])),(int(self.dic['right_shoulder']['x']),int(self.dic['right_shoulder']['y'])), (0,255,0), 2) #left_shoulder --> left_elbowcv2.line(img, (int(self.dic['left_shoulder']['x']),int(self.dic['left_shoulder']['y'])),(int(self.dic['left_elbow']['x']),int(self.dic['left_elbow']['y'])), (0,255,0), 2) #left_elbow --> left_wristcv2.line(img, (int(self.dic['left_elbow']['x']),int(self.dic['left_elbow']['y'])),(int(self.dic['left_wrist']['x']),int(self.dic['left_wrist']['y'])), (0,255,0), 2) #right_shoulder --> right_elbowcv2.line(img, (int(self.dic['right_shoulder']['x']),int(self.dic['right_shoulder']['y'])),(int(self.dic['right_elbow']['x']),int(self.dic['right_elbow']['y'])), (0,255,0), 2) #right_elbow --> right_wristcv2.line(img, (int(self.dic['right_elbow']['x']),int(self.dic['right_elbow']['y'])),(int(self.dic['right_wrist']['x']),int(self.dic['right_wrist']['y'])), (0,255,0), 2) #neck --> left_hipcv2.line(img, (int(self.dic['neck']['x']),int(self.dic['neck']['y'])),(int(self.dic['left_hip']['x']),int(self.dic['left_hip']['y'])), (0,255,0), 2) #neck --> right_hipcv2.line(img, (int(self.dic['neck']['x']),int(self.dic['neck']['y'])),(int(self.dic['right_hip']['x']),int(self.dic['right_hip']['y'])), (0,255,0), 2) #left_hip --> left_kneecv2.line(img, (int(self.dic['left_hip']['x']),int(self.dic['left_hip']['y'])),(int(self.dic['left_knee']['x']),int(self.dic['left_knee']['y'])), (0,255,0), 2) #right_hip --> right_kneecv2.line(img, (int(self.dic['right_hip']['x']),int(self.dic['right_hip']['y'])),(int(self.dic['right_knee']['x']),int(self.dic['right_knee']['y'])), (0,255,0), 2) #left_knee --> left_anklecv2.line(img, (int(self.dic['left_knee']['x']),int(self.dic['left_knee']['y'])),(int(self.dic['left_ankle']['x']),int(self.dic['left_ankle']['y'])), (0,255,0), 2) #right_knee --> right_anklecv2.line(img, (int(self.dic['right_knee']['x']),int(self.dic['right_knee']['y'])),(int(self.dic['right_ankle']['x']),int(self.dic['right_ankle']['y'])), (0,255,0), 2)def xunhun(self,img):im1 = cv2.imread(img,cv2.IMREAD_COLOR)#im2 = cv2.resize(im1, (1040,768), interpolation=cv2.INTER_CUBIC)for i in self.dic:cv2.circle(im1,(int(self.dic[i]['x']),int(self.dic[i]['y'])),5,(0,255,0),-1)self.draw_line(im1)cv2.imshow('image',im1)cv2.waitKey(0)

?

使用這個(gè)代碼,會(huì)有不準(zhǔn)的時(shí)候,試了幾張圖片都會(huì)出現(xiàn),有部分關(guān)鍵點(diǎn)的坐標(biāo)是(0,0),這種在返回值里有不正確、正確的關(guān)鍵點(diǎn)問(wèn)題,應(yīng)該不是我能解決的,所以就沒(méi)有再追究了。

?

?

如有不對(duì)的地方,歡迎批評(píng)指正,如有侵權(quán),請(qǐng)聯(lián)系我刪除。

?

轉(zhuǎn)載于:https://www.cnblogs.com/xiaoheizi-12345/p/10658936.html

總結(jié)

以上是生活随笔為你收集整理的使用百度API进行关键点识别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。