# read the h5 file | |
import h5py | |
import numpy as np | |
import argparse | |
from pathlib import Path | |
# create a parser | |
parser = argparse.ArgumentParser(description="Read h5 file and convert to mm depth") | |
parser.add_argument("--input", type=str, help="input h5 file or dir") | |
if __name__ == "__main__": | |
# parse the arguments | |
args = parser.parse_args() | |
inputs = sorted(Path(args.input).glob("*.h5")) if Path(args.input).is_dir() else [Path(args.input)] | |
for input in tqdm(inputs): | |
# read h5 file | |
f = h5py.File(input, 'r') | |
image = np.array(f['depth']) | |
image = image * 1000.0 | |
image = image.astype("uint16") | |
cv.imwrite(str(output / (input.stem + ".png")), image) | |
print("=== Done ===") |