how to fix "unrecognized table variable name" error?

조회 수: 132 (최근 30일)
Muhammad Sanwal
Muhammad Sanwal 2021년 1월 21일
댓글: Walter Roberson 2021년 1월 23일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2021년 1월 21일
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
Muhammad Sanwal
Muhammad Sanwal 2021년 1월 23일
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 2021년 1월 23일
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.

댓글을 달려면 로그인하십시오.


Jeremy Hughes
Jeremy Hughes 2021년 1월 21일
'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
Jeremy Hughes
Jeremy Hughes 2021년 1월 21일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by