In [1]:
import sys

import cv2
import dlib
from skimage import io

In [3]:
detector = dlib.get_frontal_face_detector()
win = dlib.image_window()

while True:
    from cv2 import VideoCapture
    from time import time

    cam = VideoCapture(0)  #set the port of the camera as before

    while True:
        start = time()
        retval, image = cam.read() #return a True bolean and and the image if all go right

        for row in image:
            for px in row:
                #rgb expected... but the array is bgr?
                r = px[2]
                px[2] = px[0]
                px[0] = r
        #import matplotlib.pyplot as plt
        #plt.imshow(image)
        #plt.show()

        print( "readimage: " + str( time() - start ) )

        start = time()
        dets = detector(image, 1)
        #print "your faces: %f" % len(dets)
        for i, d in enumerate( dets ):
            pass
            #print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
                #i, d.left(), d.top(), d.right(), d.bottom()))
            #print("from left: {}".format( ( (d.left() + d.right()) / 2 ) / len(image[0]) ))
            #print("from top: {}".format( ( (d.top() + d.bottom()) / 2 ) /len(image)) )
        print( "process: " + str( time() - start ) )

        start = time()
        win.clear_overlay()
        win.set_image(image)
        win.add_overlay(dets)

        print( "show: " + str( time() - start ) )
        #dlib.hit_enter_to_continue()
        dlib.hit_enter_to_continue()


---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-677160e0adb4> in <module>()
     12         retval, image = cam.read() #return a True bolean and and the image if all go right
     13 
---> 14         for row in image:
     15             for px in row:
     16                 #rgb expected... but the array is bgr?

TypeError: 'NoneType' object is not iterable

In [ ]:


In [ ]: