Skip to content

Instantly share code, notes, and snippets.

@aravindpai

aravindpai/11_6.py

Last active May 22, 2020
Embed
What would you like to do?
!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
You can’t perform that action at this time.