Cropping of images in c++ vs python
I got a strange error that I couldn't figure out where i went wrong.. I am trying to port from Python over to C++ the following cropping code:
In Python:
# x, y, w, h refers to the ROI for which the image is to be cropped.
img = cv2.imread('test.jpg')
cropped_img = img[y: y + h, x: x + w]
In C++:
auto img = cv::imread("test.jpg");
auto resized_img = img(cv::Rect(x, y, w, h));
The values used are exactly the same. However the c++ version throws the exception:
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows) in cv::Mat::Mat