Ask Your Question
0

Error Exception Handling For Cv::Rect opencv in C++

asked 2014-02-17 10:20:11 -0600

vsay gravatar image

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?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-02-17 16:36:37 -0600

Nghia gravatar image

updated 2014-02-17 16:48:27 -0600

berak gravatar image

Your last 2 checks look rather strange. Just do

if (roi_.x + roi_.width + 10 < img.cols) 
    roi_.width += 10;

if (roi_.y + roi_.height + 10 < img.rows) 
    roi_.height += 10;
edit flag offensive delete link more

Comments

The last two check, i tried to avoid the error when i increase the width and heigth of the rect where the component are too near to the border 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

vsay gravatar imagevsay ( 2014-02-18 09:12:24 -0600 )edit

Question Tools

Stats

Asked: 2014-02-17 10:20:11 -0600

Seen: 915 times

Last updated: Feb 17 '14