In [1]:
import cv2
import numpy as np
import scipy.misc
import os
import dlib
import time
os.chdir("/home/mckc/Imagedb/")
import uuid
#%matplotlib inline


video_capture = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()

In [2]:
while True:
    # Capture frame-by-frame
#    time.sleep(1)
    ret, frame = video_capture.read()
    faces = detector(frame, 1)
    
    # Draw a rectangle around the faces
    if len(faces)>0:    
        for a,b in enumerate(faces):
            fac = np.array(frame)[b.top():b.bottom(),b.left():b.right(),:]    
            cv2.rectangle(frame, (b.left(), b.top()), (b.right(), b.bottom()), (0, 255, 0), 2)
            #cv2.putText(frame,'omar',(b.left(),b.bottom()), cv2.FONT_HERSHEY_DUPLEX,1,(0,0,255), 2,8)  
            scipy.misc.toimage(cv2.cvtColor(fac,cv2.COLOR_RGB2BGR)).save(str(uuid.uuid4()) +'.jpg')
    
    cv2.imshow('Video', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        


# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-15a824a7b49a> in <module>()
      3 #    time.sleep(1)
      4     ret, frame = video_capture.read()
----> 5     faces = detector(frame, 1)
      6 
      7     # Draw a rectangle around the faces

RuntimeError: Unsupported image type, must be 8bit gray or RGB image.

In [4]:
from picamera.array import PiRGBArray
from picamera import PiCamera

camera = PiCamera()
#camera.resolution = (1008, 752)
camera.video_stabilization = True
camera.framerate = 10
#camera.vflip = True
#camera.hflip = True
#camera.zoom = (0,0,0.75,0.75)
rawCapture = PiRGBArray(camera, size=(640, 480))
cv2.namedWindow('Video',cv2.WINDOW_NORMAL)
cv2.resizeWindow('Video',640,480)
i = 0
t1 = time.time()

for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
	# grab the raw NumPy array representing the image, then initialize the timestamp
	# and occupied/unoccupied text
    frame = frame.array
    cv2.imshow('video',frame)


---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-4-184da7238b06> in <module>()
----> 1 from picamera.array import PiRGBArray
      2 from picamera import PiCamera
      3 
      4 camera = PiCamera()
      5 #camera.resolution = (1008, 752)

/home/mckc/anaconda/lib/python2.7/site-packages/picamera/__init__.py in <module>()
     70 str = type('')
     71 
---> 72 from picamera.exc import (
     73     PiCameraWarning,
     74     PiCameraDeprecated,

/home/mckc/anaconda/lib/python2.7/site-packages/picamera/exc.py in <module>()
     39 
     40 
---> 41 import picamera.mmal as mmal
     42 
     43 

/home/mckc/anaconda/lib/python2.7/site-packages/picamera/mmal.py in <module>()
     45 import warnings
     46 
---> 47 _lib = ct.CDLL('libmmal.so')
     48 
     49 # vcos_platform.h ############################################################

/home/mckc/anaconda/lib/python2.7/ctypes/__init__.pyc in __init__(self, name, mode, handle, use_errno, use_last_error)
    360 
    361         if handle is None:
--> 362             self._handle = _dlopen(self._name, mode)
    363         else:
    364             self._handle = handle

OSError: libmmal.so: cannot open shared object file: No such file or directory

In [ ]: