How to identify the correct coordinates for cropping image

I am using a face detection library(retina-face) to detect face on the following image

The library being used is retina-face which gives bounding box coordinates in the format (x1,y1,x2,y2).
The Bounding box for the face is as follows
face_area=[242, 92, 269, 129]

Now,when I run the following part of the code,I am able to draw the bounding box on the image to represent the face


The result of this is as follows

But when I use slicing to just obtain the face part of the image either I run into zero-sized array error or I get an incorrect result.
I am trying to crop as follows


The incorrect crop is shown below

Any idea what I am doing wrong here,and is there a better way to crop rather than using slicing

you just got the order of the coords wrong,
if you get (x1, y1, x2, y2) from the detection, the correct numpy slice is::

img[y1:y2, x1:x2] 

also your cv2.rectangle() coords should better be:

(x1,y1), (x2,y2)
1 Like

Thanks for the tip,I was able to get the result.On a side note the cropped image tends to be extremely coarse as shown below
I am currently upsampling it using cv2.pyrUp and then resize it to (256,256) to get this image
Would you recommend that’s the correct approach. I am looking for a better image where the eyes can be clearly seen as shown in the original image