-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
290 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,21 @@ | ||
#include "abstractfilter.h" | ||
|
||
AbstractFilter::AbstractFilter(QObject *parent) : QObject(parent) {} | ||
AbstractFilter::AbstractFilter(QObject *parent): | ||
QObject(parent), | ||
enabled(false) | ||
{} | ||
|
||
bool AbstractFilter::isEnabled() | ||
{ | ||
return enabled; | ||
} | ||
|
||
void AbstractFilter::setEnabled(bool enable) | ||
{ | ||
enabled = enable; | ||
} | ||
|
||
const QString &AbstractFilter::getName() | ||
{ | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,32 @@ | ||
#include "facedetectfilter.h" | ||
|
||
using namespace std; | ||
using namespace cv; | ||
|
||
FaceDetectFilter::FaceDetectFilter(QObject *parent): AbstractFilter(parent) | ||
{ | ||
face_cascade_gpu = cv::cuda::CascadeClassifier::create("/media/zaak/Data/dev/CamGrab/opencv/data/haarcascades_cuda/haarcascade_frontalface_alt2.xml"); | ||
name = "Face detect"; | ||
faceCascadeFilterGPU = cv::cuda::CascadeClassifier::create("/media/zaak/Data/dev/CamGrab/opencv/data/haarcascades_cuda/haarcascade_frontalface_alt2.xml"); | ||
} | ||
|
||
void FaceDetectFilter::apply(cv::Mat &mat) | ||
{ | ||
std::vector<Rect> faces; | ||
Mat frame_gray; | ||
Mat crop; | ||
Mat res; | ||
Mat gray; | ||
string text; | ||
stringstream sstm; | ||
|
||
cvtColor(mat, frame_gray, COLOR_BGR2GRAY); | ||
equalizeHist(frame_gray, frame_gray); | ||
|
||
cv::cuda::GpuMat frame_gpu(frame_gray); | ||
cv::cuda::GpuMat objbuf_gpu; | ||
|
||
// Detect faces | ||
face_cascade_gpu->detectMultiScale(frame_gpu, objbuf_gpu); | ||
face_cascade_gpu->convert(objbuf_gpu, faces); | ||
|
||
// Set Region of Interest | ||
cv::Rect roi_b; | ||
cv::Rect roi_c; | ||
|
||
size_t ic = 0; // ic is index of current element | ||
int ac = 0; // ac is area of current element | ||
|
||
size_t ib = 0; // ib is index of biggest element | ||
int ab = 0; // ab is area of biggest element | ||
|
||
for (ic = 0; ic < faces.size(); ic++) // Iterate through all current elements (detected faces) | ||
|
||
{ | ||
roi_c.x = faces[ic].x; | ||
roi_c.y = faces[ic].y; | ||
roi_c.width = (faces[ic].width); | ||
roi_c.height = (faces[ic].height); | ||
|
||
ac = roi_c.width * roi_c.height; // Get the area of current element (detected face) | ||
|
||
roi_b.x = faces[ib].x; | ||
roi_b.y = faces[ib].y; | ||
roi_b.width = (faces[ib].width); | ||
roi_b.height = (faces[ib].height); | ||
|
||
ab = roi_b.width * roi_b.height; // Get the area of biggest element, at beginning it is same as "current" element | ||
|
||
if (ac > ab) | ||
{ | ||
ib = ic; | ||
roi_b.x = faces[ib].x; | ||
roi_b.y = faces[ib].y; | ||
roi_b.width = (faces[ib].width); | ||
roi_b.height = (faces[ib].height); | ||
} | ||
|
||
Point pt1(faces[ic].x, faces[ic].y); // Display detected faces on main window - live stream from camera | ||
Point pt2((faces[ic].x + faces[ic].height), (faces[ic].y + faces[ic].width)); | ||
cv::rectangle(mat, pt1, pt2, Scalar(0, 255, 0), 2, 8, 0); | ||
} | ||
std::vector<cv::Rect> faces; | ||
cv::Mat grayedFrame; | ||
cv::Mat crop; | ||
cv::Mat res; | ||
cv::Mat gray; | ||
|
||
cv::cvtColor(mat, grayedFrame, cv::COLOR_BGR2GRAY); | ||
cv::equalizeHist(grayedFrame, grayedFrame); | ||
|
||
cv::cuda::GpuMat frameGPU(grayedFrame); | ||
cv::cuda::GpuMat objectBufferGPU; | ||
|
||
faceCascadeFilterGPU->detectMultiScale(frameGPU, objectBufferGPU); | ||
faceCascadeFilterGPU->convert(objectBufferGPU, faces); | ||
|
||
for (cv::Rect &face : faces) | ||
{ | ||
cv::Point pt1(face.x, face.y); | ||
cv::Point pt2(face.x + face.height, face.y + face.width); | ||
cv::rectangle(mat, pt1, pt2, cv::Scalar(0, 255, 0), 2, 8, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include "grayscalefilter.h" | ||
|
||
GrayscaleFilter::GrayscaleFilter(QObject *parent): AbstractFilter(parent) | ||
{ | ||
name = "Grayscale"; | ||
} | ||
|
||
void GrayscaleFilter::apply(cv::Mat &mat) | ||
{ | ||
cv::Mat grayed; | ||
|
||
cv::cvtColor(mat, grayed, cv::COLOR_BGR2GRAY); | ||
cv::cvtColor(grayed, mat, cv::COLOR_GRAY2BGR); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef GRAYSCALEFILTER_H | ||
#define GRAYSCALEFILTER_H | ||
|
||
#include <opencv2/imgproc.hpp> | ||
#include "abstractfilter.h" | ||
|
||
class GrayscaleFilter : public AbstractFilter | ||
{ | ||
public: | ||
explicit GrayscaleFilter(QObject *parent = nullptr); | ||
void apply(cv::Mat &mat); | ||
}; | ||
|
||
#endif // GRAYSCALEFILTER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.