0

我使用opencv打开相机,它同时在另一个窗口中显示面部区域裁剪,所以我同时有2个窗口。所以我想一次显示图像并获取数组。下面是我的脚本

import numpy as np
import cv2

# load clasifier from file
face_cascade = cv2.CascadeClassifier('cascades\haarcascade_frontalface_default.xml')
img = cv2.VideoCapture(0)

while(1):
#Read images

h,f=img.read()
gray = cv2.cvtColor(f, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
    # create rectangle
    cv2.rectangle(f,(x,y),(x+w,y+h),(255,255,255),)
    # crop face area
    roi_gray = gray[y:y+h, x:x+w]
    # showing crop face area 
    cv2.imshow('crop',roi_gray)

#create window camera which name is img
cv2.imshow('img',f)


key = cv2.waitKey(200)
if key in [27, ord('Q'), ord('q')]:
    break

如何从中获取数组cv2.imshow('crop',roi_gray)?谢谢

4

0 回答 0