Last active
August 27, 2017 08:30
-
-
Save BeMg/2de9501f607eca2985acb1cef769f6f0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import cv2 | |
| import pickle | |
| import os | |
| from utils import draw | |
| import numpy as np | |
| curr_path = os.getcwd() | |
| Train_path = curr_path+'/WIDER_train/images' | |
| H = 64 | |
| W = 64 | |
| cnt = 0 | |
| hog = cv2.HOGDescriptor((W, H), (16, 16), (8,8), (8,8), 9) | |
| data = [] | |
| label = [] | |
| with open('./wider_face_split/wider_face_train_bbx_gt.txt', 'r') as f: | |
| curr_img = '' | |
| img = np.zeros((H, W)) | |
| for line in f: | |
| inp = line.split(' ') | |
| if len(inp)==1: | |
| img_path = inp[0] | |
| img_path = img_path[:-1] | |
| curr_img = img_path | |
| if curr_img.isdigit(): | |
| continue | |
| # print(Train_path+'/'+curr_img) | |
| img = cv2.imread(Train_path+'/'+curr_img, 2) | |
| else: | |
| inp = [int(i) for i in inp[:-1]] | |
| x1, y1, w, h, blur, expression, illumination, invalid, occlusion, pose = inp | |
| n = max(w,h) | |
| if invalid == 1 or blur > 0 or n < 50: | |
| continue | |
| img2 = img[y1:y1+n, x1:x1+n] | |
| img3 = cv2.resize(img2, (H, W)) | |
| vec = hog.compute(img3) | |
| data.append(vec.flatten()) | |
| label.append(1) | |
| cnt += 1 | |
| print("{}: {} {} {} {}".format(len(vec),x1, y1, w, h)) | |
| with open('pos_data', 'wb') as f: | |
| pickle.dump((data, label), f) | |
| print(cnt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment