how to fix "unrecognized table variable name" error?

109 visualizaciones (últimos 30 días)
Muhammad Sanwal
Muhammad Sanwal el 21 de En. de 2021
Comentada: Walter Roberson el 23 de En. de 2021
hi. i'm running a matlab code that extracts images and forms corresponding bounding boxes, but i get the following error:
"Error using trainextract (line 7)
Unrecognized table variable name 'imds'."
the code is as follows:
clear all
close all
clc
imds = imageDatastore('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg');
%%To import data from a CSV file into MATLAB use the “readtable” function. The “readtable” function automatically detects the header and the number of lines to skip
T = readtable('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\test1.csv','ReadVariableNames',false);
getdata = T.imds;
the image under test is:
can someone please help me fix this error?
note: if someone will edit this code, he/she would have to write his own location where the image is stored.
the csv file is attached as well.

Respuestas (2)

Walter Roberson
Walter Roberson el 21 de En. de 2021
imds = imageDatastore('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg');
%%To import data from a CSV file into MATLAB use the “readtable” function. The “readtable” function automatically detects the header and the number of lines to skip
T = readtable('C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\test1.csv','ReadVariableNames',false);
[imgfound, imgidx] = ismember(T.Var1, imds.Files);
T.img = cell(height(T),1);
for K = 1 : length(imgfound)
if imgfound(K)
T.img{K} = readimage(imds, imgidx(K));
else
T.img{K} = zeros(0, 0, 3, 'uint8');
end
end
Any image listed in the csv and is present in the imds under the exact same name will have its T.img entry set to the content of the image; any file not located in the imds will have T.img set to an empty RGB image.
  2 comentarios
Muhammad Sanwal
Muhammad Sanwal el 23 de En. de 2021
it gives the following error:
Error using cell/ismember (line 34)
Input A of class double and input B of class cell must be cell arrays of character vectors, unless one is a character
vector.
Error in trainextract (line 4)
[imgfound, imgidx] = ismember(T.Var1, imds.Files);
Walter Roberson
Walter Roberson el 23 de En. de 2021
T = readtable('test1.csv', 'readvariablenames', false)
T = 1x6 table
Var1 Var2 Var3 Var4 Var5 Var6 _____________________________________________________________________________________________________________________ __________________________________________________ _____________________ __________ __________ ____________________ {'C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg'} {'"[194,78,273,122;155,27,183,35;106,32,124,45]"'} {'"[213,34,255,50]"'} {0×0 char} {0×0 char} {'"[43,25,109,55]"'}
T.Var1
ans = 1x1 cell array
{'C:\Users\Muhammad Sanwal\Desktop\COMSATS\The 9th Semester (FA20)\FYP pt 1\MIO-TCD-Localization\train\00000000.jpg'}
It does not come out as double as your error message indicates.

Iniciar sesión para comentar.


Jeremy Hughes
Jeremy Hughes el 21 de En. de 2021
'ReadVariableNames',false
This tells readtable not to read variable names from the file. So all the variable names will be "Var1","Var2",..., etc.
T.imds is trying to acces the variable named "imds" which doesn't exist.
  3 comentarios
Jeremy Hughes
Jeremy Hughes el 21 de En. de 2021
Yes, because "imds" is not a variable name in the table T.
It's hard to say what you need to do next, because it's not clear what data you're trying to get out of that table.
If you want to read the data in the image, you should be calling,
read(imds)

Iniciar sesión para comentar.

Categorías

Más información sobre Image Data Workflows en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by