Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

Capturing images with Pupil, python and OpenCV

More than 5 years have passed since last update.

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

jellied_unagi
Python and Matlab tips for computer vision
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away