问题描述
我正在使用python中的opencv和face_recognition库捕获图像, 这是我的程序的代码段
while True:
ret,frame = video_capture.read()
rgb_frame = frame[:,:,::-1]
face_locations = fr.face_locations(rgb_frame)
face_encodings = fr.face_encodings(rgb_frame,face_locations)
cv2.imwrite('test.png',frame)
if len(face_encodings)!=0:
print(face_locations)
temp = list(face_locations[0])
img = cv2.imread('test.png')
cropped = img[temp[0]:temp[2],temp[0]:temp[1]]
cv2.imshow("cropped",cropped)
cv2.imwrite('face.png',cropped)
我正在尝试将裁剪的图像保存到我的目录中。但是上面的代码不起作用。您知道如何使用opencv保存裁剪后的图像的方式吗?
解决方法
尝试一下cv2.imwrite('path/to/face.png',cropped)