blob: 919ae8d2a26f63cd71d32d01a1c693eb3a068875 [file] [log] [blame]
Tai-Hsu Lin63e1a732012-03-03 19:20:26 +08001# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
Michael Spang06269ad2013-01-04 14:34:51 -05005import glob, os
Tai-Hsu Lin63e1a732012-03-03 19:20:26 +08006import numpy as np
7
8# Dimension padding/unpadding function for converting points matrices to
9# the OpenCV format (channel-based).
10def Pad(x):
11 return np.expand_dims(x, axis=0)
12
13
14def Unpad(x):
15 return np.squeeze(x)
16
17
18class Pod(object):
19 '''A POD (plain-old-data) object containing arbitrary fields.'''
20 def __init__(self, **args):
21 self.__dict__.update(args)
22
23 def __repr__(self):
24 '''Returns a representation of the object, including its properties.'''
25 return (self.__class__.__name__ + '(' +
26 ', '.join('%s=%s' % (k, v) for k, v in sorted(self.__dict__.items())
27 if not k.startswith('_')) + ')')
Michael Spang06269ad2013-01-04 14:34:51 -050028
29
30def find_camera():
31 """
32 Find a V4L camera device.
33
34 @return (device_name, device_index). If no camera is found, (None, None).
35 """
36 cameras = [os.path.basename(camera) for camera in
37 glob.glob('/sys/bus/usb/drivers/uvcvideo/*/video4linux/video*')]
38 if not cameras:
39 return None, None
40 camera = cameras[0]
41 return camera, int(camera[5:])