Commit c470e15d authored by marina.kolpakova's avatar marina.kolpakova

integrate speprocessing strategy

parent d23a4f50
...@@ -1529,32 +1529,37 @@ public: ...@@ -1529,32 +1529,37 @@ public:
// ======================== GPU version for soft cascade ===================== // // ======================== GPU version for soft cascade ===================== //
// Implementation of soft (stageless) cascaded detector. class CV_EXPORTS ChannelsProcessor
class CV_EXPORTS SCascade : public Algorithm
{ {
public: public:
enum
enum { GENERIC = 1, SEPARABLE = 2};
class CV_EXPORTS Preprocessor
{ {
public: GENERIC = 1 << 4,
SEPARABLE = 2 << 4
};
// Appends specified number of HOG first-order features integrals into given vector. // Appends specified number of HOG first-order features integrals into given vector.
// Param frame is an input 3-channel bgr image. // Param frame is an input 3-channel bgr image.
// Param channels is a GPU matrix of integrals. // Param channels is a GPU matrix of optionally shrinked channels
// Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution. // Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution.
virtual void apply(InputArray frame, OutputArray channels, Stream& stream = Stream::Null()) = 0; virtual void apply(InputArray frame, OutputArray channels, Stream& stream = Stream::Null()) = 0;
// Creates a specific preprocessor implementation. // Creates a specific preprocessor implementation.
// Param shrinkage is a resizing factor. Resize is applied before the computing integral sum // Param shrinkage is a resizing factor. Resize is applied before the computing integral sum
// Param bins is a number of HOG-like channels. // Param bins is a number of HOG-like channels.
// Param method is a channel computing method. // Param flags is a channel computing extra flags.
static cv::Ptr<Preprocessor> create(const int shrinkage, const int bins, const int method = GENERIC); static cv::Ptr<ChannelsProcessor> create(const int shrinkage, const int bins, const int flags = GENERIC);
virtual ~ChannelsProcessor();
protected: protected:
Preprocessor(); ChannelsProcessor();
}; };
// Implementation of soft (stageless) cascaded detector.
class CV_EXPORTS SCascade : public Algorithm
{
public:
// Representation of detectors result. // Representation of detectors result.
struct CV_EXPORTS Detection struct CV_EXPORTS Detection
...@@ -1569,14 +1574,15 @@ public: ...@@ -1569,14 +1574,15 @@ public:
enum {PEDESTRIAN = 0}; enum {PEDESTRIAN = 0};
}; };
enum { NO_REJECT = 1, DOLLAR = 2, /*PASCAL = 4,*/ DEFAULT = NO_REJECT}; enum { NO_REJECT = 1, DOLLAR = 2, /*PASCAL = 4,*/ DEFAULT = NO_REJECT, NMS_MASK = 0xF};
// An empty cascade will be created. // An empty cascade will be created.
// Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed. // Param minScale is a minimum scale relative to the original size of the image on which cascade will be applyed.
// Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed. // Param minScale is a maximum scale relative to the original size of the image on which cascade will be applyed.
// Param scales is a number of scales from minScale to maxScale. // Param scales is a number of scales from minScale to maxScale.
// Param rejfactor is used for NMS. // Param flags is an extra tuning flags.
SCascade(const double minScale = 0.4, const double maxScale = 5., const int scales = 55, const int rejCriteria = 1); SCascade(const double minScale = 0.4, const double maxScale = 5., const int scales = 55,
const int flags = NO_REJECT || ChannelsProcessor::GENERIC);
virtual ~SCascade(); virtual ~SCascade();
...@@ -1598,13 +1604,6 @@ public: ...@@ -1598,13 +1604,6 @@ public:
// Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution // Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution
virtual void detect(InputArray image, InputArray rois, OutputArray objects, Stream& stream = Stream::Null()) const; virtual void detect(InputArray image, InputArray rois, OutputArray objects, Stream& stream = Stream::Null()) const;
// Convert ROI matrix into the suitable for detect method.
// Param roi is an input matrix of the same size as the image.
// There non zero value mean that detector should be executed in this point.
// Param mask is an output mask
// Param stream is stream is a high-level CUDA stream abstraction used for asynchronous execution
virtual void genRoi(InputArray roi, OutputArray mask, Stream& stream = Stream::Null()) const;
private: private:
struct Fields; struct Fields;
...@@ -1612,9 +1611,9 @@ private: ...@@ -1612,9 +1611,9 @@ private:
double minScale; double minScale;
double maxScale; double maxScale;
int scales; int scales;
int rejCriteria;
int flags;
}; };
CV_EXPORTS bool initModule_gpu(void); CV_EXPORTS bool initModule_gpu(void);
......
...@@ -71,15 +71,14 @@ RUN_GPU(SCascadeTest, detect) ...@@ -71,15 +71,14 @@ RUN_GPU(SCascadeTest, detect)
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1), trois; cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1); rois.setTo(1);
cascade.genRoi(rois, trois);
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
} }
SANITY_CHECK(sortDetections(objectBoxes)); SANITY_CHECK(sortDetections(objectBoxes));
...@@ -142,14 +141,11 @@ RUN_GPU(SCascadeTestRoi, detectInRoi) ...@@ -142,14 +141,11 @@ RUN_GPU(SCascadeTestRoi, detectInRoi)
sub.setTo(1); sub.setTo(1);
} }
cv::gpu::GpuMat trois; cascade.detect(colored, rois, objectBoxes);
cascade.genRoi(rois, trois);
cascade.detect(colored, trois, objectBoxes);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
} }
SANITY_CHECK(sortDetections(objectBoxes)); SANITY_CHECK(sortDetections(objectBoxes));
...@@ -186,14 +182,11 @@ RUN_GPU(SCascadeTestRoi, detectEachRoi) ...@@ -186,14 +182,11 @@ RUN_GPU(SCascadeTestRoi, detectEachRoi)
cv::gpu::GpuMat sub(rois, r); cv::gpu::GpuMat sub(rois, r);
sub.setTo(1); sub.setTo(1);
cv::gpu::GpuMat trois; cascade.detect(colored, rois, objectBoxes);
cascade.genRoi(rois, trois);
cascade.detect(colored, trois, objectBoxes);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
} }
SANITY_CHECK(sortDetections(objectBoxes)); SANITY_CHECK(sortDetections(objectBoxes));
...@@ -235,15 +228,14 @@ RUN_GPU(SCascadeTest, detectOnIntegral) ...@@ -235,15 +228,14 @@ RUN_GPU(SCascadeTest, detectOnIntegral)
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1), trois; cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1); rois.setTo(1);
cascade.genRoi(rois, trois);
cascade.detect(hogluv, trois, objectBoxes); cascade.detect(hogluv, rois, objectBoxes);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(hogluv, trois, objectBoxes); cascade.detect(hogluv, rois, objectBoxes);
} }
SANITY_CHECK(sortDetections(objectBoxes)); SANITY_CHECK(sortDetections(objectBoxes));
...@@ -270,18 +262,16 @@ RUN_GPU(SCascadeTest, detectStream) ...@@ -270,18 +262,16 @@ RUN_GPU(SCascadeTest, detectStream)
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1), trois; cv::gpu::GpuMat objectBoxes(1, 10000 * sizeof(cv::gpu::SCascade::Detection), CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(1); rois.setTo(1);
cv::gpu::Stream s; cv::gpu::Stream s;
cascade.genRoi(rois, trois, s); cascade.detect(colored, rois, objectBoxes, s);
cascade.detect(colored, trois, objectBoxes, s);
TEST_CYCLE() TEST_CYCLE()
{ {
cascade.detect(colored, trois, objectBoxes, s); cascade.detect(colored, rois, objectBoxes, s);
} }
#ifdef HAVE_CUDA #ifdef HAVE_CUDA
......
...@@ -46,10 +46,9 @@ namespace cv { namespace gpu ...@@ -46,10 +46,9 @@ namespace cv { namespace gpu
{ {
CV_INIT_ALGORITHM(SCascade, "CascadeDetector.SCascade", CV_INIT_ALGORITHM(SCascade, "CascadeDetector.SCascade",
obj.info()->addParam(obj, "minScale", obj.minScale); obj.info()->addParam(obj, "minScale", obj.minScale);
obj.info()->addParam(obj, "maxScale", obj.maxScale); obj.info()->addParam(obj, "maxScale", obj.maxScale);
obj.info()->addParam(obj, "scales", obj.scales); obj.info()->addParam(obj, "scales", obj.scales));
obj.info()->addParam(obj, "rejCriteria", obj.rejCriteria));
bool initModule_gpu(void) bool initModule_gpu(void)
{ {
......
This diff is collapsed.
...@@ -169,7 +169,7 @@ GPU_TEST_P(SCascadeTestRoi, detect, ...@@ -169,7 +169,7 @@ GPU_TEST_P(SCascadeTestRoi, detect,
ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode())); ASSERT_TRUE(cascade.load(fs.getFirstTopLevelNode()));
GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1), trois; GpuMat colored(coloredCpu), objectBoxes(1, 16384, CV_8UC1), rois(colored.size(), CV_8UC1);
rois.setTo(0); rois.setTo(0);
int nroi = GET_PARAM(3); int nroi = GET_PARAM(3);
...@@ -183,8 +183,8 @@ GPU_TEST_P(SCascadeTestRoi, detect, ...@@ -183,8 +183,8 @@ GPU_TEST_P(SCascadeTestRoi, detect,
cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1); cv::rectangle(result, r, cv::Scalar(0, 0, 255, 255), 1);
} }
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.genRoi(rois, trois);
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
cv::Mat dt(objectBoxes); cv::Mat dt(objectBoxes);
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
...@@ -239,10 +239,8 @@ GPU_TEST_P(SCascadeTestAll, detect, ...@@ -239,10 +239,8 @@ GPU_TEST_P(SCascadeTestAll, detect,
GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2)); GpuMat sub(rois, cv::Rect(rois.cols / 4, rois.rows / 4,rois.cols / 2, rois.rows / 2));
sub.setTo(cv::Scalar::all(1)); sub.setTo(cv::Scalar::all(1));
cv::gpu::GpuMat trois;
cascade.genRoi(rois, trois);
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(colored, trois, objectBoxes); cascade.detect(colored, rois, objectBoxes);
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes); cv::Mat detections(objectBoxes);
...@@ -279,10 +277,8 @@ GPU_TEST_P(SCascadeTestAll, detectOnIntegral, ...@@ -279,10 +277,8 @@ GPU_TEST_P(SCascadeTestAll, detectOnIntegral,
GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1); GpuMat objectBoxes(1, 100000, CV_8UC1), rois(cv::Size(640, 480), CV_8UC1);
rois.setTo(1); rois.setTo(1);
cv::gpu::GpuMat trois;
cascade.genRoi(rois, trois);
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(hogluv, trois, objectBoxes); cascade.detect(hogluv, rois, objectBoxes);
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes); cv::Mat detections(objectBoxes);
...@@ -315,12 +311,9 @@ GPU_TEST_P(SCascadeTestAll, detectStream, ...@@ -315,12 +311,9 @@ GPU_TEST_P(SCascadeTestAll, detectStream,
cv::gpu::Stream s; cv::gpu::Stream s;
cv::gpu::GpuMat trois;
cascade.genRoi(rois, trois, s);
objectBoxes.setTo(0); objectBoxes.setTo(0);
cascade.detect(colored, trois, objectBoxes, s); cascade.detect(colored, rois, objectBoxes, s);
s.waitForCompletion();
cudaDeviceSynchronize();
typedef cv::gpu::SCascade::Detection Detection; typedef cv::gpu::SCascade::Detection Detection;
cv::Mat detections(objectBoxes); cv::Mat detections(objectBoxes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment