好吧,我正在使用此代码拍摄图片,但是我希望它拍摄图片,然后将其调整为确定的大小,例如,我需要10张具有相同大小的图片的数据进行训练PCA人脸识别,我需要112 x 92像素的图像。有人知道该怎么做吗?
import cv2
import time
face_cascade = cv2.CascadeClassifier('/home/alvaro/Desktop/Pruebas Algoritmos/PCA/DetecRostro/opencv-master/data/haarcascades/haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(0)
num = 0
while num<1:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = frame[y:y+h, x:x+w]
x = 0
y = 20
text_color = (0,255,0)
cv2.imwrite('opencv'+str(num)+'.jpg',frame)
num = num+1
cap.release()
cv2.destroyAllWindows()