Commit 2fe06b7fce991c955dd4809fec2072f809376918
1 parent
05cbdcd9
Exists in
master
and in
1 other branch
staged.
Showing
1 changed file
with
5 additions
and
4 deletions
Show diff stats
mdata/crop.py
@@ -20,7 +20,7 @@ def crop_Test(): | @@ -20,7 +20,7 @@ def crop_Test(): | ||
20 | print image | 20 | print image |
21 | 21 | ||
22 | # try: | 22 | # try: |
23 | - # im = Image.open(image) | 23 | + # im = Image.open(image) |
24 | # w, h = im.size | 24 | # w, h = im.size |
25 | # if w < 300 or h < 300: | 25 | # if w < 300 or h < 300: |
26 | # continue | 26 | # continue |
@@ -33,15 +33,16 @@ def crop_Test(): | @@ -33,15 +33,16 @@ def crop_Test(): | ||
33 | try: | 33 | try: |
34 | img = cv2.imread(image, cv2.CV_LOAD_IMAGE_UNCHANGED) | 34 | img = cv2.imread(image, cv2.CV_LOAD_IMAGE_UNCHANGED) |
35 | h, w = img.shape[:2] | 35 | h, w = img.shape[:2] |
36 | + if w < 300 or h < 300: | ||
37 | + continue | ||
36 | left, upper = random.randint(0, w - 300), random.randint(0, h - 300) | 38 | left, upper = random.randint(0, w - 300), random.randint(0, h - 300) |
37 | img_crop = img[upper:upper + 300, left:left + 300] | 39 | img_crop = img[upper:upper + 300, left:left + 300] |
38 | - cv2.imwrite(os.path.join(base_dir, category + '_crop_cv', name),img_crop) | 40 | + cv2.imwrite(os.path.join(base_dir, category + '_crop_cv', name), img_crop) |
39 | except Exception as e: | 41 | except Exception as e: |
40 | - print '[EXCPT]',e | 42 | + print '[EXCPT]', e |
41 | pass | 43 | pass |
42 | 44 | ||
43 | 45 | ||
44 | - | ||
45 | if __name__ == '__main__': | 46 | if __name__ == '__main__': |
46 | timer = Timer() | 47 | timer = Timer() |
47 | 48 |