使用 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è)人都具有姓名、出生日期、國籍、性別等屬性,可用于識(shí)別此人。
下面是 webapp 的鏈接和 UI 的快照。
OpenCV — SeventhSense-人臉識(shí)別網(wǎng)絡(luò)應(yīng)用程序
Python 和 C++ SDK 可用于將圖像對(duì)象發(fā)布到 API 并檢索給定圖像的檢測響應(yīng)。
下面的代碼片段使你能夠?qū)⒔巧砑拥郊现,并檢索給定測試圖像的檢測響應(yīng)。
我使用自己的舊照片來查看模型是否能夠準(zhǔn)確檢測到我的臉。
導(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 人物集合中檢測給定圖像
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測結(jié)果的舊圖像。
原文標(biāo)題 : 使用 OpenCV-SeventhSense SOTA 模型進(jìn)行人臉識(shí)別

發(fā)表評(píng)論
請(qǐng)輸入評(píng)論內(nèi)容...
請(qǐng)輸入評(píng)論/評(píng)論長度6~500個(gè)字
最新活動(dòng)更多
-
3月27日立即報(bào)名>> 【工程師系列】汽車電子技術(shù)在線大會(huì)
-
4月30日立即下載>> 【村田汽車】汽車E/E架構(gòu)革新中,新智能座艙挑戰(zhàn)的解決方案
-
5月15-17日立即預(yù)約>> 【線下巡回】2025年STM32峰會(huì)
-
即日-5.15立即報(bào)名>>> 【在線會(huì)議】安森美Hyperlux™ ID系列引領(lǐng)iToF技術(shù)革新
-
5月15日立即下載>> 【白皮書】精確和高效地表征3000V/20A功率器件應(yīng)用指南
-
5月16日立即參評(píng) >> 【評(píng)選啟動(dòng)】維科杯·OFweek 2025(第十屆)人工智能行業(yè)年度評(píng)選
推薦專題
- 1 UALink規(guī)范發(fā)布:挑戰(zhàn)英偉達(dá)AI統(tǒng)治的開始
- 2 北電數(shù)智主辦酒仙橋論壇,探索AI產(chǎn)業(yè)發(fā)展新路徑
- 3 降薪、加班、裁員三重暴擊,“AI四小龍”已折戟兩家
- 4 “AI寒武紀(jì)”爆發(fā)至今,五類新物種登上歷史舞臺(tái)
- 5 國產(chǎn)智駕迎戰(zhàn)特斯拉FSD,AI含量差幾何?
- 6 光計(jì)算迎來商業(yè)化突破,但落地仍需時(shí)間
- 7 東陽光:2024年扭虧、一季度凈利大增,液冷疊加具身智能打開成長空間
- 8 地平線自動(dòng)駕駛方案解讀
- 9 封殺AI“照騙”,“淘寶們”終于不忍了?
- 10 優(yōu)必選:營收大增主靠小件,虧損繼續(xù)又逢關(guān)稅,能否乘機(jī)器人東風(fēng)翻身?