Batch conversion from mat file to pcd file
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello. I have around 1800 mat file in the discontinous order like 1,2,4,7,8, etc. I already found a code to load all the mat file but I can not do the batch conversion from mat to pcd file. Can anyone help me with this? Thanks in advance!
採用された回答
Walter Roberson
2022 年 7 月 18 日
inputdir = 'Appropriate mat folder name goes here';
outputdir = 'Appropriate pcd folder name goes here';
if ~exist(inputdir, 'dir'); error('Input directory %s does not exist', inputdir); end
if ~exist(outputdir, 'dir'); mkdir(outputdir); end
dinfo = dir( fullfile(inputdir, '*.mat') );
filenames = fullfile({dinfo.folder}, {dinfo.name});
for K = 1 : length(filenames)
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
outname = fullfile(outputdir, [basename '.pcd']);
Convert_mat_to_pcd(thisfile, outname);
end
Given appropriate code Convert_mat_to_pcd that uses the first parameter as the name of the input .mat file and uses the second parameter as the (fully qualified) output file name.
7 件のコメント
Vu Minh
2022 年 7 月 19 日
Thank you for your suggestion. However, when I replace the inputdir and outputdir with my two appropriate directory, the code ran into an error stating that Unrecognized function or variable 'Convert_mat_to_pcd'. This means I have to define the function Convert_mat_to_pcd before running the code right. Sorry for this because Im a very beginner.
Walter Roberson
2022 年 7 月 19 日
I have no idea how to convert your mat files to pcd files. I do not the variables you have stored, or which portion of them need to be extracted, or which computations need to be done to create something that could potentially be written to a pcd file. I have no idea what the pcd file format is, and I do not know if any routines are available to write to pcd files.
The difficulty you outlined was in how to loop through the input files. The implication was that given any one mat file that you already know how to convert it to pcd. If so then write that logic into your own function Convert_mat_to_pcd
Walter Roberson
2022 年 7 月 19 日
https://www.mathworks.com/help/vision/ref/pcwrite.html can write pcd files
Vu Minh
2022 年 7 月 19 日
Yes I can convert 1 by 1 mat file to pcd as the code below:
A = importdata('save_220523_103750_pointcloud.mat');
xyzPoints = A.Location;
ptCloud = pointCloud(xyzPoints);
pcwrite(ptCloud,'save_220523_103750_pointcloud.pcd');
Walter Roberson
2022 年 7 月 19 日
編集済み: Walter Roberson
2022 年 7 月 19 日
function Convert_mat_to_pcd(matname, pcdname)
A = load(matname, 'Location');
xyzPoints = A.Location;
ptCloud = pointCloud(xyzPoints);
pcwrite(ptCloud, pcdname );
end
Vu Minh
2022 年 7 月 19 日
Thank you sir for your valueable advice. I got this now. Anyway the function for loading mat file should be "importdata" instead of "load".
Walter Roberson
2022 年 7 月 19 日
No, the function for loading mat files should be load(). importdata() has a lot of overhead and can return unexpected results.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Read, Write, and Modify Image についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
