Created
April 13, 2022 05:09
-
-
Save Abusheik008/22172bd88de7d8854daf10f491ee9df2 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
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