# Revision history [back]

Your rectangle is getting out of the image, maybe with one pixel, and that is the problem.

Your rectangle is getting out of the image, maybe with one pixel, and that is the problem. I had the same case many times. I have solved it by adding a line like this:

cv::Rect roi = _rectangle & cv::Rect(0, 0, image.width, image.height);


Your rectangle is getting out of the image, maybe with one pixel, and that is the problem. I had the same case many times. I have solved it by adding a line like this:

cv::Rect roi = _rectangle & cv::Rect(0, 0, image.width, image.height);


Mat crop = frame(roi);


If you would like not to create another rect, then just update the existing one:

_rectangle = _rectangle & cv::Rect(0, 0, image.width, image.height);


Your rectangle is getting out of the image, maybe with one pixel, and that is the problem. I had the same case many times. I have solved it by adding a line like this:

cv::Rect roi = _rectangle & cv::Rect(0, 0, image.width, image.height);


Mat crop = frame(roi);

_rectangle = _rectangle & cv::Rect(0, 0, image.width, image.height);