Subversion Repositories Projects

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2526 - 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
                    try
21
                    {
22
                        _cameraMethods = new WebCamLib.CameraMethods();
23
 
24
                    }
25
                    catch (Exception)
26
                    {
27
                    }
28
 
29
                }
30
 
31
                return _cameraMethods;
32
            }
33
        }
34
 
35
        [Export(ExportInterfaceNames.DefaultCamera)]
36
        public static Camera DefaultCamera
37
        {
38
            get { return AvailableCameras.FirstOrDefault(); }
39
        }
40
 
41
        private static List<Camera> _availableCameras;
42
        public static IList<Camera> AvailableCameras
43
        {
44
            get
45
            {
46
                try
47
                {
48
                    if (_availableCameras == null && CameraMethods != null)
49
                    {
50
                        _availableCameras = BuildCameraList().ToList();
51
                    }
52
 
53
                }
54
                catch (Exception)
55
                {
56
 
57
                }
58
 
59
 
60
                return _availableCameras;
61
            }
62
        }
63
        public static void ClearCameraList()
64
        {
65
            _availableCameras = null;
66
            _cameraMethods = null;
67
        }
68
 
69
        private static IEnumerable<Camera> BuildCameraList()
70
        {
71
            if (CameraMethods != null)
72
            {
73
                for (int i = 0; i < CameraMethods.Count; i++)
74
                {
75
                    WebCamLib.CameraInfo cameraInfo = CameraMethods.GetCameraInfo(i);
76
                    yield return new Camera(CameraMethods, cameraInfo.Name, cameraInfo.Index);
77
                }
78
            }
79
        }
80
    }
81
}