sairate
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 22 KiB |
|
@ -27,6 +27,11 @@ while photo_count < max_photos:
|
||||||
|
|
||||||
for face_location in face_locations:
|
for face_location in face_locations:
|
||||||
top, right, bottom, left = face_location
|
top, right, bottom, left = face_location
|
||||||
|
|
||||||
|
# 在图像上绘制绿框
|
||||||
|
cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)
|
||||||
|
|
||||||
|
# 提取人脸区域
|
||||||
face_image = frame[top:bottom, left:right]
|
face_image = frame[top:bottom, left:right]
|
||||||
|
|
||||||
# 保存抓拍的照片
|
# 保存抓拍的照片
|
||||||
|
@ -48,7 +53,6 @@ cv2.destroyAllWindows()
|
||||||
|
|
||||||
print(f"Captured {photo_count} images.")
|
print(f"Captured {photo_count} images.")
|
||||||
|
|
||||||
|
|
||||||
def create_face_database(db_name="face_database.db"):
|
def create_face_database(db_name="face_database.db"):
|
||||||
conn = sqlite3.connect(db_name)
|
conn = sqlite3.connect(db_name)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
@ -59,7 +63,6 @@ def create_face_database(db_name="face_database.db"):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def add_face_to_database(name, image_path, db_name="face_database.db"):
|
def add_face_to_database(name, image_path, db_name="face_database.db"):
|
||||||
conn = sqlite3.connect(db_name)
|
conn = sqlite3.connect(db_name)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
@ -77,7 +80,6 @@ def add_face_to_database(name, image_path, db_name="face_database.db"):
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def match_faces(captured_images, db_name="face_database.db", tolerance=0.4):
|
def match_faces(captured_images, db_name="face_database.db", tolerance=0.4):
|
||||||
conn = sqlite3.connect(db_name)
|
conn = sqlite3.connect(db_name)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
@ -105,7 +107,7 @@ def match_faces(captured_images, db_name="face_database.db", tolerance=0.4):
|
||||||
print(f"发现匹配: {name} 在 {image_path}")
|
print(f"发现匹配: {name} 在 {image_path}")
|
||||||
conn.close()
|
conn.close()
|
||||||
return True # 一旦找到匹配,返回成功
|
return True # 一旦找到匹配,返回成功
|
||||||
|
print(f"没发现匹配: 在 {image_path}")
|
||||||
conn.close()
|
conn.close()
|
||||||
return False # 如果所有比较都没有匹配,返回失败
|
return False # 如果所有比较都没有匹配,返回失败
|
||||||
|
|
||||||
|
@ -120,4 +122,3 @@ if match_faces(captured_images):
|
||||||
print("至少一张匹配")
|
print("至少一张匹配")
|
||||||
else:
|
else:
|
||||||
print("没有匹配")
|
print("没有匹配")
|
||||||
|
|
||||||
|
|