#include "opencvluxplugin.h"
#include "timestamp.h"
#include <listplusplus.h>
+#include <superptr.hpp>
#include <iostream>
#include <opencv2/imgproc/imgproc.hpp>
+#include <opencv2/objdetect/objdetect.hpp>
#include <QFuture>
#include <QFutureWatcher>
extern "C" AbstractSource * create(AbstractRoutingEngine* routingengine, map<string, string> config)
{
VehicleProperty::registerProperty(VideoLogging, [](){
- return new BasicPropertyType<bool>(VideoLogging,false);
+ return new BasicPropertyType<bool>(VideoLogging, false);
+ });
+
+ VehicleProperty::registerProperty("DriverDrowsiness", [](){
+ return new OpenCvLuxPlugin::DriverDrowsinessType("DriverDrowsiness", false);
});
return new OpenCvLuxPlugin(routingengine, config);
OpenCvLuxPlugin::OpenCvLuxPlugin(AbstractRoutingEngine* re, map<string, string> config)
:AbstractSource(re, config), lastLux(0), speed(0), latitude(0), longitude(0), extBrightness(new VehicleProperty::ExteriorBrightnessType(0))
{
+ driverDrowsiness = amb::make_unique(new DriverDrowsinessType("DriverDrowsiness", false));
+
shared = new Shared;
shared->parent = this;
shared->useOpenCl = false;
shared->useCuda = false;
shared->loggingOn = false;
+ shared->ddd = false;
shared->fps=30;
device="0";
{
#ifdef OPENCL
shared->useOpenCl = config["opencl"] == "true";
+#else
+ DebugOut(DebugOut::Warning) << "You really don't have openCL support. Disabling." << endl;S
+ shared->useOpenCl = false;
#endif
}
#endif
}
+ if(config.find("ddd") != config.end())
+ {
+ shared->ddd = config["ddd"] == "true";
+ }
+
+ if(config.find("logging") != config.end())
+ {
+ shared->loggingOn = config["logging"] == "true";
+ }
+
#ifdef OPENCL
if(shared->useOpenCl)
}
#endif
+ if(shared->ddd)
+ {
+#ifdef OPENCL
+ if(shared->useOpenCl)
+ {
+ faceCascade = new cv::ocl::OclCascadeClassifier();
+ eyeCascade = new cv::ocl::OclCascadeClassifier();
+ }
+ else
+#endif
+ {
+ faceCascade = new cv::CascadeClassifier();
+ eyeCascade = new cv::CascadeClassifier();
+ }
+
+ if(!faceCascade->load("/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml"))
+ {
+ DebugOut(DebugOut::Warning) << "Could not load face cascade. Disabling ddd" << endl;
+ shared->ddd = false;
+ }
+ if(!eyeCascade->load("/usr/share/opencv/haarcascades/haarcascade_eye_tree_eyeglasses.xml"))
+ {
+ DebugOut(DebugOut::Warning) << "Could not load face cascade. Disabling ddd" << endl;
+ shared->ddd = false;
+ }
+
+ }
+
routingEngine->subscribeToProperty(VehicleProperty::VehicleSpeed, this);
- routingEngine->subscribeToProperty(VehicleProperty::Latitude,this);
+ routingEngine->subscribeToProperty(VehicleProperty::Latitude, this);
routingEngine->subscribeToProperty(VehicleProperty::Longitude, this);
}
*(shared->m_capture) >> m_image;
}
+ if(shared->ddd)
+ shared->parent->detectEyes(m_image);
+
if(shared->threaded)
{
QFutureWatcher<uint> *watcher = new QFutureWatcher<uint>();
if(shared->loggingOn && speed > 0)
{
-
-
cv::Mat frame;
f.copyTo(frame);
cv::putText(frame, datestr.str(), dateOrg, fontFace, fontScale,
cv::Scalar::all(255), thickness, 8);
- (*shared->mWriter)<<frame;
- (*shared->mWriter)<<frame;
+ (*shared->mWriter) << frame;
+ (*shared->mWriter) << frame;
}
}
cv::namedWindow( "Hough Circle Transform Demo", CV_WINDOW_AUTOSIZE );
cv::imshow( "Hough Circle Transform Demo", img );
+}
+
+
+void OpenCvLuxPlugin::detectEyes(cv::Mat frame)
+{
+ bool hasEyes = false;
+ std::vector<cv::Rect> faces;
+ cv::Mat frameGray;
+ cv::ocl::oclMat gray2;
+
+ if(shared->useOpenCl)
+ {
+#ifdef OPENCL
+ cv::ocl::oclMat src(frame);
+ cv::ocl::cvtColor(src, gray2, CV_BGR2GRAY);
+ cv::ocl::equalizeHist(gray2, gray2);
+ faceCascade->detectMultiScale(gray2, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
+#endif
+ }
+ else
+ {
+ cv::cvtColor(frame, frameGray, CV_BGR2GRAY);
+ cv::equalizeHist(frameGray, frameGray);
+ faceCascade->detectMultiScale(frameGray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30));
+ }
+
+ for( size_t i = 0; i < faces.size(); i++ )
+ {
+ cv::Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
+ cv::ellipse( frame, center, cv::Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, cv::Scalar( 255, 0, 255 ), 4, 8, 0 );
+#ifdef OPENCL
+ cv::ocl::oclMat faceROI = gray2(faces[i]);
+#else
+ cv::Mat faceROI = frameGray(faces[i]);
+#endif
+ std::vector<cv::Rect> eyes;
+ //-- In each face, detect eyes
+ eyeCascade->detectMultiScale( faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, cv::Size(30, 30) );
+ if(eyes.size())
+ {
+ hasEyes = true;
+ DebugOut() << "Number of eyes: " << eyes.size() << endl;
+ }
+
+ for( size_t j = 0; j < eyes.size(); j++ )
+ {
+ cv::Point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );
+ int radius = cvRound( (eyes[j].width + eyes[j].height)*0.25 );
+ cv::circle( frame, center, radius, cv::Scalar( 255, 0, 0 ), 4, 8, 0 );
+ }
+ }
}