简体   繁体   中英

How to save cropped image using openCV?

I am capturing image using opencv and face_recognition library in python, Here is the snippet of my program

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)

I am trying to save cropped image to my directory. But the code above doesn't work. Do you know the way how can I save cropped Image using opencv ?

试试这个cv2.imwrite('path/to/face.png',cropped)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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