remove debug imshow from code
This commit is contained in:
parent
8e092f8b5d
commit
5651743784
@ -501,6 +501,8 @@ public:
|
|||||||
int kind;
|
int kind;
|
||||||
|
|
||||||
enum {PEDESTRIAN = 0};
|
enum {PEDESTRIAN = 0};
|
||||||
|
|
||||||
|
Detection(const cv::Rect& r, const float c, int k = PEDESTRIAN) : rect(r), confidence(c), kind(k) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
//! An empty cascade will be created.
|
//! An empty cascade will be created.
|
||||||
|
@ -204,6 +204,7 @@ struct Level
|
|||||||
enum { R_SHIFT = 1 << 15 };
|
enum { R_SHIFT = 1 << 15 };
|
||||||
|
|
||||||
float scaling[2];
|
float scaling[2];
|
||||||
|
typedef cv::SoftCascade::Detection detection_t;
|
||||||
|
|
||||||
Level(const Octave& oct, const float scale, const int shrinkage, const int w, const int h)
|
Level(const Octave& oct, const float scale, const int shrinkage, const int w, const int h)
|
||||||
: octave(&oct), origScale(scale), relScale(scale / oct.scale), shrScale (relScale / (float)shrinkage),
|
: octave(&oct), origScale(scale), relScale(scale / oct.scale), shrScale (relScale / (float)shrinkage),
|
||||||
@ -215,12 +216,12 @@ struct Level
|
|||||||
scaleshift = relScale * (1 << 16);
|
scaleshift = relScale * (1 << 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
void markDetection(const int x, const int y, float confidence, std::vector<Object>& detections) const
|
void markDetection(const int x, const int y, float confidence, std::vector<detection_t>& detections) const
|
||||||
{
|
{
|
||||||
int shrinkage = (*octave).shrinkage;
|
int shrinkage = (*octave).shrinkage;
|
||||||
cv::Rect rect(cvRound(x * shrinkage), cvRound(y * shrinkage), objSize.width, objSize.height);
|
cv::Rect rect(cvRound(x * shrinkage), cvRound(y * shrinkage), objSize.width, objSize.height);
|
||||||
|
|
||||||
detections.push_back(Object(rect, confidence));
|
detections.push_back(detection_t(rect, confidence));
|
||||||
}
|
}
|
||||||
|
|
||||||
float rescale(cv::Rect& scaledRect, const float threshold, int idx) const
|
float rescale(cv::Rect& scaledRect, const float threshold, int idx) const
|
||||||
@ -432,7 +433,8 @@ struct cv::SoftCascade::Filds
|
|||||||
|
|
||||||
typedef std::vector<Octave>::iterator octIt_t;
|
typedef std::vector<Octave>::iterator octIt_t;
|
||||||
|
|
||||||
void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage, std::vector<Object>& detections) const
|
void detectAt(const int dx, const int dy, const Level& level, const ChannelStorage& storage,
|
||||||
|
std::vector<Detection>& detections) const
|
||||||
{
|
{
|
||||||
dprintf("detect at: %d %d\n", dx, dy);
|
dprintf("detect at: %d %d\n", dx, dy);
|
||||||
|
|
||||||
@ -685,12 +687,11 @@ bool cv::SoftCascade::load( const string& filename, const float minScale, const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEBUG_SHOW_RESULT
|
|
||||||
|
|
||||||
void cv::SoftCascade::detectMultiScale(const Mat& image, const std::vector<cv::Rect>& /*rois*/,
|
void cv::SoftCascade::detectMultiScale(const Mat& image, const std::vector<cv::Rect>& /*rois*/,
|
||||||
std::vector<Detection>& objects, const int /*rejectfactor*/) const
|
std::vector<Detection>& objects, const int /*rejectfactor*/) const
|
||||||
{
|
{
|
||||||
typedef std::vector<cv::Rect>::const_iterator RIter_t;
|
typedef std::vector<cv::Rect>::const_iterator RIter_t;
|
||||||
|
|
||||||
// only color images are supperted
|
// only color images are supperted
|
||||||
CV_Assert(image.type() == CV_8UC3);
|
CV_Assert(image.type() == CV_8UC3);
|
||||||
|
|
||||||
@ -704,49 +705,20 @@ void cv::SoftCascade::detectMultiScale(const Mat& image, const std::vector<cv::R
|
|||||||
// create integrals
|
// create integrals
|
||||||
ChannelStorage storage(image, fld.shrinkage);
|
ChannelStorage storage(image, fld.shrinkage);
|
||||||
|
|
||||||
// object candidates
|
|
||||||
std::vector<Object> detections;
|
|
||||||
|
|
||||||
typedef std::vector<Level>::const_iterator lIt;
|
typedef std::vector<Level>::const_iterator lIt;
|
||||||
int total = 0, l = 0;
|
|
||||||
for (lIt it = fld.levels.begin(); it != fld.levels.end(); ++it)
|
for (lIt it = fld.levels.begin(); it != fld.levels.end(); ++it)
|
||||||
{
|
{
|
||||||
const Level& level = *it;
|
const Level& level = *it;
|
||||||
|
|
||||||
#if defined WITH_DEBUG_OUT
|
|
||||||
std::cout << "================================ " << l++ << std::endl;
|
|
||||||
#else
|
|
||||||
(void)l;
|
|
||||||
#endif
|
|
||||||
// int dx = 79; int dy = 76;
|
|
||||||
for (int dy = 0; dy < level.workRect.height; ++dy)
|
for (int dy = 0; dy < level.workRect.height; ++dy)
|
||||||
{
|
{
|
||||||
for (int dx = 0; dx < level.workRect.width; ++dx)
|
for (int dx = 0; dx < level.workRect.width; ++dx)
|
||||||
{
|
{
|
||||||
storage.offset = dy * storage.step + dx;
|
storage.offset = dy * storage.step + dx;
|
||||||
fld.detectAt(dx, dy, level, storage, detections);
|
fld.detectAt(dx, dy, level, storage, objects);
|
||||||
|
}
|
||||||
total++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined DEBUG_SHOW_RESULT
|
|
||||||
cv::Mat out = image.clone();
|
|
||||||
|
|
||||||
printf("TOTAL: %d from %d\n", (int)detections.size(),total) ;
|
|
||||||
|
|
||||||
for(int i = 0; i < (int)detections.size(); ++i)
|
|
||||||
{
|
|
||||||
cv::rectangle(out, detections[i].rect, cv::Scalar(255, 0, 0, 255), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
cv::imshow("out", out);
|
|
||||||
cv::waitKey(0);
|
|
||||||
std::cout << "work rect: " << level.workRect.width << " " << level.workRect.height << std::endl;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
detections.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// std::swap(detections, objects);
|
|
||||||
}
|
}
|
@ -59,11 +59,36 @@ TEST(SoftCascade, detect)
|
|||||||
cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png");
|
cv::Mat colored = cv::imread(cvtest::TS::ptr()->get_data_path() + "cascadeandhog/bahnhof/image_00000000_0.png");
|
||||||
ASSERT_FALSE(colored.empty());
|
ASSERT_FALSE(colored.empty());
|
||||||
|
|
||||||
std::vector<detection_t> objectBoxes;
|
std::vector<detection_t> objects;
|
||||||
std::vector<cv::Rect> rois;
|
std::vector<cv::Rect> rois;
|
||||||
rois.push_back(cv::Rect(0, 0, 640, 480));
|
rois.push_back(cv::Rect(0, 0, 640, 480));
|
||||||
// ASSERT_NO_THROW(
|
|
||||||
// {
|
cascade.detectMultiScale(colored, rois, objects);
|
||||||
cascade.detectMultiScale(colored, rois, objectBoxes);
|
|
||||||
// });
|
std::cout << "detected: " << (int)objects.size() << std::endl;
|
||||||
|
|
||||||
|
cv::Mat out = colored.clone();
|
||||||
|
int level = 0, total = 0;
|
||||||
|
int levelWidth = objects[0].rect.width;
|
||||||
|
|
||||||
|
for(int i = 0 ; i < (int)objects.size(); ++i)
|
||||||
|
{
|
||||||
|
if (objects[i].rect.width != levelWidth)
|
||||||
|
{
|
||||||
|
std::cout << "Level: " << level << " total " << total << std::endl;
|
||||||
|
cv::imshow("out", out);
|
||||||
|
cv::waitKey(0);
|
||||||
|
|
||||||
|
out = colored.clone();
|
||||||
|
levelWidth = objects[i].rect.width;
|
||||||
|
total = 0;
|
||||||
|
level++;
|
||||||
|
}
|
||||||
|
cv::rectangle(out, objects[i].rect, cv::Scalar(255, 0, 0, 255), 1);
|
||||||
|
std::cout << "detection: " << objects[i].rect.x
|
||||||
|
<< " " << objects[i].rect.y
|
||||||
|
<< " " << objects[i].rect.width
|
||||||
|
<< " " << objects[i].rect.height << std::endl;
|
||||||
|
total++;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user