Skip to content

Instantly share code, notes, and snippets.

@Abusheik008
Created April 13, 2022 05:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abusheik008/22172bd88de7d8854daf10f491ee9df2 to your computer and use it in GitHub Desktop.
Save Abusheik008/22172bd88de7d8854daf10f491ee9df2 to your computer and use it in GitHub Desktop.
def crop(img, result):
global count
count += 1
for cls, objs in result.items():
if not os.path.exists(os.path.join(save_path, cls)):
os.mkdir(os.path.join(save_path, cls))
for x1, y1, x2, y2 in objs:
img_crop = img[y1:y2, x1:x2]
img_save = save_path + "/" + cls + "/" + cls + "_" + str(count) + ".jpg"
try:
cv2.imwrite(img_save, img_crop)
except:
print("Error Image", img_save)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment