我正在使用“人脸识别”库,并设置“cnn”参数
locations = face_recognition.face_locations(frame, model='cnn')
我怎样才能让这个脚本通过独立显卡而不是内置显卡工作?
跑过
optirun python main.py
和
primusrun python main.py
不返回任何结果,在检查使用情况时我只得到
nvidia-smi
...
|=======================================================================================|
| 0 N/A N/A 7626 G /usr/lib/Xorg 5MiB |
+---------------------------------------------------------------------------------------+
因此,脚本本身并不使用独立显卡
我对Linux很弱,但我想了解这个漂亮的操作系统,所以我将非常感谢您的回答。
剧本:
def detected():
# data = pickle.loads(open('user_1_encodings.pickle', 'rb').read())
cams = cv2.VideoCapture(0)
not_identify = []
while True:
ret, frame = cams.read()
locations = face_recognition.face_locations(frame, model='cnn')
encodings = face_recognition.face_encodings(frame, locations)
for face_encoding, face_location in zip(encodings, locations):
# user_encodings = user_data['encodings']
# result = face_recognition.compare_faces(user_encodings, face_encoding)
result = False
green = [0, 255, 0]
blue = [255, 0, 0]
red = [0, 0, 255]
if any(result):
print(result)
match = user_data['name']
left_top = (face_location[3], face_location[0])
right_bottom = (face_location[1], face_location[2])
cv2.rectangle(frame, left_top, right_bottom, green, 2)
text_x = face_location[3]
text_y = face_location[0] - 10
font_scale = 0.5
font_thickness = 1
font_face = cv2.FONT_HERSHEY_COMPLEX_SMALL
text_size, _ = cv2.getTextSize(match, font_face, font_scale, font_thickness)
text_width, text_height = text_size
rect_left_top = (text_x-1, text_y+5)
rect_right_bottom = (text_x + text_width+5, text_y - text_height-5)
cv2.rectangle(frame, rect_left_top, rect_right_bottom, (255, 255, 255), -1)
cv2.putText(frame, match, (text_x, text_y), font_face, font_scale, (255, 0, 0), font_thickness)
else:
print('NOT OK')
print(face_location)
match = 'Unknown'
top, right, bottom, left = face_location
face = frame[top:bottom, left:right]
pil_image = Image.fromarray(face)
print(pil_image)
not_identify.append(pil_image)
print(not_identify)
if len(not_identify) > 3:
#
if result is False:
not_identify = []
else:
data = result
not_identify = []
left_top = face_location[3], face_location[0]
right_bottom = (face_location[1], face_location[2])
cv2.rectangle(frame, left_top, right_bottom, red, 2)
text_x = face_location[3]
text_y = face_location[0] - 10
font_scale = 0.5
font_thickness = 1
font_face = cv2.FONT_HERSHEY_COMPLEX_SMALL
text_size, _ = cv2.getTextSize(match, font_face, font_scale, font_thickness)
text_width, text_height = text_size
rect_left_top = (text_x-1, text_y+5)
rect_right_bottom = (text_x + text_width+5, text_y - text_height-5)
cv2.rectangle(frame, rect_left_top, rect_right_bottom, (255, 255, 255), -1)
cv2.putText(frame, match, (text_x, text_y), font_face, font_scale, (255, 0, 0), font_thickness)
cv2.imshow('scan', frame)
k = cv2.waitKey(20)
if k == ord('q'):
break
if name == 'main': 检测到()