LoginSignup
9
7

More than 5 years have passed since last update.

Capturing images with Pupil, python and OpenCV

Last updated at Posted at 2014-10-24

Pupil is a head-mounted eye tracker, which is very low price (380 Euro~)
See Pupil lab: http://pupil-labs.com/pupil/

Although a good sdk for MacOS and Linux is available officially, I had a try to use this device just for capuring inside/outside views.

capture.py
import cv2
import sys
import numpy as np
import re


def init_camera(id, width, height):
    u'''
    Initializing a camera
    '''
    cap = cv2.VideoCapture(id)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, width)
    cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, height)

    return cap


def run(ids, width=320, height=180):
    u'''
    Capturing images
    '''
    caps = [init_camera(id, width, height) for id in ids]

    while(True):
        # Capture frame-by-frame
        for id in ids:
            ret, frame = caps[id].read()

            # Our operations on the frame come here

            # Display the resulting frame
            cv2.imshow('cam %d' % id, frame)

        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # When everything done, release the capture
    for id in ids:
        caps[id].release()
    cv2.destroyAllWindows()


def parse_argvs(argvs):
    if(len(argvs) == 1):
        print 'Usage: python capture.py --ids [0, 1, ...] --width [width], --height [height]'

    if '--width' in argvs:
        width = np.int(argvs[argvs.index('--width') + 1])
    else:
        width = 320
    if '--height' in argvs:
        height = np.int(argvs[argvs.index('--height') + 1])
    else:
        height = 180
    if '--ids' in argvs:
        ids = []
        idx = argvs.index('--ids') + 1
        while(re.match('--.*', argvs[idx]) is None):
            ids.append(np.int(argvs[idx]))
            idx = idx + 1
    else:
        ids = [0]

    return ids, width, height

if(__name__ == '__main__'):
    ids, width, height = parse_argvs(sys.argv)
    run(ids, width, height)

Example:

python capture.py --ids 0 1 --width 320 --height 180
kobito.1414127169.369296.png

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7