Pergunta

I have bounding box and I want to crop image with this bounding box.

However I want to increase the size of the bounding box, so I do

if ((roi_.x - 5) > 0) // i test here in case the component at the left near border we do not minus otherwise it will be error
{
    roi_.x += (-5);
}
if ((roi_.y - 5) > 0) // i test here in case the component at the left near border we do not minus otherwise it will be error
{
    roi_.y += (-5);
}
if (&(roi_ + cv::Size(10, 0)) != NULL)
{
    roi_.width += 10;
}
if (&(roi_ + cv::Size(0, 10)) != NULL)
{
    roi_.height += 10;
}

For the component at the most right near the border if I increase the width it will be error. The same thing for the height in case the component is at the bottom near the border

Are there any ways to handle this exception?

Foi útil?

Solução

You get the error because & requires the l-value, which are not for both roi_ + cv::Size(10, 0) and roi_ + cv::Size(0, 10).

You need to change

if (&(roi_ + cv::Size(10, 0)) != NULL)
...
if (&(roi_ + cv::Size(0, 10)) != NULL)

to

if ((roi_.x + roi_.width + 10) < img.cols)
...
if ((roi_.y + roi_.height + 10) < img.rows)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top