怎麼用 imgaug套件取得轉換後的訊息
參照了Day16的作業使用了幾個fun
import imgaug as ia
import imgaug.augmenters as iaa
from imgaug.augmentables.kps import Keypoint, KeypointsOnImage
def augment(img, points):
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #Cv2讀進來是BGR,轉成RGB
img= np.array(img, dtype=np.float32)
kps = [
Keypoint(x=points[0], y=points[1]), # 'left_eye_center_x', 'left_eye_center_y'
Keypoint(x=points[2], y=points[3]), # 'right_eye_center_x', 'right_eye_center_y',
Keypoint(x=points[4], y=points[5]), # 'left_eye_inner_corner_x', 'left_eye_inner_corner_y',
Keypoint(x=points[6], y=points[7]), # 'left_eye_outer_corner_x', 'left_eye_outer_corner_y',
Keypoint(x=points[8], y=points[9]), # 'right_eye_inner_corner_x', 'right_eye_inner_corner_y',
Keypoint(x=points[10], y=points[11]), # 'right_eye_outer_corner_x', 'right_eye_outer_corner_y',
Keypoint(x=points[12], y=points[13]), # 'left_eyebrow_inner_end_x', 'left_eyebrow_inner_end_y',
Keypoint(x=points[14], y=points[15]), # 'left_eyebrow_outer_end_x', 'left_eyebrow_outer_end_y',
Keypoint(x=points[16], y=points[17]), # 'right_eyebrow_inner_end_x', 'right_eyebrow_inner_end_y',
Keypoint(x=points[18], y=points[19]), # 'right_eyebrow_outer_end_x', 'right_eyebrow_outer_end_y',
Keypoint(x=points[20], y=points[21]), # 'nose_tip_x', 'nose_tip_y',
Keypoint(x=points[22], y=points[23]), # 'mouth_left_corner_x', 'mouth_left_corner_y',
Keypoint(x=points[24], y=points[25]), # 'mouth_right_corner_x', 'mouth_right_corner_y'
Keypoint(x=points[26], y=points[27]), # 'mouth_center_top_lip_x', 'mouth_center_top_lip_y',
Keypoint(x=points[28], y=points[29]) # 'mouth_center_bottom_lip_x', 'mouth_center_bottom_lip_y'
]
kpsoi = KeypointsOnImage(kps, shape=img.shape)
sometimes = lambda aug: iaa.Sometimes(0.5, aug) # Sometimes(0.5, ...) 代表每次都有50%的機率運用不同的Augmentation
##包裝想運用之圖像強化方式
seq = iaa.Sequential([
iaa.Fliplr(0.5), # horizontally flip 50% of the images
iaa.Flipud(0.5), # vertically flip 50% of all images
#iaa.GaussianBlur(sigma=(0, 3.0)), # blur images with a sigma of 0 to 3.0
iaa.Affine(
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # scale images to 80-120% of their size, individually per axis
translate_px={"x": (-16, 16), "y": (-16, 16)}, # translate by -16 to +16 pixels (per axis)
rotate=(-45, 45), # rotate by -45 to +45 degrees
shear=(-16, 16), # shear by -16 to +16 degrees
order=ia.ALL, # use any of scikit-image's interpolation methods
#cval=(0, 1.0), # if mode is constant, use a cval between 0 and 1.0
#mode=ia.ALL # use any of scikit-image's warping modes (see 2nd image from the top for examples)
)
],
random_order=True # do all of the above in random order
)
#image_aug = seq.augment_images(img) ## Image Augmentation
image_aug, kps_aug = seq(image=img, keypoints=kpsoi) # Image Augmentation
#for i in range(len(kpsoi.keypoints)):
# kps_before = kpsoi.keypoints[i]
# kps_after = kps_aug.keypoints[i]
#print("Keypoint %d: (%.8f, %.8f) -> (%.8f, %.8f)" % (i, kps_before.x, kps_before.y, kps_after.x, kps_after.y))
return image_aug, kps_aug
這個fun可以幫助我取得轉換後的key points! 但是資訊的形式卻變成...
Keypoint(x=-10.57457924, y=-10.79163456)
Keypoint(x=-11.02216148, y=-10.82747650)
Keypoint(x=-10.65522385, y=-10.78267384)
...
這個lib中我該如何簡單取出(x,y) 的座標呢?
以及這個fun 中 ia.imshow(point_aug.draw_on_image 怎麼將圖形還原大小呢? 我怎麼畫都很小.....
回答列表
-
2020/02/10 下午 10:54Jeffrey贊同數:0不贊同數:0留言數:0