columnNames = string({'Aricept','Donepezil','Dementia','tpicerA','ROOMS','BRICK'});
stary=char(columnNames);
% Load an image
% I = imread('product_aricept_10mg.jpg');
% cd('E:\saba_study\7th sem\New folder\task3\*.jpg');
[mat, dirc] = uigetfile('*.jpg', 'Select a file');
I= imread( fullfile(dirc, mat) );
% Perform OCR
roi = [360 118 384 560];
results = ocr(I);
% disp(results);
disp(results.Text);
% Display one of the recognized words
% for i=1:results
word = results.Words{3};
disp(word);
com=char(word);
% end
%
% Location of the word in I
wordBBox = results.WordBoundingBoxes(3,:);
figure;
Iname = insertObjectAnnotation(I, 'rectangle', wordBBox, word);
img=imcrop(Iname);
imshow(img);
x=validatestring(com,columnNames);
if(x==stary)
disp(x);
else
disp('not recognized');
end
% Find characters with low confidence
lowConfidenceIdx = results.CharacterConfidences < 0.6;
% Get the bounding box locations of the low confidence characters
lowConfBBoxes = results.CharacterBoundingBoxes(lowConfidenceIdx, :);
% Get confidence values
lowConfVal = results.CharacterConfidences(lowConfidenceIdx);
% Annotate image with character confidences
str = sprintf('confidence = %f', lowConfVal);
Ilowconf = insertObjectAnnotation(I, 'rectangle', lowConfBBoxes, str);
figure;
imshow(Ilowconf);
title('you need to take this medicine 3 times a day');`
我希望当选择任何图像并应用ocr函数时,将通过字符串值使用validate属性比较返回的值,以检查它是否与值匹配,然后显示值,否则返回无匹配值。请帮助我如何处理条件
答案 0 :(得分:0)
那是因为
names={'Aricept','Donepezil','Dementia','tpicerA','ROOMS','BRICK'}
已经是一个单元格,matlab中几乎没有运算符可以将单元格作为输入。 然而
string(names{1})
是有效输入,因为名称{1}包含字符串。