How can I crop images, like I\'ve done before in PIL, using OpenCV.
Working example on PIL
im = Image.open(\'0.png\').convert(\'L\')
im = im.crop((1
i had this question and found another answer here: copy region of interest
If we consider (0,0) as top left corner of image called im
with left-to-right as x direction and top-to-bottom as y direction. and we have (x1,y1) as the top-left vertex and (x2,y2) as the bottom-right vertex of a rectangle region within that image, then:
roi = im[y1:y2, x1:x2]
here is a comprehensive resource on numpy array indexing and slicing which can tell you more about things like cropping a part of an image. images would be stored as a numpy array in opencv2.
:)