Dot indexing is not supported for variables of this type.

3 次查看(过去 30 天)
I faced this problem here. Please help me. I already try with give solution .
image_files = [];
for f = isfolder(image_path)
if f.endsWith([".jpg",".jpeg",".png", ".PNG"]) //problem is here
image_files.append(f);
end
end
Problem
Dot indexing is not supported for variables of this type.
Error in undistortion>undistorb_images (line 51)
if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
  2 个评论
DGM
DGM 2021-8-17
编辑:DGM 2021-8-17
You're going to have to explain what exactly you're trying to do here, because this code doesn't make any sense.
% what is image_path? is it a scalar string or char vector?
% is it a string array or a cell array of chars?
image_path = ???;
image_files = [];
% assuming image_path specifies multiple files,
% isfolder() will output a logical vector.
% f will be scalar logical, and the loop steps through each value
% but they're never used for anything
% if you're intending to only look at paths which are directories
% then why is the inner conditional looking to see if they're image files?
for f = isfolder(image_path)
% f is a scalar logical. it has no method endsWith().
% the correct syntax endsWith(f,pattern) doesn't make sense either
% because f is a scalar logical, not a string or char.
if f.endsWith([".jpg",".jpeg",".png", ".PNG"]) //problem is here
% again, append() doesn't work like that, and it doesn't work
% on logical scalars either. even if it did, this entire loop
% would accomplish nothing but disassembling the output from
% isfolder() and then reassembling it back into a logical vector.
image_files.append(f);
end
end
Are you trying to recursively search directories and build a list of paths to image files? What about image files that are not in a directory, but are specified directly in image_path?
Md Shahidul Islam
Md Shahidul Islam 2021-8-17
Yes, I am trying to recursively search directories and build a list of paths to image files. Here is my full code:
undistorb_images([], []);
function [tvec, rvec, camera_matrix, dist] = read_wp2c(input_name)
%input_name = "output_wp2camera.json";
raw = fileread(input_name);
input_params = jsondecode(raw);
camera_matrix = input_params.camera_matrix;
dist = input_params.dist_coefs;
tvec_json = input_params.translational_vectors;
%tvec = struct2cell(tvec_json);
rvec_json = input_params.rotational_vectors;
%rvec = struct2cell(rvec_json);
tvec = [];
rvec = [];
len = length(tvec_json);
for i = 1:len
%tvec.append(array(tvec_json(image + string(i))))
%tvec.append.tvec_json(i);
tvec = struct2cell(tvec_json(i));
%[A{:}]
%tvec.append(input_params.translational_vectors.image0);
%rvec.append(array(rvec_json(image + string(i))));
rvec = struct2cell(rvec_json(i));
end
end
function undistorb_images(inputParams, result)
%if result is None:
if isempty(result)
input_name = "output_wp2camera.json";
[tvec, rvec, camera_matrix, dist] = read_wp2c(input_name);
else
tvec = result(4);
rvec = result(3);
camera_matrix = result(1);
dist = result(2);
end
if isempty(inputParams)
image_path = "D:\matlab_code\Calibration_Task\images\";
else
image_path = inputParams.opencv_storage.settings.Images_Folder;
end
image_files = [];
files = [dir(fullfile(image_path,'*.jpg')); dir(fullfile(image_path,'*.png')); dir(fullfile(image_path,'*.jpeg')); dir(fullfile(image_path,'*.PNG'))];
%files = dir(fullfile(image_path, '*.(jpg|png)'));
L = length(files);
for i=1:L
image_files=files(i).name;
%disp(file)
end
% for f = dir(image_path)
% %ext = image_path(split(lower(f)));
% %disp(f)
% %if f.endsWith([".jpg",".jpeg",".png", ".PNG"])
% % image_files.append(f);
% %end
% end
image_file_name = [];
if ~isempty(image_files)
for image_file = image_files
image_file_name.append(image_file);
image = imread(image_path + "/" + image_file);
[height, width] = size(image);
print(str(height) + " " + str(width))
[newcameramtx, roi] = getOptimalNewCameraMatrix(camera_matrix, dist, [width,height], 0, [width,height]);
% dst = cv2.undistort(image, camera_matrix, dist, None, newcameramtx)
[mapx, mapy] = cv.initUndistortRectifyMap(camera_matrix, dist, None, newcameramtx, [width,height], 5);
dst = cv.remap(image, mapx, mapy, INTER_LINEAR);
x, y, w, h = roi;
dst = dst(y:y+h, x:x+w);
[height, width] = size(dst);
print(str(height) + " " + str(width));
imwrite("undistortion/" + image_file, dst);
end
end
end

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2021-8-17
编辑:Adam Danz 2021-8-17
> I am trying to recursively search directories and build a list of paths to image files
Inputs:
% Define the main directory
image_path = 'C:\Users\name\Documents';
% list accepted extensions (with leading dot, case ignored)
acceptedExt = [".jpg",".jpeg",".png"];
Recursively search main directory (and sub directories) for files with listed extensions. fileList contains a cell array of full paths to matched files. The extension match ignores case.
d = dir(fullfile(image_path,'**\*.*'));
d([d.isdir]) = []; % remove directories from list
[~,ext] = regexp({d.name}','.*(\..*$)','match','once','tokens');
isAccepted = ismember(lower([ext{:}]), lower(acceptedExt));
d(~isAccepted) = []; % remove files that do not have accepted ext.
% list full paths to accepted files
fileList = fullfile({d.folder},{d.name})';
  2 个评论
Adam Danz
Adam Danz 2021-8-17
编辑:Adam Danz 2021-8-17
Sure, to display the number of accepted files for each extension, replace the ismember line with the line below and add the second block of code to the end.
[isAccepted,extIdx] = ismember(lower([ext{:}]), lower(acceptedExt));
% Count number of matches for each acceptedExt
unqExtIdx = unique(extIdx(isAccepted));
count = histcounts(extIdx(isAccepted), 'BinMethod','integers');
disp(compose('%s: %.0f', acceptedExt', count'))
Example output:
ans =
4×1 cell array
{'.jpg: 388'}
{'.jpeg: 0' }
{'.png: 0' }
{'.gif: 1' }

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

标签

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by