Merge cuda-geek/soft-cascade-gpu into cuda-dev
This commit is contained in:
@@ -30,7 +30,7 @@ const Size2i preferredVideoFrameSize(640, 480);
|
||||
const string wndTitle = "NVIDIA Computer Vision :: Haar Classifiers Cascade";
|
||||
|
||||
|
||||
void matPrint(Mat &img, int lineOffsY, Scalar fontColor, const string &ss)
|
||||
static void matPrint(Mat &img, int lineOffsY, Scalar fontColor, const string &ss)
|
||||
{
|
||||
int fontFace = FONT_HERSHEY_DUPLEX;
|
||||
double fontScale = 0.8;
|
||||
@@ -45,7 +45,7 @@ void matPrint(Mat &img, int lineOffsY, Scalar fontColor, const string &ss)
|
||||
}
|
||||
|
||||
|
||||
void displayState(Mat &canvas, bool bHelp, bool bGpu, bool bLargestFace, bool bFilter, double fps)
|
||||
static void displayState(Mat &canvas, bool bHelp, bool bGpu, bool bLargestFace, bool bFilter, double fps)
|
||||
{
|
||||
Scalar fontColorRed = CV_RGB(255,0,0);
|
||||
Scalar fontColorNV = CV_RGB(118,185,0);
|
||||
@@ -74,7 +74,7 @@ void displayState(Mat &canvas, bool bHelp, bool bGpu, bool bLargestFace, bool bF
|
||||
}
|
||||
|
||||
|
||||
NCVStatus process(Mat *srcdst,
|
||||
static NCVStatus process(Mat *srcdst,
|
||||
Ncv32u width, Ncv32u height,
|
||||
NcvBool bFilterRects, NcvBool bLargestFace,
|
||||
HaarClassifierCascadeDescriptor &haar,
|
||||
@@ -281,7 +281,7 @@ int main(int argc, const char** argv)
|
||||
//==============================================================================
|
||||
|
||||
namedWindow(wndTitle, 1);
|
||||
Mat gray, frameDisp;
|
||||
Mat frameDisp;
|
||||
|
||||
do
|
||||
{
|
||||
|
@@ -59,7 +59,7 @@ public:
|
||||
class RgbToR
|
||||
{
|
||||
public:
|
||||
float operator ()(unsigned char b, unsigned char g, unsigned char r)
|
||||
float operator ()(unsigned char /*b*/, unsigned char /*g*/, unsigned char r)
|
||||
{
|
||||
return static_cast<float>(r)/255.0f;
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
class RgbToG
|
||||
{
|
||||
public:
|
||||
float operator ()(unsigned char b, unsigned char g, unsigned char r)
|
||||
float operator ()(unsigned char /*b*/, unsigned char g, unsigned char /*r*/)
|
||||
{
|
||||
return static_cast<float>(g)/255.0f;
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public:
|
||||
class RgbToB
|
||||
{
|
||||
public:
|
||||
float operator ()(unsigned char b, unsigned char g, unsigned char r)
|
||||
float operator ()(unsigned char b, unsigned char /*g*/, unsigned char /*r*/)
|
||||
{
|
||||
return static_cast<float>(b)/255.0f;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ NCVStatus CopyData(const IplImage *image, const NCVMatrixAlloc<Ncv32f> &dst)
|
||||
return NCV_SUCCESS;
|
||||
}
|
||||
|
||||
NCVStatus LoadImages (const char *frame0Name,
|
||||
static NCVStatus LoadImages (const char *frame0Name,
|
||||
const char *frame1Name,
|
||||
int &width,
|
||||
int &height,
|
||||
@@ -186,7 +186,7 @@ inline T MapValue (T x, T a, T b, T c, T d)
|
||||
return c + (d - c) * (x - a) / (b - a);
|
||||
}
|
||||
|
||||
NCVStatus ShowFlow (NCVMatrixAlloc<Ncv32f> &u, NCVMatrixAlloc<Ncv32f> &v, const char *name)
|
||||
static NCVStatus ShowFlow (NCVMatrixAlloc<Ncv32f> &u, NCVMatrixAlloc<Ncv32f> &v, const char *name)
|
||||
{
|
||||
IplImage *flowField;
|
||||
|
||||
@@ -246,7 +246,7 @@ NCVStatus ShowFlow (NCVMatrixAlloc<Ncv32f> &u, NCVMatrixAlloc<Ncv32f> &v, const
|
||||
return NCV_SUCCESS;
|
||||
}
|
||||
|
||||
IplImage *CreateImage (NCVMatrixAlloc<Ncv32f> &h_r, NCVMatrixAlloc<Ncv32f> &h_g, NCVMatrixAlloc<Ncv32f> &h_b)
|
||||
static IplImage *CreateImage (NCVMatrixAlloc<Ncv32f> &h_r, NCVMatrixAlloc<Ncv32f> &h_g, NCVMatrixAlloc<Ncv32f> &h_b)
|
||||
{
|
||||
CvSize imageSize = cvSize (h_r.width (), h_r.height ());
|
||||
IplImage *image = cvCreateImage (imageSize, IPL_DEPTH_8U, 4);
|
||||
@@ -270,7 +270,7 @@ IplImage *CreateImage (NCVMatrixAlloc<Ncv32f> &h_r, NCVMatrixAlloc<Ncv32f> &h_g,
|
||||
return image;
|
||||
}
|
||||
|
||||
void PrintHelp ()
|
||||
static void PrintHelp ()
|
||||
{
|
||||
std::cout << "Usage help:\n";
|
||||
std::cout << std::setiosflags(std::ios::left);
|
||||
@@ -286,7 +286,7 @@ void PrintHelp ()
|
||||
std::cout << "\t" << std::setw(15) << PARAM_HELP << " - display this help message\n";
|
||||
}
|
||||
|
||||
int ProcessCommandLine(int argc, char **argv,
|
||||
static int ProcessCommandLine(int argc, char **argv,
|
||||
Ncv32f &timeStep,
|
||||
char *&frame0Name,
|
||||
char *&frame1Name,
|
||||
|
106
samples/gpu/softcascade.cpp
Normal file
106
samples/gpu/softcascade.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
#include <opencv2/gpu/gpu.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const std::string keys =
|
||||
"{help h usage ? | | print this message }"
|
||||
"{cascade c | | path to configuration xml }"
|
||||
"{frames f | | path to configuration xml }"
|
||||
"{min_scale |0.4f | path to configuration xml }"
|
||||
"{max_scale |5.0f | path to configuration xml }"
|
||||
"{total_scales |55 | path to configuration xml }"
|
||||
"{device d |0 | path to configuration xml }"
|
||||
;
|
||||
|
||||
cv::CommandLineParser parser(argc, argv, keys);
|
||||
parser.about("Soft cascade training application.");
|
||||
|
||||
if (parser.has("help"))
|
||||
{
|
||||
parser.printMessage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!parser.check())
|
||||
{
|
||||
parser.printErrors();
|
||||
return 1;
|
||||
}
|
||||
|
||||
cv::gpu::setDevice(parser.get<int>("device"));
|
||||
|
||||
std::string cascadePath = parser.get<std::string>("cascade");
|
||||
|
||||
cv::FileStorage fs(cascadePath, cv::FileStorage::READ);
|
||||
if(!fs.isOpened())
|
||||
{
|
||||
std::cout << "Soft Cascade file " << cascadePath << " can't be opened." << std::endl << std::flush;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Read cascade from file " << cascadePath << std::endl;
|
||||
|
||||
float minScale = parser.get<float>("min_scale");
|
||||
float maxScale = parser.get<float>("max_scale");
|
||||
int scales = parser.get<int>("total_scales");
|
||||
|
||||
using cv::gpu::SCascade;
|
||||
SCascade cascade(minScale, maxScale, scales);
|
||||
|
||||
if (!cascade.load(fs.getFirstTopLevelNode()))
|
||||
{
|
||||
std::cout << "Soft Cascade can't be parsed." << std::endl << std::flush;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string frames = parser.get<std::string>("frames");
|
||||
cv::VideoCapture capture(frames);
|
||||
if(!capture.isOpened())
|
||||
{
|
||||
std::cout << "Frame source " << frames << " can't be opened." << std::endl << std::flush;
|
||||
return 1;
|
||||
}
|
||||
|
||||
cv::gpu::GpuMat objects(1, sizeof(SCascade::Detection) * 10000, CV_8UC1);
|
||||
cv::gpu::printShortCudaDeviceInfo(parser.get<int>("device"));
|
||||
for (;;)
|
||||
{
|
||||
cv::Mat frame;
|
||||
if (!capture.read(frame))
|
||||
{
|
||||
std::cout << "Nothing to read. " << std::endl << std::flush;
|
||||
return 0;
|
||||
}
|
||||
|
||||
cv::gpu::GpuMat dframe(frame), roi(frame.rows, frame.cols, CV_8UC1), trois;
|
||||
roi.setTo(cv::Scalar::all(1));
|
||||
cascade.genRoi(roi, trois);
|
||||
cascade.detect(dframe, trois, objects);
|
||||
|
||||
cv::Mat dt(objects);
|
||||
typedef cv::gpu::SCascade::Detection Detection;
|
||||
|
||||
Detection* dts = ((Detection*)dt.data) + 1;
|
||||
int* count = dt.ptr<int>(0);
|
||||
|
||||
std::cout << *count << std::endl;
|
||||
|
||||
cv::Mat result;
|
||||
frame.copyTo(result);
|
||||
|
||||
|
||||
for (int i = 0; i < *count; ++i)
|
||||
{
|
||||
Detection d = dts[i];
|
||||
cv::rectangle(result, cv::Rect(d.x, d.y, d.w, d.h), cv::Scalar(255, 0, 0, 255), 1);
|
||||
}
|
||||
|
||||
std::cout << "working..." << std::endl;
|
||||
cv::imshow("Soft Cascade demo", result);
|
||||
cv::waitKey(10);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user