Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用openCV保存裁剪后的图像?_Python_Image_Opencv_Crop_Face Recognition - Fatal编程技术网

Python 如何使用openCV保存裁剪后的图像?

Python 如何使用openCV保存裁剪后的图像?,python,image,opencv,crop,face-recognition,Python,Image,Opencv,Crop,Face Recognition,我用python中的opencv和face_识别库拍摄图像, 这是我的程序片段 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)

我用python中的opencv和face_识别库拍摄图像, 这是我的程序片段

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)
这意味着什么不起作用,根本不保存,或最终出错或保存到你不想保存的地方?temp[3]呢?很抱歉,它已经成功了,谢谢你