Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/clip_images.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 30 15:22:02 2018

@author: avsthiago
"""

import cv2, os, multiprocessing
from tqdm import tqdm

PATH = '/home/avsthiago/tese_thiago/thesis/thesis-deepbee/data/processed/human_test_set/size_220'
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about remove hard coded configuration?
Use https://pypi.org/project/environs/ instead.


files = []

for path, subdirs, fls in os.walk(PATH):
for name in fls:
files.append(os.path.join(path, name))

def resize_and_save(im_name):
size = 110
img = cv2.imread(im_name)

center = img.shape[0]//2

min_y = center - size
min_x = center - size
max_y = center + size
max_x = center + size
roi = img[min_y:max_y,min_x:max_x]

cv2.imwrite(im_name,roi)


pool = multiprocessing.Pool(processes=8)

with tqdm(total=len(files)) as t:
for _ in pool.imap_unordered(resize_and_save, files):
t.update(1)

pool.terminate()
Empty file added src/create_dataset.py
Empty file.
Loading