使用 OpenCV-SeventhSense SOTA 模型進(jìn)行人臉識(shí)別
OpenCV 最近發(fā)布了與 SeventhSense 合作的人臉識(shí)別 SDK。它是 NIST 人臉識(shí)別挑戰(zhàn)賽(2022 年 3 月)的前 10 名模型,速度極快且無需 GPU。
在 opencv-seventhsense FR webapp 中,你可以創(chuàng)建一個(gè)集合并將組織中的人員聚合到組中。添加到集合中的每個(gè)人都具有姓名、出生日期、國(guó)籍、性別等屬性,可用于識(shí)別此人。
下面是 webapp 的鏈接和 UI 的快照。
OpenCV — SeventhSense-人臉識(shí)別網(wǎng)絡(luò)應(yīng)用程序
Python 和 C++ SDK 可用于將圖像對(duì)象發(fā)布到 API 并檢索給定圖像的檢測(cè)響應(yīng)。
下面的代碼片段使你能夠?qū)⒔巧砑拥郊现,并檢索給定測(cè)試圖像的檢測(cè)響應(yīng)。
我使用自己的舊照片來查看模型是否能夠準(zhǔn)確檢測(cè)到我的臉。
導(dǎo)入圖片到 FR Webapp
# Import the packages
from opencv.fr import FR
from opencv.fr.persons.schemas import PersonBase,PersonGender
from pathlib import Path
import cv2
import json
# Define the region, and developer key
BACKEND_URL = "https://us.opencv.fr"
DEVELOPER_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Initialize the SDK
sdk = FR(BACKEND_URL, DEVELOPER_KEY)
directory = "/imagepath"
files = Path(directory).glob('*')
# Here we get an existing collection, but this could also
# be a collection you created
all_collections = sdk.collections.list()
all_collections = str(all_collections)
all_collections = all_collections.replace("'", """)
all_collections = json.loads(all_collections)
col_id = all_collections['collections'][0]['id']
print(f"The collection id is - {col_id}")
my_collection = sdk.collections.get(col_id)
for file in files:
if Path(str(file)).suffix == ".jpg" :
# Create PersonBase
image = cv2.imread(str(file))
person = PersonBase([image], name="Rajathithan Rajasekar",
gender=PersonGender("M"), nationality="Indian",)
# Add collection to the person's collections
person.collections.a(chǎn)ppend(my_collection)
# Create the person
person = sdk.persons.create(person)
print(f'Uploaded the image file - {file}')
從 FR webapp 人物集合中檢測(cè)給定圖像
from opencv.fr.search.schemas import DetectionRequest, SearchOptions
from opencv.fr.a(chǎn)pi_error import APIError, APIDataValidationError
from pathlib import Path
from opencv.fr import FR
import json
from json import JSONDecodeError
import cv2
import numpy as np
import imutils
import time
BACKEND_URL = "https://us.opencv.fr"
DEVELOPER_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Initialize the SDK
sdk = FR(BACKEND_URL, DEVELOPER_KEY)
image_base_path = Path("sample_images")
image_path = "imagepath/test/test.jpg"
sourceimage = "imagepath/rajathithan-rajasekar.jpg"
# resize source image
simg = cv2.imread(sourceimage)
simg = imutils.resize(simg, width=640)
simg = imutils.resize(simg, height=480)
#Read old test image
frame = cv2.imread(image_path)
print(frame.shape)
#Get collection id
all_collections = sdk.collections.list()
all_collections = str(all_collections)
all_collections = all_collections.replace("'", """)
all_collections = json.loads(all_collections)
col_id = all_collections['collections'][0]['id']
print(f"The collection id is - {col_id}")
#Initilize the search options
options = SearchOptions(
collection_id=col_id,
min_score = 0.8,
)
#Detection request with search options
detect_request_with_search = DetectionRequest(image_path,options)
detectionObject = sdk.search.detect(detect_request_with_search)
print(detectionObject)
bbox = detectionObject[0].box
print(bbox)
personInfo = detectionObject[0].persons[0]
print(f"Name:{personInfo.person.name}")
print(f"Gender:{personInfo.person.gender}")
print(f"Nationality:{personInfo.person.nationality}")
print(f"Score:{personInfo.score}")
def rec_frame_display(frame: np.ndarray, roi, personInfo) -> np.ndarray:
diff1 = round((roi['bottom'] - roi['top'])/4)
diff2 = round((roi['left'] - roi['right'])/4)
cv2.line(frame, (roi['left'],roi['top']), (roi['left'],roi['top']+diff1), (0, 200, 0), 4)
cv2.line(frame, (roi['left'],roi['bottom']), (roi['left'],roi['bottom']-diff1), (0, 200, 0), 4)
cv2.line(frame, (roi['right'],roi['top']), (roi['right'],roi['top']+diff1), (0, 200, 0), 4)
cv2.line(frame, (roi['right'],roi['bottom']), (roi['right'],roi['bottom']-diff1), (0, 200, 0), 4)
cv2.line(frame, (roi['left'],roi['top']), (roi['left']-diff2,roi['top']), (0, 200, 0), 4)
cv2.line(frame, (roi['left'],roi['bottom']), (roi['left']-diff2,roi['bottom']), (0, 200, 0), 4)
cv2.line(frame, (roi['right'],roi['top']), (roi['right']+diff2,roi['top']), (0, 200, 0), 4)
cv2.line(frame, (roi['right'],roi['bottom']), (roi['right']+diff2,roi['bottom']), (0, 200, 0), 4)
cv2.putText(frame, "Name : " + personInfo.person.name, (50, 50),
cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255),2,cv2.LINE_AA, False)
cv2.putText(frame, "Gender : " + str(personInfo.person.gender), (50, 150),
cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255),2,cv2.LINE_AA, False)
cv2.putText(frame, "Nationality : " + str(personInfo.person.nationality), (50, 250),
cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255),2,cv2.LINE_AA, False)
cv2.putText(frame, "Confidence Score : " + str(round(personInfo.score * 100,2)) + " %", (50, 350),
cv2.FONT_HERSHEY_SIMPLEX, 2, (255, 255, 255),2,cv2.LINE_AA, False)
return frame
roi = json.loads(str(bbox).replace("'","""))
frame = rec_frame_display(frame, roi, personInfo)
frame = imutils.resize(frame, width = 640,height = 480)
combine = np.concatenate((simg, frame), axis=1)
cv2.imwrite("final.jpg",combine)
cv2.imshow("Face recognition on an old pic",combine)
cv2.waitKey(0)
cv2.destroyAllWindows()
左側(cè)照片是我當(dāng)前的圖像,右側(cè)照片是我?guī)в袡z測(cè)結(jié)果的舊圖像。
原文標(biāo)題 : 使用 OpenCV-SeventhSense SOTA 模型進(jìn)行人臉識(shí)別

發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長(zhǎng)度6~500個(gè)字
最新活動(dòng)更多
-
6月20日立即下載>> 【白皮書】精準(zhǔn)測(cè)量 安全高效——福祿克光伏行業(yè)解決方案
-
7月3日立即報(bào)名>> 【在線會(huì)議】英飛凌新一代智能照明方案賦能綠色建筑與工業(yè)互聯(lián)
-
7月22-29日立即報(bào)名>> 【線下論壇】第三屆安富利汽車生態(tài)圈峰會(huì)
-
7.30-8.1火熱報(bào)名中>> 全數(shù)會(huì)2025(第六屆)機(jī)器人及智能工廠展
-
7月31日免費(fèi)預(yù)約>> OFweek 2025具身機(jī)器人動(dòng)力電池技術(shù)應(yīng)用大會(huì)
-
免費(fèi)參會(huì)立即報(bào)名>> 7月30日- 8月1日 2025全數(shù)會(huì)工業(yè)芯片與傳感儀表展
推薦專題
- 1 AI 眼鏡讓百萬 APP「集體失業(yè)」?
- 2 大廠紛紛入局,百度、阿里、字節(jié)搶奪Agent話語(yǔ)權(quán)
- 3 深度報(bào)告|中國(guó)AI產(chǎn)業(yè)正在崛起成全球力量,市場(chǎng)潛力和關(guān)鍵挑戰(zhàn)有哪些?
- 4 上海跑出80億超級(jí)獨(dú)角獸:獲上市公司戰(zhàn)投,干人形機(jī)器人
- 5 國(guó)家數(shù)據(jù)局局長(zhǎng)劉烈宏調(diào)研格創(chuàng)東智
- 6 下一代入口之戰(zhàn):大廠為何紛紛押注智能體?
- 7 百億AI芯片訂單,瘋狂傾銷中東?
- 8 Robotaxi新消息密集釋放,量產(chǎn)元年誰在領(lǐng)跑?
- 9 格斗大賽出圈!人形機(jī)器人致命短板曝光:頭腦過于簡(jiǎn)單
- 10 “搶灘”家用機(jī)器人領(lǐng)域,聯(lián)通、海爾、美的等紛紛入局