def getUserPicture(outputWidth):

    camera = cv2.VideoCapture(0)

    if not camera.isOpened():
        logging.error("Arrgghhh! The camera is not working!")
        return None

    outputSize = calculateScaledSize(outputWidth, capture=camera)
    logging.debug("Reading camera...")
    readOk, image = camera.read()

    picWin = "Sonria..."
    cv2.namedWindow(picWin)

    key = -1

    while key != ENTER_KEY and readOk:
        image = cv2.resize(image, outputSize)
        drawLabel("Presione [Enter]...", image, (int(outputWidth/3), 50))
        cv2.imshow(picWin, image)
        key = cv2.waitKey(5) % 256
        readOk, image = camera.read()

    cv2.destroyWindow(picWin)
    cv2.waitKey(1)

    logging.debug('Picture taken.')

    return image
def main():
    args = configureArguments()
    configureLogging(args.log)
    logging.info("Starting video delay...")
    picWin = "Sonria..."

    try:
        camera = cv2.VideoCapture(0)
        outputSize = calculateScaledSize(args.outputWidth, capture=camera)

        if not camera.isOpened():
            logging.error("Arrrgggghhhh! Camera is not open...")
            return None

        cv2.namedWindow(picWin)

        if args.delay == 0:
            readOk = True
            while cv2.waitKey(1) == -1:
                readOk, image = camera.read()
                cv2.imshow(picWin, image)
                cv2.waitKey(1)
        else:
            fps = camera.get(cv2.cv.CV_CAP_PROP_FPS)
            logging.debug("Detected {0} FPS".format(fps))
            fps = fps if fps > 0 else 30
            logging.debug("Using {0} FPS".format(fps))

            frameBufferSize = fps * args.delay
            framesBuffer = [None] * frameBufferSize

            logging.debug("Start reading and buffering {0} frames...".format(frameBufferSize))
            i = 0
            while cv2.waitKey(1) and i < frameBufferSize:
                readOk, image = camera.read()
                framesBuffer[i] = image
                i += 1

            logging.debug("Start display of buffered images and queue new ones...")
            while True:
                for i in xrange(frameBufferSize):
                    readOk, image = camera.read()
                    delayedImage = framesBuffer[i]
                    framesBuffer[i] = image

                    outputImage = delayedImage  # cv2.resize(delayedImage, outputSize)
                    cv2.imshow(picWin, outputImage)
                    cv2.waitKey(1)

    except KeyboardInterrupt:
        pass

    logging.debug("Trying to exit app gracefuly.")
    camera.release()
    cv2.destroyWindow(picWin)
    logging.info("Exit video delay OK.")
Пример #3
0
def main():
  args = configureArguments()
  configureLogging(args.log)

  windowTitle = "Test draw app"
  cv2.namedWindow(windowTitle)

  haarFolder = "/home/juan/ciberpunks/opencv-2.4.11/data/haarcascades"
  faceCascade = loadCascadeClassifier(haarFolder + "/haarcascade_frontalface_alt2.xml")
  leftEyeCascade = loadCascadeClassifier(haarFolder + "/haarcascade_lefteye_2splits.xml")
  rightEyeCascade = loadCascadeClassifier(haarFolder + "/haarcascade_righteye_2splits.xml")
  mouthCascade = loadCascadeClassifier(haarFolder + '/haarcascade_mcs_mouth.xml')

  color = (120,120,130)
  thickness = 2

  width = 600

  image = cv2.imread('/home/juan/ciberpunks/faces/news/[email protected]')
  image = cv2.resize(image, calculateScaledSize(width, image=image))

  if image is None:
    print 'ERROR: no se pudo leer la imagen.'
    return

  minFaceSize = (10, 10)
  minEyeSize = (5, 5)

  faces = detectFaces(image, faceCascade, leftEyeCascade, rightEyeCascade, minFaceSize, minEyeSize)

  for (x, y, w, h, leftEyes, rightEyes) in faces:
    center = calculateCenter((x,y,w,h))

    cv2.line(image, (x,0), (x, width), color, 2)
    cv2.line(image, (x+w,0), (x+w, width), color, 2)
    cv2.line(image, (0,y), (width, y), color, 2)
    cv2.line(image, (0,y+h), (width, y+h), color, 2)

    drawLabel("Juan Gabriel", image, (x, y+20))

    cv2.imshow(windowTitle, image)
    cv2.waitKey(6000)
    
  cv2.destroyWindow(windowTitle)