def gen_neg():
progress = 0.0
cropped_images = []
for i in range(9000):
frame_number = str(random.randint(0, 11178))
frame = 'frame_' + '0'*(6-len(frame_number)) + frame_number + '.jpg'
img = cv2.imread("../lara_data/images/" + frame)
height, width = img.shape[:2]
x = random.randint(max_window_size[0], width - max_window_size[0])
y = random.randint(max_window_size[1], height - max_window_size[1])
up_limit = y - max_window_size[1]/2
down_limit = y + max_window_size[1]/2
left_limit = x - max_window_size[0]/2
right_limit = x + max_window_size[0]/2
cropped_img = img[up_limit: down_limit, left_limit: right_limit]
h, w = cropped_img.shape[:2]
if int(w) == int(max_window_size[0]) and int(h) == int(max_window_size[1]):
cropped_images.append(cropped_img)
progress += 1.0
update_progress(progress/float(9000))
print("Generating Negative Images")
progress = 0.0
i = 0
for cropped_image in cropped_images:
# out_image = cv2.cvtColor(cropped_image, cv2.COLOR_RGB2YCR_CB)
# out_image = cv2.split(out_image)[0]
out_image = cropped_image
image_name = "neg" + str(i) + ".ppm"
image_path = os.path.join(neg_img_path, image_name)
cv2.imwrite(image_path, out_image)
progress += 1.0
i += 1
update_progress(progress/float(len(cropped_images)))
lara_cropper.py 文件源码
python
阅读 18
收藏 0
点赞 0
评论 0
评论列表
文章目录