template<template< class > class A>
struct Simd::Detection< A >
The Detection structure provides object detection with using of HAAR and LBP cascade classifiers.
Using example (face detection in the image):
#include "Simd/SimdDetection.hpp"
#include "Simd/SimdDrawing.hpp"
int main()
{
image.Load("../../data/image/face/lena.pgm");
detection.Load("../../data/cascade/haar_face_0.xml");
detection.Init(image.Size());
detection.Detect(image, objects);
for (size_t i = 0; i < objects.size(); ++i)
image.Save("result.pgm");
return 0;
}
SIMD_INLINE void DrawRectangle(View< A > &canvas, const Rectangle< ptrdiff_t > &rect, const Color &color, size_t width=1)
Draws a rectangle at the image.
Definition: SimdDrawing.hpp:201
The Detection structure provides object detection with using of HAAR and LBP cascade classifiers.
Definition: SimdDetection.hpp:158
std::vector< Object > Objects
Definition: SimdDetection.hpp:206
Detection()
Definition: SimdDetection.hpp:211
Simd::View< A > View
Definition: SimdDetection.hpp:160
Using example (face detection in the video captured by OpenCV):
#include <iostream>
#include <string>
#include "opencv2/opencv.hpp"
#include "opencv2/core/utils/logger.hpp"
#ifndef SIMD_OPENCV_ENABLE
#define SIMD_OPENCV_ENABLE
#endif
#include "Simd/SimdDetection.hpp"
#include "Simd/SimdDrawing.hpp"
int main(int argc, char * argv[])
{
if (argc < 2)
{
std::cout << "You have to set video source! It can be 0 for camera or video file name." << std::endl;
return 1;
}
std::string source = argv[1], output = argc > 2 ? argv[2] : "";
cv::VideoCapture capture;
cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_ERROR);
if (source == "0")
capture.open(0);
else
capture.open(source);
if (!capture.isOpened())
{
std::cout << "Can't capture '" << source << "' !" << std::endl;
return 1;
}
int W = (int)capture.get(cv::CAP_PROP_FRAME_WIDTH);
int H = (int)capture.get(cv::CAP_PROP_FRAME_HEIGHT);
cv::VideoWriter writer;
if (output.size())
{
writer.open(output, cv::VideoWriter::fourcc('F', 'M', 'P', '4'), capture.get(cv::CAP_PROP_FPS), cv::Size(W, H));
if (!writer.isOpened())
{
std::cout << "Can't open output file '" << output << "' !" << std::endl;
return 1;
}
}
detection.Load("../../data/cascade/haar_face_0.xml");
const char * WINDOW_NAME = "FaceDetection";
cv::namedWindow(WINDOW_NAME, 1);
for (;;)
{
cv::Mat frame;
if (!capture.read(frame))
break;
detection.Detect(image, objects);
for (size_t i = 0; i < objects.size(); ++i)
cv::imshow(WINDOW_NAME, frame);
if (writer.isOpened())
writer.write(frame);
if (cv::waitKey(1) == 27)
break;
}
return 0;
}
Simd::Point< ptrdiff_t > Size
Definition: SimdDetection.hpp:161
24-bit BGR pixel.
Definition: SimdPixel.hpp:55
- Note
- This is wrapper around low-level Object Detection API.