Skip to content

Commit a373179

Browse files
committed
Fix bug with memory leak
1 parent 51a9ca3 commit a373179

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

example/VideoExample.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ void VideoExample::SyncProcess()
101101
regions_t regions;
102102
Detection(frame, regions);
103103
Tracking(frame, regions);
104-
105104
int64 t2 = cv::getTickCount();
106105

107106
allTime += t2 - t1;

example/examples.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ class YoloDarknetExample : public VideoExample
676676
break;
677677
}
678678
config.emplace("classNames", pathToModel + "coco.names");
679-
config.emplace("maxCropRatio", "1");
679+
config.emplace("maxCropRatio", "-1");
680680

681681
config.emplace("white_list", "person");
682682
config.emplace("white_list", "car");

src/Detector/YoloDarknetDetector.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void YoloDarknetDetector::Detect(const cv::UMat& colorFrame)
9898
for (size_t i = 0; i < crops.size(); ++i)
9999
{
100100
const auto& crop = crops[i];
101-
std::cout << "Crop " << i << ": " << crop << std::endl;
101+
//std::cout << "Crop " << i << ": " << crop << std::endl;
102102
DetectInCrop(colorMat, crop, tmpRegions);
103103
}
104104

@@ -112,10 +112,10 @@ void YoloDarknetDetector::Detect(const cv::UMat& colorFrame)
112112
[](const CRegion& reg) { return reg.m_confidence; },
113113
[](const CRegion& reg) { return reg.m_type; },
114114
0, 0.f);
115-
std::cout << "nms for " << tmpRegions.size() << " objects - result " << m_regions.size() << std::endl;
115+
//std::cout << "nms for " << tmpRegions.size() << " objects - result " << m_regions.size() << std::endl;
116116
}
117117
}
118-
//std::cout << "Finally " << m_regions.size() << " objects" << std::endl;
118+
//std::cout << "Finally " << m_regions.size() << " objects, " << colorMat.u->refcount << ", " << colorMat.u->urefcount << std::endl;
119119
}
120120

121121
///
@@ -144,9 +144,11 @@ void YoloDarknetDetector::DetectInCrop(const cv::Mat& colorFrame, const cv::Rect
144144
for (const bbox_t& bbox : detects)
145145
{
146146
if (m_classesWhiteList.empty() || m_classesWhiteList.find(m_classNames[bbox.obj_id]) != std::end(m_classesWhiteList))
147-
tmpRegions.emplace_back(cv::Rect(wk * bbox.x + crop.x, hk * bbox.y + crop.y, wk * bbox.w, hk * bbox.h), m_classNames[bbox.obj_id], bbox.prob);
147+
tmpRegions.emplace_back(cv::Rect(cvRound(wk * bbox.x) + crop.x, cvRound(hk * bbox.y) + crop.y, cvRound(wk * bbox.w), cvRound(hk * bbox.h)), m_classNames[bbox.obj_id], bbox.prob);
148148
}
149-
std::cout << "Detected " << detects.size() << " objects" << std::endl;
149+
if (crop.width == netSize.width && crop.height == netSize.height)
150+
m_tmpImg.release();
151+
//std::cout << "Detected " << detects.size() << " objects" << std::endl;
150152
}
151153

152154
///
@@ -174,9 +176,9 @@ void YoloDarknetDetector::Detect(const cv::Mat& colorFrame, regions_t& tmpRegion
174176
for (const bbox_t& bbox : detects)
175177
{
176178
if (m_classesWhiteList.empty() || m_classesWhiteList.find(m_classNames[bbox.obj_id]) != std::end(m_classesWhiteList))
177-
tmpRegions.emplace_back(cv::Rect(wk * bbox.x, hk * bbox.y, wk * bbox.w, hk * bbox.h), m_classNames[bbox.obj_id], bbox.prob);
179+
tmpRegions.emplace_back(cv::Rect(cvRound(wk * bbox.x), cvRound(hk * bbox.y), cvRound(wk * bbox.w), cvRound(hk * bbox.h)), m_classNames[bbox.obj_id], bbox.prob);
178180
}
179-
std::cout << "Detected " << detects.size() << " objects" << std::endl;
181+
//std::cout << "Detected " << detects.size() << " objects" << std::endl;
180182
}
181183

182184
///

0 commit comments

Comments
 (0)