def crop_out(img,x1,y1,x2,y2,b,h):
'''
This function is used to crop the image into desired dimmensions.
img: image from which the rectangle is to be cropped
x1,y1: top left vertex parameter
x2,y2: bottom right parameter
b,h: dimmesions of the cropped image
'''
xa=x1
xb=x2
xc=x1
xd=x2
ya=y1
yb=y1
yc=y2
yd=y2
pts1 = np.float32([[xa,ya],[xc,yc],[xb,yb],[xd,yd]])
pts2 = np.float32([[0,0],[0,h],[b,0],[b,h]])
persM = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img,persM,(b,h))
return dst
#detection begins here
评论列表
文章目录