繁体   English   中英

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

[英]How to save cropped image using openCV?

我在 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM