@@ -508,29 +508,16 @@ void TrtYoloX::preprocess(const std::vector<cv::Mat> & images)
508
508
const float input_width = static_cast <float >(input_dims.d [3 ]);
509
509
std::vector<cv::Mat> dst_images;
510
510
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);
534
521
}
535
522
const auto chw_images = cv::dnn::blobFromImages (
536
523
dst_images, norm_factor_, cv::Size (), cv::Scalar (), false , false , CV_32F);
@@ -650,34 +637,21 @@ void TrtYoloX::preprocessWithRoi(
650
637
const float input_width = static_cast <float >(input_dims.d [3 ]);
651
638
std::vector<cv::Mat> dst_images;
652
639
scales_.clear ();
653
- bool letterbox = true ;
654
640
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++;
681
655
}
682
656
const auto chw_images = cv::dnn::blobFromImages (
683
657
dst_images, norm_factor_, cv::Size (), cv::Scalar (), false , false , CV_32F);
0 commit comments