使用 OpenCV-SeventhSense SOTA 模型進(jìn)行人臉識(shí)別
OpenCV 最近發(fā)布了與 SeventhSense 合作的人臉識(shí)別 SDK。它是 NIST 人臉識(shí)別挑戰(zhàn)賽(2022 年 3 月)的前 10 名模型,速度極快且無(wú)需 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ū)⒔巧砑拥郊现校z索給定測(cè)試圖像的檢測(cè)響應(yīng)。
我使用自己的舊照片來(lái)查看模型是否能夠準(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)更多
-
即日-12.26立即報(bào)名>>> 【在線會(huì)議】村田用于AR/VR設(shè)計(jì)開發(fā)解決方案
-
1月8日火熱報(bào)名中>> Allegro助力汽車電氣化和底盤解決方案優(yōu)化在線研討會(huì)
-
即日-1.14火熱報(bào)名中>> OFweek2025中國(guó)智造CIO在線峰會(huì)
-
即日-1.24立即參與>>> 【限時(shí)免費(fèi)】安森美:Treo 平臺(tái)帶來(lái)出色的精密模擬
-
即日-2025.8.1立即下載>> 《2024智能制造產(chǎn)業(yè)高端化、智能化、綠色化發(fā)展藍(lán)皮書》
-
精彩回顧立即查看>> 【線下會(huì)議】OFweek 2024(第九屆)物聯(lián)網(wǎng)產(chǎn)業(yè)大會(huì)
推薦專題
-
2
- 1 人形機(jī)器人核心零部件,誰(shuí)是盈利最強(qiáng)企業(yè)?
- 2 AI Agent現(xiàn)狀如何?聊聊近期國(guó)內(nèi)的智能體市場(chǎng)動(dòng)向
- 3 5nm重大突破,研祥智能助力半導(dǎo)體企業(yè)高效發(fā)展!
- 4 人形機(jī)器人引爆“PEEK材料”!概念股梳理(名單)
- 5 馬云沒(méi)回牌桌,但重注全壓在了
- 6 7 豆包AI登頂國(guó)內(nèi)第一!概念股梳理(名單)
- 8 押注AI王者歸來(lái),歌爾股份“智能體”在下一盤“大棋”
- 9 AI超級(jí)應(yīng)用什么時(shí)候才能出現(xiàn)?
- 10 英偉達(dá)迎來(lái)當(dāng)頭一棒
- 高級(jí)軟件工程師 廣東省/深圳市
- 自動(dòng)化高級(jí)工程師 廣東省/深圳市
- 光器件研發(fā)工程師 福建省/福州市
- 銷售總監(jiān)(光器件) 北京市/海淀區(qū)
- 激光器高級(jí)銷售經(jīng)理 上海市/虹口區(qū)
- 光器件物理工程師 北京市/海淀區(qū)
- 激光研發(fā)工程師 北京市/昌平區(qū)
- 技術(shù)專家 廣東省/江門市
- 封裝工程師 北京市/海淀區(qū)
- 結(jié)構(gòu)工程師 廣東省/深圳市
OFweek人工智能網(wǎng)
獲取更多精彩內(nèi)容