add Actor7 support
This commit is contained in:
1 parent
a4c53e3265
commit
7aed8b140a
16 files changed
+403
-316
No files matched your search
@@ -8,6 +8,7 @@ import os, sys
|
||||
sys.path.insert(0, os.getcwd())
|
||||
from common.logger import Logger
|
||||
|
||||
|
||||
def bbox2point(left, right, top, bottom, type='bbox'):
|
||||
''' bbox from detector and landmarks are different
|
||||
'''
|
||||
@@ -32,6 +33,7 @@ def processing_one_folder(ipath_frame, ipath_ldmks, ipath_fcrop, ipath_tfrom, ip
|
||||
vpath_image = sorted(ipath_frame.glob(f"*.{suffix}"), key=lambda x: int(x.stem.split("-")[-1]), reverse=False)
|
||||
logger.info(f'--> total have {len(vpath_image)} images, top: \n{vpath_image[:3]}')
|
||||
|
||||
|
||||
# set prev_ldmk
|
||||
prev_ldmk = None
|
||||
|
||||
@@ -43,11 +45,10 @@ def processing_one_folder(ipath_frame, ipath_ldmks, ipath_fcrop, ipath_tfrom, ip
|
||||
for j, jpath_frame in enumerate(vpath_image):
|
||||
image_name = jpath_frame.stem # (frame-0000)
|
||||
|
||||
if j%100 == 0:
|
||||
if j%200 == 0:
|
||||
logger.info(f"load jpath_frame --> {jpath_frame}")
|
||||
|
||||
# if j < 19300: continu
|
||||
|
||||
ipath_ldmk = ipath_ldmks.joinpath(image_name + ".txt")
|
||||
if not ipath_ldmk.exists():
|
||||
raise Exception(f"ipath_ldmk not exists --> {ipath_ldmk}")
|
||||
@@ -88,11 +89,6 @@ def processing_one_folder(ipath_frame, ipath_ldmks, ipath_fcrop, ipath_tfrom, ip
|
||||
# record prev
|
||||
prev_ldmk = kpt.copy().reshape(-1) # record prev_ldmk
|
||||
|
||||
# reverse H&W
|
||||
if roation_image:
|
||||
image = image.transpose(1,0,2) # (H, W, 3)
|
||||
kpt = kpt[:, ::-1] # (68, 2)
|
||||
|
||||
if use_same_bbox:
|
||||
left, right = same_bbox[0], same_bbox[1]
|
||||
top, bottom = same_bbox[2], same_bbox[3]
|
||||
@@ -113,41 +109,50 @@ def processing_one_folder(ipath_frame, ipath_ldmks, ipath_fcrop, ipath_tfrom, ip
|
||||
[0, crop_size - 1], # (left-botton corner)
|
||||
[crop_size - 1, 0]]) # (right-top corner)
|
||||
|
||||
# logger.info(f"estimate_transform - 3")
|
||||
# tform_params dytpe = float64, shape = (3, 3)
|
||||
tform = estimate_transform('similarity', src_pts, DST_PTS)
|
||||
|
||||
# image = image/255.
|
||||
# (crop_size, crop_size, 3) ,float64
|
||||
cropped_imag = warp(image, tform.inverse, output_shape=(crop_size, crop_size)) # scale to (0~1)
|
||||
# logger.info(f"estimate_transform - 3 - 2")
|
||||
|
||||
## use skimage (crop_size, crop_size, 3) ,float64, 0~1
|
||||
# cropped_imag = warp(image, tform.inverse, output_shape=(crop_size, crop_size)) # scale to (0~1)
|
||||
# cropped_imag = (255*cropped_imag).astype(np.uint8)
|
||||
|
||||
## use cv2.warpAffine
|
||||
# (crop_size, crop_size, 3) ,uint8, 0~255
|
||||
cropped_imag = cv2.warpAffine(image, tform.params[:2,:], (crop_size, crop_size), flags=cv2.INTER_LANCZOS4) # (dtype=uint, 0~255)
|
||||
cv2.imwrite(str(kpath_fcrop), cropped_imag)
|
||||
|
||||
|
||||
# logger.info(f"estimate_transform - 3 - 3")
|
||||
cropped_ldmk = np.dot(tform.params, np.hstack([kpt, np.ones([kpt.shape[0],1])]).T).T # (68,3)
|
||||
cropped_ldmk = cropped_ldmk[:, :2]
|
||||
|
||||
# logger.info(f"image dytpe = {image.dtype}, shape = {image.shape} ")
|
||||
# logger.info(f"cropped_imag dytpe = {cropped_imag.dtype}, shape = {cropped_imag.shape} ")
|
||||
# logger.info(f"tform_params dytpe = {tform.params.dtype}, shape = {tform.params.shape} ")
|
||||
# logger.info(f"cropped_ldmk dytpe = {cropped_ldmk.dtype}, shape = {cropped_ldmk.shape}, max={cropped_ldmk.max()}, min={cropped_ldmk.min()} ")
|
||||
|
||||
|
||||
# logger.info(f"save np - 4")
|
||||
np.save(kpath_tfrom, tform.params)
|
||||
np.savetxt(kpath_lcrop, cropped_ldmk, fmt=" %3d")
|
||||
|
||||
cropped_imag = (255*cropped_imag).astype(np.uint8)
|
||||
cv2.imwrite(str(kpath_fcrop), cropped_imag)
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
actor = "Actor6"
|
||||
sub_folder = "processing2" # smile, processing, processing2
|
||||
actor = "Actor7"
|
||||
sub_folder = "processing" # smile, processing, processing2
|
||||
|
||||
# logger
|
||||
logger = Logger(f"./data/{actor}", postfix=f"crop-transform-{sub_folder}")
|
||||
|
||||
path_data = Path(f"/ssdata1/lsen/DATA/{actor}/{sub_folder}")
|
||||
path_data = Path(f"/mfs/lsen/DATA/{actor}/{sub_folder}")
|
||||
path_same_bbox = f"data/{actor}/max_bbox_{sub_folder}.npy"
|
||||
|
||||
#
|
||||
vpath_videos = sorted(path_data.glob("*"), reverse=False)
|
||||
vpath_videos = sorted(path_data.glob("*"), reverse=True)
|
||||
logger.info(f"Have {len(vpath_videos)} dir files")
|
||||
|
||||
# whole body need roation frame
|
||||
@@ -155,11 +160,11 @@ if __name__ == "__main__":
|
||||
logger.info(f"roation_image = {roation_image}")
|
||||
|
||||
# for each word
|
||||
for i, ipath_item in enumerate(vpath_videos):
|
||||
for i, ipath_item in enumerate(vpath_videos[10:]):
|
||||
iname = ipath_item.stem
|
||||
logger.info(f"processing {i}/{len(vpath_videos)} -> {ipath_item} ... ")
|
||||
|
||||
if iname not in ["4R3A0139"]: continue
|
||||
# if iname not in ["4R3A0139"]: continue
|
||||
|
||||
# if iname not in IDs: continue
|
||||
ipath_ldmks = ipath_item.joinpath("landmarks_FAN")
|
||||
@@ -174,11 +179,17 @@ if __name__ == "__main__":
|
||||
|
||||
num_frame = len(list(ipath_frame.glob("*.jpg")))
|
||||
|
||||
|
||||
# check frame have exsit
|
||||
if num_frame < 50:
|
||||
logger.info(f"\n Skip: num_frame = {num_frame} is small!")
|
||||
continue
|
||||
|
||||
# check have done
|
||||
# num_fcrop = len(list(ipath_fcrop.glob("*.jpg")))
|
||||
# if num_frame == num_fcrop:
|
||||
# logger.info(f"\n Skip: have already done!")
|
||||
# continue
|
||||
num_fcrop = len(list(ipath_fcrop.glob("*.jpg")))
|
||||
if num_frame == num_fcrop:
|
||||
logger.info(f"\n Skip: have already done!")
|
||||
continue
|
||||
|
||||
# check landmarks have exists
|
||||
num_ldmks = len(list(ipath_ldmks.glob("*.txt")))
|
||||
|
||||
Reference in new issue
Block a user