Skip to content

Commit 374703e

Browse files
veqccpre-commit-ci[bot]
authored andcommitted
fix(tensorrt_yolox): fix knownConditionTrueFalse (autowarefoundation#7823)
* fix(tensorrt_yolox): fix knownConditionTrueFalse Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> * style(pre-commit): autofix --------- Signed-off-by: Ryuta Kambe <ryuta.kambe@tier4.jp> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c16edbe commit 374703e

File tree

1 file changed

+24
-50
lines changed

1 file changed

+24
-50
lines changed

perception/tensorrt_yolox/src/tensorrt_yolox.cpp

+24-50
Original file line numberDiff line numberDiff line change
@@ -508,29 +508,16 @@ void TrtYoloX::preprocess(const std::vector<cv::Mat> & images)
508508
const float input_width = static_cast<float>(input_dims.d[3]);
509509
std::vector<cv::Mat> dst_images;
510510
scales_.clear();
511-
bool letterbox = true;
512-
if (letterbox) {
513-
for (const auto & image : images) {
514-
cv::Mat dst_image;
515-
const float scale = std::min(input_width / image.cols, input_height / image.rows);
516-
scales_.emplace_back(scale);
517-
const auto scale_size = cv::Size(image.cols * scale, image.rows * scale);
518-
cv::resize(image, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
519-
const auto bottom = input_height - dst_image.rows;
520-
const auto right = input_width - dst_image.cols;
521-
copyMakeBorder(
522-
dst_image, dst_image, 0, bottom, 0, right, cv::BORDER_CONSTANT, {114, 114, 114});
523-
dst_images.emplace_back(dst_image);
524-
}
525-
} else {
526-
for (const auto & image : images) {
527-
cv::Mat dst_image;
528-
const float scale = -1.0;
529-
scales_.emplace_back(scale);
530-
const auto scale_size = cv::Size(input_width, input_height);
531-
cv::resize(image, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
532-
dst_images.emplace_back(dst_image);
533-
}
511+
for (const auto & image : images) {
512+
cv::Mat dst_image;
513+
const float scale = std::min(input_width / image.cols, input_height / image.rows);
514+
scales_.emplace_back(scale);
515+
const auto scale_size = cv::Size(image.cols * scale, image.rows * scale);
516+
cv::resize(image, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
517+
const auto bottom = input_height - dst_image.rows;
518+
const auto right = input_width - dst_image.cols;
519+
copyMakeBorder(dst_image, dst_image, 0, bottom, 0, right, cv::BORDER_CONSTANT, {114, 114, 114});
520+
dst_images.emplace_back(dst_image);
534521
}
535522
const auto chw_images = cv::dnn::blobFromImages(
536523
dst_images, norm_factor_, cv::Size(), cv::Scalar(), false, false, CV_32F);
@@ -650,34 +637,21 @@ void TrtYoloX::preprocessWithRoi(
650637
const float input_width = static_cast<float>(input_dims.d[3]);
651638
std::vector<cv::Mat> dst_images;
652639
scales_.clear();
653-
bool letterbox = true;
654640
int b = 0;
655-
if (letterbox) {
656-
for (const auto & image : images) {
657-
cv::Mat dst_image;
658-
cv::Mat cropped = image(rois[b]);
659-
const float scale = std::min(
660-
input_width / static_cast<float>(rois[b].width),
661-
input_height / static_cast<float>(rois[b].height));
662-
scales_.emplace_back(scale);
663-
const auto scale_size = cv::Size(rois[b].width * scale, rois[b].height * scale);
664-
cv::resize(cropped, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
665-
const auto bottom = input_height - dst_image.rows;
666-
const auto right = input_width - dst_image.cols;
667-
copyMakeBorder(
668-
dst_image, dst_image, 0, bottom, 0, right, cv::BORDER_CONSTANT, {114, 114, 114});
669-
dst_images.emplace_back(dst_image);
670-
b++;
671-
}
672-
} else {
673-
for (const auto & image : images) {
674-
cv::Mat dst_image;
675-
const float scale = -1.0;
676-
scales_.emplace_back(scale);
677-
const auto scale_size = cv::Size(input_width, input_height);
678-
cv::resize(image, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
679-
dst_images.emplace_back(dst_image);
680-
}
641+
for (const auto & image : images) {
642+
cv::Mat dst_image;
643+
cv::Mat cropped = image(rois[b]);
644+
const float scale = std::min(
645+
input_width / static_cast<float>(rois[b].width),
646+
input_height / static_cast<float>(rois[b].height));
647+
scales_.emplace_back(scale);
648+
const auto scale_size = cv::Size(rois[b].width * scale, rois[b].height * scale);
649+
cv::resize(cropped, dst_image, scale_size, 0, 0, cv::INTER_CUBIC);
650+
const auto bottom = input_height - dst_image.rows;
651+
const auto right = input_width - dst_image.cols;
652+
copyMakeBorder(dst_image, dst_image, 0, bottom, 0, right, cv::BORDER_CONSTANT, {114, 114, 114});
653+
dst_images.emplace_back(dst_image);
654+
b++;
681655
}
682656
const auto chw_images = cv::dnn::blobFromImages(
683657
dst_images, norm_factor_, cv::Size(), cv::Scalar(), false, false, CV_32F);

0 commit comments

Comments
 (0)