Skip to content

Commit e21a29b

Browse files
authored
Merge pull request #2531 from Wovchena/demos-reshape-after-shape-verification-make-sure-personRects.begin-returns-non-end-iterator
demos: reshape after shape verification, make sure personRects.begin(); returns non end iterator
2 parents 0493d06 + f0c1460 commit e21a29b

File tree

2 files changed

+38
-35
lines changed

2 files changed

+38
-35
lines changed

demos/common/cpp/models/src/deblurring_model.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ DeblurringModel::DeblurringModel(const std::string& modelFileName, const cv::Siz
2929
void DeblurringModel::prepareInputsOutputs(CNNNetwork& cnnNetwork) {
3030
// --------------------------- Configure input & output -------------------------------------------------
3131
// --------------------------- Prepare input blobs ------------------------------------------------------
32-
changeInputSize(cnnNetwork);
3332

3433
ICNNNetwork::InputShapes inputShapes = cnnNetwork.getInputShapes();
3534
if (inputShapes.size() != 1)
@@ -52,6 +51,8 @@ void DeblurringModel::prepareInputsOutputs(CNNNetwork& cnnNetwork) {
5251
const SizeVector& outSizeVector = data.getTensorDesc().getDims();
5352
if (outSizeVector.size() != 4 || outSizeVector[0] != 1 || outSizeVector[1] != 3)
5453
throw std::runtime_error("3-channel 4-dimensional model's output is expected");
54+
55+
changeInputSize(cnnNetwork);
5556
}
5657

5758
void DeblurringModel::changeInputSize(CNNNetwork& cnnNetwork) {

demos/social_distance_demo/cpp/main.cpp

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -518,43 +518,45 @@ bool DetectionsProcessor::isReady() {
518518
}
519519

520520
void DetectionsProcessor::process() {
521-
Context& context = static_cast<ReborningVideoFrame*>(sharedVideoFrame.get())->context;
522-
523-
if (!FLAGS_m_reid.empty()) {
524-
auto personRectsIt = personRects.begin();
525-
526-
for (auto reidRequestsIt = reservedReIdRequests.begin(); reidRequestsIt != reservedReIdRequests.end(); personRectsIt++, reidRequestsIt++) {
527-
const cv::Rect personRect = *personRectsIt;
528-
InferRequest& reidRequest = *reidRequestsIt;
529-
context.detectionsProcessorsContext.reid.setImage(reidRequest, sharedVideoFrame->frame, personRect);
530-
531-
reidRequest.SetCompletionCallback(
532-
std::bind([](std::shared_ptr<ClassifiersAggregator> classifiersAggregator,
533-
InferRequest &reidRequest, cv::Rect rect, Context &context) {
534-
reidRequest.SetCompletionCallback([] {}); // destroy the stored bind object
535-
std::vector<float> result = context.detectionsProcessorsContext.reid.getResults(reidRequest);
536-
537-
classifiersAggregator->push(cv::Rect(rect));
538-
classifiersAggregator->push(TrackableObject{rect,
539-
std::move(result), {rect.x + rect.width / 2, rect.y + rect.height } });
540-
context.reidInfers.inferRequests.lockedPushBack(reidRequest);
541-
},
542-
classifiersAggregator, std::ref(reidRequest), personRect, std::ref(context)));
521+
if (!personRects.empty()) {
522+
Context& context = static_cast<ReborningVideoFrame*>(sharedVideoFrame.get())->context;
543523

544-
reidRequest.StartAsync();
545-
}
546-
personRects.erase(personRects.begin(), personRectsIt);
547-
} else {
548-
for (const cv::Rect& personRect : personRects) {
549-
classifiersAggregator->push(cv::Rect(personRect));
524+
if (!FLAGS_m_reid.empty()) {
525+
auto personRectsIt = personRects.begin();
526+
527+
for (auto reidRequestsIt = reservedReIdRequests.begin(); reidRequestsIt != reservedReIdRequests.end(); personRectsIt++, reidRequestsIt++) {
528+
const cv::Rect personRect = *personRectsIt;
529+
InferRequest& reidRequest = *reidRequestsIt;
530+
context.detectionsProcessorsContext.reid.setImage(reidRequest, sharedVideoFrame->frame, personRect);
531+
532+
reidRequest.SetCompletionCallback(
533+
std::bind([](std::shared_ptr<ClassifiersAggregator> classifiersAggregator,
534+
InferRequest &reidRequest, cv::Rect rect, Context &context) {
535+
reidRequest.SetCompletionCallback([] {}); // destroy the stored bind object
536+
std::vector<float> result = context.detectionsProcessorsContext.reid.getResults(reidRequest);
537+
538+
classifiersAggregator->push(cv::Rect(rect));
539+
classifiersAggregator->push(TrackableObject{rect,
540+
std::move(result), {rect.x + rect.width / 2, rect.y + rect.height } });
541+
context.reidInfers.inferRequests.lockedPushBack(reidRequest);
542+
},
543+
classifiersAggregator, std::ref(reidRequest), personRect, std::ref(context)));
544+
545+
reidRequest.StartAsync();
546+
}
547+
personRects.erase(personRects.begin(), personRectsIt);
548+
} else {
549+
for (const cv::Rect& personRect : personRects) {
550+
classifiersAggregator->push(cv::Rect(personRect));
551+
}
552+
personRects.clear();
550553
}
551-
personRects.clear();
552-
}
553554

554-
// Run DetectionsProcessor for remaining persons
555-
if (!personRects.empty()) {
556-
tryPush(context.detectionsProcessorsContext.reidTasksWorker,
557-
std::make_shared<DetectionsProcessor>(sharedVideoFrame, std::move(classifiersAggregator), std::move(personRects)));
555+
// Run DetectionsProcessor for remaining persons
556+
if (!personRects.empty()) {
557+
tryPush(context.detectionsProcessorsContext.reidTasksWorker,
558+
std::make_shared<DetectionsProcessor>(sharedVideoFrame, std::move(classifiersAggregator), std::move(personRects)));
559+
}
558560
}
559561
}
560562

0 commit comments

Comments
 (0)