Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2484 - 1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Runtime.InteropServices;
6
using System.ComponentModel.Composition;
7
 
8
namespace Touchless.Vision.Camera
9
{
10
    public static class CameraService
11
    {
12
        private static WebCamLib.CameraMethods _cameraMethods;
13
 
14
        private static WebCamLib.CameraMethods CameraMethods
15
        {
16
            get
17
            {
18
                if (_cameraMethods == null)
19
                {
20
                    _cameraMethods = new WebCamLib.CameraMethods();
21
                }
22
 
23
                return _cameraMethods;
24
            }
25
        }
26
 
27
        [Export(ExportInterfaceNames.DefaultCamera)]
28
        public static Camera DefaultCamera
29
        {
30
            get { return AvailableCameras.FirstOrDefault(); }
31
        }
32
 
33
        private static List<Camera> _availableCameras;
34
        public static IList<Camera> AvailableCameras
35
        {
36
            get
37
            {
38
                if (_availableCameras == null)
39
                {
40
                    _availableCameras = BuildCameraList().ToList();
41
                }
42
 
43
                return _availableCameras;
44
            }
45
        }
46
        public static void ClearCameraList()
47
        {
48
            _availableCameras = null;
49
            _cameraMethods = null;
50
        }
51
 
52
        private static IEnumerable<Camera> BuildCameraList()
53
        {
54
            for (int i = 0; i < CameraMethods.Count; i++)
55
            {
56
                WebCamLib.CameraInfo cameraInfo = CameraMethods.GetCameraInfo(i);
57
                yield return new Camera(CameraMethods, cameraInfo.Name, cameraInfo.Index);
58
            }
59
        }
60
    }
61
}