Capturing images with Pupil, python and OpenCV

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](https://qiita-image-store.s3.amazonaws.com/0/69/9106d176-d0de-5ce1-0f2c-65d2a0e2339f.png "kobito.1414127169.369296.png ")



Recommended Posts

Capturing images with Pupil, python and OpenCV
Shining life with Python and OpenCV
Neural network with OpenCV 3 and Python 3
Load gif images with Python + OpenCV
[python, openCV] base64 Face recognition with images
[Python] Read images with OpenCV (for beginners)
Importing and exporting GeoTiff images with Python
[Python] Try to recognize characters from images with OpenCV and pyocr
Binarization with OpenCV / Python
Install OpenCV 4.0 and Python 3.7 on Windows 10 with Anaconda
Wavelet transform of images with PyWavelets and OpenCV
Feature matching with OpenCV 3 and Python 3 (A-KAZE, KNN)
Programming with Python and Tkinter
Encryption and decryption with Python
Bordering images with python Part 1
Get media timeline images and videos with Python + Tweepy
"Apple processing" with OpenCV3 + Python3
Python and hardware-Using RS232C with Python-
Image editing with python OpenCV
Camera capture with Python + OpenCV
[Python] Using OpenCV with Python (Basic)
Try projective transformation of images using OpenCV with Python
Face detection with Python + OpenCV
Ubuntu 20.04 on raspberry pi 4 with OpenCV and use with python
python with pyenv and venv
[Python] Webcam frame size and FPS settings with OpenCV
Reading, displaying and speeding up gifs with python [OpenCV]
Troubleshoot with installing OpenCV on Raspberry Pi and capturing
Using OpenCV with Python @Mac
Works with Python and R
I tried "morphology conversion" of images with Python + OpenCV
I made a program to convert images into ASCII art with Python and OpenCV
Separate color images into RGB images and display them with OpenCV
Send experiment results (text and images) to slack with Python
Convert video to black and white with ffmpeg + python + opencv
Communicate with FX-5204PS with Python and PyUSB
Number recognition in images with Python
Environment construction of python and opencv
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Node, Ruby and Python
[Python] Using OpenCV with Python (Image transformation)
Scraping with Python, Selenium and Chromedriver
[Python] Using OpenCV with Python (Edge Detection)
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Hadoop introduction and MapReduce with Python
Easy Python + OpenCV programming with Canopy
[GUI with Python] PyQt5-Drag and drop-
Post multiple Twitter images with python
Reading and writing NetCDF with Python
Animate multiple still images with Python
Try face recognition with python + OpenCV
Cut out face with Python + OpenCV
Face recognition with camera with opencv3 + python2.7
I played with PyQt5 and Python3
[Python] Collect images easily with icrawler!
Reading and writing CSV with Python
Find image similarity with Python + OpenCV