简体   繁体   中英

Cannot analyse opencv2 capture device frame by frame

I am piecing together a live facial recognition system on a webcam stream using python and opencv2. So far, I have managed to set up both the web cam stream and the facial recognition component, but I have had trouble putting them together.

Right now the issue is passing each frame from the webcam to the facial detection and recognition component.

The relevant piece of code is:

    # Capture frame-by-frame
    ret, frame = video_capture.read()
    image=cv2.VideoCapture.grab(frame)
    image_grey=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
    faces = faceCascade.detectMultiScale(image_grey,scaleFactor=1.2,minNeighbors=5,minSize=(25,25),flags=0)

However, this gives me:

Traceback (most recent call last):
  File "webcam_cv3(2).py", line 66, in <module>
    image=cv2.VideoCapture.grab(frame)
AttributeError: 'builtin_function_or_method' object has no attribute 'grab'

I have been looking through the opencv2 documentatioon and I can't seem to find any reason for cv2.VideoCapture.grab not being valid.

I am using python 2.7 with opencv2. Any help would really be appreciated!

ret, frame = video_capture.read() already gives you frame as an np.array. You can then go on:

image_grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(image_grey,scaleFactor=1.2,minNeighbors=5,minSize=(25,25),flags=0)

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