Merge pull request #30 from tripzero/master
[profile/ivi/automotive-message-broker.git] / plugins / opencvlux / opencvluxplugin.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef OPENCVLUXPLUGIN_H
20 #define OPENCVLUXPLUGIN_H
21
22 #include <abstractsource.h>
23 #include <string>
24 #include <memory>
25
26 #include <opencv/cv.h>
27 #include <opencv2/highgui/highgui.hpp>
28
29 #include <QObject>
30 #include <QMutex>
31
32 using namespace std;
33
34 class OpenCvLuxPlugin: public QObject, public AbstractSource
35 {
36 Q_OBJECT
37 public:
38
39         typedef BasicPropertyType<bool> DriverDrowsinessType;
40
41         struct Shared
42         {
43                 std::unique_ptr<cv::VideoCapture> m_capture;
44                 std::unique_ptr<cv::VideoWriter> mWriter;
45                 PropertyList mRequests;
46                 OpenCvLuxPlugin* parent;
47
48                 double fps;
49                 bool threaded;
50                 bool kinect;
51                 bool useOpenCl;
52                 bool useCuda;
53                 int pixelLowerBound;
54                 int pixelUpperBound;
55                 bool loggingOn;
56                 bool ddd;
57         };
58
59         OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config);
60
61         ~OpenCvLuxPlugin();
62
63         const string uuid();
64         void getPropertyAsync(AsyncPropertyReply *reply);
65         void getRangePropertyAsync(AsyncRangePropertyReply *reply);
66         AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
67         void subscribeToPropertyChanges(VehicleProperty::Property property);
68         void unsubscribeToPropertyChanges(VehicleProperty::Property property);
69         PropertyList supported();
70
71         int supportedOperations();
72
73         void propertyChanged(AbstractPropertyType* value);
74
75         void supportedChanged(const PropertyList &);
76
77         void updateProperty(uint lux);
78
79         void writeVideoFrame(cv::Mat frame);
80
81         void detectEyes(cv::Mat frame);
82
83 public Q_SLOTS:
84         void imgProcResult();
85
86
87 private: /// methods:
88         bool init();
89
90 private:
91
92
93         uint speed;
94         uint latitude;
95         uint longitude;
96
97         uint lastLux;
98         std::string device;
99         std::list<AsyncPropertyReply*> replyQueue;
100
101         std::unique_ptr<VehicleProperty::ExteriorBrightnessType> extBrightness;
102
103         std::unique_ptr<Shared> shared;
104         QMutex mutex;
105
106         std::unique_ptr<cv::CascadeClassifier> faceCascade;
107         std::unique_ptr<cv::CascadeClassifier> eyeCascade;
108
109         std::unique_ptr<DriverDrowsinessType> driverDrowsiness;
110
111         std::unique_ptr<BasicPropertyType<bool>> openCl;
112 };
113
114 static int grabImage(void *data);
115 static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared);
116
117 namespace TrafficLight
118 {
119 enum Color
120 {
121         Unknown = -1,
122         Red = 0,
123         Yellow,
124         Green
125 };
126 }
127
128 TrafficLight::Color detectLight(cv::Mat img, OpenCvLuxPlugin::Shared* shared);
129
130
131 #endif // EXAMPLEPLUGIN_H