results->indices.push_back(box.index);
results->names.push_back(mUserListName[box.index]);
results->confidences.push_back(box.score);
- results->locations.push_back(
- cv::Rect(static_cast<int>((box.location.x - box.location.width * 0.5f) *
- static_cast<float>(mSourceSize.width)),
- static_cast<int>((box.location.y - box.location.height * 0.5f) *
- static_cast<float>(mSourceSize.height)),
- static_cast<int>(box.location.width * static_cast<float>(mSourceSize.width)),
- static_cast<int>(box.location.height * static_cast<float>(mSourceSize.height))));
+ if (mMetadata.GetInputMeta().GetOption().begin()->second.resizer == Resizer::LETTERBOX) {
+ double srcW = static_cast<double>(mSourceSize.width);
+ double srcH = static_cast<double>(mSourceSize.height);
+ double dstW = static_cast<double>(mMetadata.GetInputMeta().GetLayer().begin()->second.getWidth());
+ double dstH = static_cast<double>(mMetadata.GetInputMeta().GetLayer().begin()->second.getHeight());
+ double scale = std::min(1.0, std::min(dstW/srcW, dstH/srcH));
+ double padSize[] = {(dstW - (scale*srcW))/2.0, (dstH - (scale*srcH))/2.0};
+
+ results->locations.push_back(cv::Rect(
+ static_cast<int>(std::min(srcW, std::max(((box.location.x - box.location.width * 0.5f) * dstW - padSize[0])/scale, 0.0))),
+ static_cast<int>(std::min(srcH, std::max(((box.location.y - box.location.height * 0.5f) * dstH - padSize[1])/scale, 0.0))),
+ static_cast<int>((box.location.width * dstW)/scale + padSize[0]),
+ static_cast<int>((box.location.height * dstH)/scale + padSize[1])
+ ));
+ results->locations.back().width = (results->locations.back().x + results->locations.back().width) > srcW ?
+ srcW - results->locations.back().x :
+ results->locations.back().width;
+ results->locations.back().height = (results->locations.back().y + results->locations.back().height) > srcH ?
+ srcH - results->locations.back().y :
+ results->locations.back().height;
+ } else {
+ results->locations.push_back(
+ cv::Rect(static_cast<int>((box.location.x - box.location.width * 0.5f) *
+ static_cast<float>(mSourceSize.width)),
+ static_cast<int>((box.location.y - box.location.height * 0.5f) *
+ static_cast<float>(mSourceSize.height)),
+ static_cast<int>(box.location.width * static_cast<float>(mSourceSize.width)),
+ static_cast<int>(box.location.height * static_cast<float>(mSourceSize.height))));
+ }
results->number_of_objects++;
}