automotive-message-broker  0.14.803
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
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 <ambpluginimpl.h>
24 #include <string>
25 #include <memory>
26 
27 #include <opencv2/objdetect.hpp>
28 #include <opencv2/highgui/highgui.hpp>
29 
30 #include <QObject>
31 #include <QMutex>
32 
33 using namespace std;
34 
35 class OpenCvLuxPlugin: public QObject, public AmbPluginImpl
36 {
37 Q_OBJECT
38 public:
39 
41 
42  struct Shared
43  {
44  Shared(): frameCount(0) { }
45  std::unique_ptr<cv::VideoCapture> m_capture;
46  std::unique_ptr<cv::VideoWriter> mWriter;
47  PropertyList mRequests;
48  OpenCvLuxPlugin* parent;
49 
50  int fps;
51  bool threaded;
52  bool kinect;
53  bool useCuda;
54  int pixelLowerBound;
55  int pixelUpperBound;
56  bool loggingOn;
57  bool ddd;
58  int frameCount;
59  };
60 
61  OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config, AbstractSource& parent);
62 
63  ~OpenCvLuxPlugin();
64 
65  const string uuid() const;
66  void getPropertyAsync(AsyncPropertyReply *reply);
67  void getRangePropertyAsync(AsyncRangePropertyReply *reply);
68  AsyncPropertyReply * setProperty(AsyncSetPropertyRequest request);
69  void subscribeToPropertyChanges(VehicleProperty::Property property);
70  void unsubscribeToPropertyChanges(VehicleProperty::Property property);
71 
72  void propertyChanged(AbstractPropertyType* value);
73 
74  void supportedChanged(const PropertyList &);
75 
76  void updateProperty(uint16_t lux);
77 
78  void writeVideoFrame(cv::UMat frame);
79 
80  void detectEyes(cv::UMat frame);
81 
82  void init();
83 
84  std::shared_ptr<AbstractPropertyType> videoLogging;
85 
86 public Q_SLOTS:
87  void imgProcResult();
88 
89 private:
90  uint speed;
91  uint latitude;
92  uint longitude;
93 
94  uint lastLux;
95  std::string device;
96  std::list<AsyncPropertyReply*> replyQueue;
97 
98  std::shared_ptr<AbstractPropertyType> extBrightness;
99 
100  std::unique_ptr<Shared> shared;
101  QMutex mutex;
102 
103  std::unique_ptr<cv::CascadeClassifier> faceCascade;
104  std::unique_ptr<cv::CascadeClassifier> eyeCascade;
105 
106  std::shared_ptr<AbstractPropertyType> driverDrowsiness;
107  std::shared_ptr<AbstractPropertyType> openCl;
108 };
109 
110 static int grabImage(void *data);
111 static uint evalImage(cv::UMat qImg, OpenCvLuxPlugin::Shared *shared);
112 
113 namespace TrafficLight
114 {
115 enum Color
116 {
117  Unknown = -1,
118  Red = 0,
119  Yellow,
120  Green
121 };
122 }
123 
124 TrafficLight::Color detectLight(cv::UMat img, OpenCvLuxPlugin::Shared* shared);
125 
126 
127 #endif // EXAMPLEPLUGIN_H