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


face_cascade = cv2.CascadeClassifier('/home/mckc/Downloads/opencv-2.4.13/data/haarcascades_GPU/haarcascade_frontalface_default.xml')
video_capture = cv2.VideoCapture(0)

In [2]:
align = openface.AlignDlib('/home/mckc/Downloads/shape_predictor_68_face_landmarks.dat')

net = openface.TorchNeuralNet('/home/mckc/Downloads/nn4.small2.3d.v1.t7', imgDim=96)

In [3]:
while True:
#   Capture frame-by-frame
#   time.sleep(1)
    video_capture.open(0)
    ret, frame = video_capture.read()
    start_time = time.time()
    cv2.imshow('Video',frame)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)
    faces  = align.getLargestFaceBoundingBox(a)
    print(time.time()-start_time)

    # Draw a rectangle around the faces
    if len(faces)>0:    
        for (x, y, w, h) in faces:
            fac = np.array(frame)[y:(y+h),x:(x+h),:]            
            cv2.rectangle(frame, (x, y), (x+h, y+w), (0, 255, 0), 2)
            cv2.putText(frame,'omar',(x,y+h), cv2.FONT_HERSHEY_DUPLEX,1,(0,0,255), 2,8)            
            scipy.misc.toimage(cv2.cvtColor(fac, cv2.COLOR_RGB2BGR)).save(str(uuid.uuid4()) +'.jpg')

    # Display the resulting frame
    cv2.imshow('Video', frame)
#        fac = np.array(frame)[y:(y+h),x:(x+h)]
    if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        


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


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-3-becdee74f5fb> in <module>()
      5     ret, frame = video_capture.read()
      6     start_time = time.time()
----> 7     cv2.imshow('Video',frame)
      8     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
      9     gray = cv2.equalizeHist(gray)

error: /home/mckc/Downloads/opencv-2.4.13/modules/highgui/src/window.cpp:261: error: (-215) size.width>0 && size.height>0 in function imshow

In [ ]: