This question is about how to automatically call a command line tool to loop through every .obj
file (which is a 3D file format) in a directory and process them into .pcd
files (which is another 3D file format).
I am stuck at how to automate substitute file extensions from obj
to pcd
and in particular how to do that in a for
loop.
Here is what the data directory looks like:
(folding) yuqiong@yuqiong-G7-7588:/media/yuqiong/DATA/problems$ tree
.
├── input
│ ├── UUID_2832c3d3-9605-41da-916b-779582a26a9c.obj
│ ├── UUID_6979a19e-24a0-42fe-91d6-594f257a7fa6.obj
│ ├── UUID_81b8510f-cab2-4e51-b730-6824f39877da.obj
│ ├── UUID_87007a99-879e-48e2-aaae-20c7000c2e11.obj
│ ├── UUID_8be34bf6-4b01-4a63-8550-3273f5ae412d.obj
│ ├── UUID_92043aaf-4f2c-46d3-9af2-c2150457f089.obj
│ ├── UUID_aa16a01d-b388-4acf-92bb-706127b059b0.obj
│ ├── UUID_aec77ad3-f558-4030-a9d4-392ad99fb771.obj
│ ├── UUID_b55151a7-01d8-4dbc-b011-bb6df74d5e6c.obj
│ ├── UUID_d022be8c-67a0-4d5d-92df-8bfbe8b27f7c.obj
│ ├── UUID_d94ce864-7437-460a-8a1a-c5bbd7b2eb5e.obj
│ └── UUID_f6ea8a38-9b24-4d3c-ba4d-099a1a76966c.obj
├── out
│ └── UUID_f6ea8a38-9b24-4d3c-ba4d-099a1a76966c.pcd
├── run.sh
└── Untitled.ipynb
To process an individual .obj
file, I run this command:
pcl_mesh_sampling ./input/UUID_f6ea8a38-9b24-4d3c-ba4d-099a1a76966c.obj ./out/UUID_f6ea8a38-9b24-4d3c-ba4d-099a1a76966c.pcd -n_samples 2048
Here you might notice that the first argument to pcl_mesh_sampling
is just a file in the input
folder, while the second argument is the name of the output file in the out
folder. They have the same name but different extension.
I would like to automate this process, but am unable to come up with a shell script. Currently I have this:
#!/usr/bin/env bash
shopt -s nullglob
for i in ./input/*.obj; do
echo $(echo $i | awk -F. '{OFS="."} {$2="pcd"; print $0}')
pcl_mesh_sampling $i ./out/$fname -n_samples 2048
echo $i
done
But this is not working as expected and I suspect I used awk
wrong...
More, every time the pcl_mesh_sampling
finishes one task, it will show the resulting file. The process won't return until I close the visualization Window. Is there a command line utility that suppresses it from doing so?
Any suggestions will be helpful! Thanks.