Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

aww, you're looking at outdated c-api code from pre 2010 (which is not using numpy arrays to store images or generic matrices)

take a close look at the python tutorials and, ofc, the sample codes

but here's the nutshell:

import cv2
import numpy as np

cam = cv2.VideoCapture(0)
while cam.isOpened():
    ok,img = cam.read()
   if (not ok):
       continue # maybe you got an oldish webcam, that needs some 'warmup'
    # if you had a video **file** instead, you want to break here instead (reached last frame)
    #
    # your img processing would go here ;)
    #
    cv2.imshow("lalala", img)
    k = cv2.waitKey(10) & 0xff
    if k==27:
        break

aww, you're looking at outdated c-api code from pre 2010 (which is not using numpy arrays to store images or generic matrices)

take a close look at the python tutorials and, ofc, the sample codes

but here's the nutshell:

import cv2
import numpy as np

cam = cv2.VideoCapture(0)
while cam.isOpened():
    ok,img = cam.read()
   if (not ok):
       continue # maybe you got an oldish webcam, that needs some 'warmup'
    # if you had a video **file** instead, you want to break here instead (reached last frame)
    #
    # your img processing would go here ;)
    #
    cv2.imshow("lalala", img)
    k = cv2.waitKey(10) & 0xff
    if k==27:
        break