0

I am detecting objects and sometimes the ROI area is smaller than the 100x100 and I want to use min 100x100 ROI area even if the object is smaller . I don't want to resize resulting cv::Mat because if the ROI is small area then it looks bad. It's okay to have ROI more than 100x100

How can I increase the ROI area to 100x100 without getting exception (within the image )?

barbsan
  • 3,418
  • 11
  • 21
  • 28
Lisa
  • 13
  • 4
  • In which sense "it looks bad" ? If you have a much smaller object than 100x100, an exact ROI and you want a larder ROI, what would you expect ideally ? – xiawi Jun 13 '19 at 19:42
  • When the object detected at distance its ROI smaller. so I want to increase the ROI after that to show 100x100 region. – Lisa Jun 14 '19 at 09:36
  • Sorry but I do not really understand. could you include some images to better explain your problem ? – xiawi Jun 14 '19 at 12:36
  • @xiawi for example face detection good example. face detected and cropped 50x50 . instead of resize this I want to increase that area withour resizing – Lisa Jun 15 '19 at 16:17

1 Answers1

0

Make a border of some size so that, the out matrix will have the desired size.

/*
enum BorderTypes {
    BORDER_CONSTANT    = 0, //!< `iiiiii|abcdefgh|iiiiiii`  with some specified `i`
    BORDER_REPLICATE   = 1, //!< `aaaaaa|abcdefgh|hhhhhhh`
    BORDER_REFLECT     = 2, //!< `fedcba|abcdefgh|hgfedcb`
    BORDER_WRAP        = 3, //!< `cdefgh|abcdefgh|abcdefg`
    BORDER_REFLECT_101 = 4, //!< `gfedcb|abcdefgh|gfedcba`
    BORDER_TRANSPARENT = 5, //!< `uvwxyz|abcdefgh|ijklmno`

    BORDER_REFLECT101  = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
    BORDER_DEFAULT     = BORDER_REFLECT_101, //!< same as BORDER_REFLECT_101
    BORDER_ISOLATED    = 16 //!< do not look outside of ROI
};

*/

cv::Mat out;

int top_border = ...
int bottom_border = ...
int left_border = ...
int right_border = ...

// Not sure that BORDER_TRANSPARENT is the best choice for
// your particular case. Check the other above (BORDER_CONSTANT may be better).
cv::copyMakeBorder(img, out, top_border, bottom_border,
                   left_border, right_border, cv::BORDER_TRANSPARENT);
Cynichniy Bandera
  • 5,991
  • 2
  • 29
  • 33