Skip to content

Commit 5eb01cd

Browse files
committed
Added objects type
1 parent da22d84 commit 5eb01cd

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

Detector/DNNDetector.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void DNNDetector::Detect(cv::UMat& colorFrame)
7070
cv::Mat detection = m_net.forward("detection_out"); //compute output
7171

7272
std::vector<double> layersTimings;
73-
double freq = cv::getTickFrequency() / 1000;
74-
double time = m_net.getPerfProfile(layersTimings) / freq;
73+
//double freq = cv::getTickFrequency() / 1000;
74+
//double time = m_net.getPerfProfile(layersTimings) / freq;
7575

7676
cv::Mat detectionMat(detection.size[2], detection.size[3], CV_32F, detection.ptr<float>());
7777

@@ -98,12 +98,12 @@ void DNNDetector::Detect(cv::UMat& colorFrame)
9898

9999
cv::Rect object((int)xLeftBottom, (int)yLeftBottom, (int)(xRightTop - xLeftBottom), (int)(yRightTop - yLeftBottom));
100100

101-
m_regions.push_back(object);
101+
m_regions.push_back(CRegion(object, classNames[objectClass], confidence));
102102

103103
//cv::rectangle(frame, object, Scalar(0, 255, 0));
104-
std::string label = classNames[objectClass] + ": " + std::to_string(confidence);
105-
int baseLine = 0;
106-
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
104+
//std::string label = classNames[objectClass] + ": " + std::to_string(confidence);
105+
//int baseLine = 0;
106+
//cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
107107
//cv::rectangle(frame, cv::Rect(cv::Point(xLeftBottom, yLeftBottom - labelSize.height), cv::Size(labelSize.width, labelSize.height + baseLine)), cv::Scalar(255, 255, 255), CV_FILLED);
108108
//cv::putText(frame, label, Point(xLeftBottom, yLeftBottom), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0,0,0));
109109
}

VideoExample.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,13 @@ class DNNDetectorExample : public VideoExample
612612
)
613613
{
614614
DrawTrack(frame, 1, *track);
615+
616+
std::string label = track->m_lastRegion.m_type + ": " + std::to_string(track->m_lastRegion.m_confidence);
617+
int baseLine = 0;
618+
cv::Size labelSize = cv::getTextSize(label, cv::FONT_HERSHEY_SIMPLEX, 0.5, 1, &baseLine);
619+
auto rect(track->GetLastRect());
620+
cv::rectangle(frame, cv::Rect(cv::Point(rect.x, rect.y - labelSize.height), cv::Size(labelSize.width, labelSize.height + baseLine)), cv::Scalar(255, 255, 255), CV_FILLED);
621+
cv::putText(frame, label, cv::Point(rect.x, rect.y), cv::FONT_HERSHEY_SIMPLEX, 0.5, cv::Scalar(0, 0, 0));
615622
}
616623
}
617624

defines.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class CRegion
1818
{
1919
public:
2020
CRegion()
21+
: m_type(""), m_confidence(-1)
2122
{
2223
}
2324

@@ -27,8 +28,17 @@ class CRegion
2728

2829
}
2930

31+
CRegion(const cv::Rect& rect, const std::string& type, float confidence)
32+
: m_rect(rect), m_type(type), m_confidence(confidence)
33+
{
34+
35+
}
36+
3037
cv::Rect m_rect;
3138
std::vector<cv::Point2f> m_points;
39+
40+
std::string m_type;
41+
float m_confidence;
3242
};
3343

3444
typedef std::vector<CRegion> regions_t;

0 commit comments

Comments
 (0)