Last active
December 6, 2022 10:49
-
-
Save aravindpai/d5b90297d55f00f2641281536fc0d585 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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