Skip to content

Instantly share code, notes, and snippets.

@aravindpai
Last active December 6, 2022 10:49
Show Gist options
  • Save aravindpai/d5b90297d55f00f2641281536fc0d585 to your computer and use it in GitHub Desktop.
Save aravindpai/d5b90297d55f00f2641281536fc0d585 to your computer and use it in GitHub Desktop.
!rm -r patch/*
num=20
cnt=0
for i in range(len(contours)):
x,y,w,h = cv2.boundingRect(contours[i])
numer=min([w,h])
denom=max([w,h])
ratio=numer/denom
if(x>=num and y>=num):
xmin, ymin= x-num, y-num
xmax, ymax= x+w+num, y+h+num
else:
xmin, ymin=x, y
xmax, ymax=x+w, y+h
if(ratio>=0.5 and ((w<=10) and (h<=10)) ):
print(cnt,x,y,w,h,ratio)
cv2.imwrite("patch/"+str(cnt)+".png",img[ymin:ymax,xmin:xmax])
cnt=cnt+1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment