added xwalk. added set
[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         struct Shared
40         {
41                 cv::VideoCapture *m_capture;
42                 cv::VideoWriter *mWriter;
43                 PropertyList mRequests;
44                 OpenCvLuxPlugin* parent;
45
46                 double fps;
47                 bool threaded;
48                 bool kinect;
49                 bool useOpenCl;
50                 bool useCuda;
51                 int pixelLowerBound;
52                 int pixelUpperBound;
53                 bool loggingOn;
54         };
55
56         OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config);
57
58         ~OpenCvLuxPlugin();
59
60         const string uuid();
61         void getPropertyAsync(AsyncPropertyReply *reply);
62         void getRangePropertyAsync(AsyncRangePropertyReply *reply);
63         AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
64         void subscribeToPropertyChanges(VehicleProperty::Property property);
65         void unsubscribeToPropertyChanges(VehicleProperty::Property property);
66         PropertyList supported();
67
68         int supportedOperations();
69
70         void propertyChanged(AbstractPropertyType* value);
71
72         void supportedChanged(const PropertyList &);
73
74         void updateProperty(uint lux);
75
76         void writeVideoFrame(cv::Mat frame);
77
78 public Q_SLOTS:
79         void imgProcResult();
80
81
82 private: /// methods:
83         bool init();
84
85 private:
86         uint speed;
87         uint latitude;
88         uint longitude;
89
90         uint lastLux;
91         std::string device;
92         std::list<AsyncPropertyReply*> replyQueue;
93
94         std::unique_ptr<VehicleProperty::ExteriorBrightnessType> extBrightness;
95
96         Shared* shared;
97         QMutex mutex;
98 };
99
100 static int grabImage(void *data);
101 static uint evalImage(cv::Mat qImg, OpenCvLuxPlugin::Shared *shared);
102
103 namespace TrafficLight
104 {
105 enum Color
106 {
107         Unknown = -1,
108         Red = 0,
109         Yellow,
110         Green
111 };
112 }
113
114 TrafficLight::Color detectLight(cv::Mat img, OpenCvLuxPlugin::Shared* shared);
115
116 #endif // EXAMPLEPLUGIN_H