'How ROI coordinates in opencv works

How exactly coordinates in ROI works? For example, I have image size of 450x280 (got it from opencv documentation). I want to select a ball. In documentation it says that ball = img[280:340, 330:390], but that doesn't work for me, if I try cv2.imshow("Image", ball) I get this: error: (-215:Assertion failed) size.width>0 && size.height>0 in function 'cv::imshow'. So I tried to try different coordinates and it's totally confused me. After a lot of errors I came to this (ball = img[235:275, 250:320]). How exactly this numbers works? What is that grey zone to the right? enter image description here

Original image

enter image description here

Result with coordinates [235:275, 250:320]



Solution 1:[1]

Ok. Got it. Grey zone is just me being stupid. But the way coordinates works is kinda dumb. So, our ball fits in square with coordinates 277:235 (top left) and 320:290 (bottom right). For some reason in opencv it looks like [235:290, 277:320]. Y's comes first enter image description here

Solution 2:[2]

In opencv you can do it like [x:x1,y:y1],(for example: [235:290, 277:320]) where (x,y) is one coordinate and (x1,y1) is another.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Mushfirat Mohaimin