我试着用MATLAB的OCR来写一些文字,recognition.This是我代码的一部分-
r = ocr(n1,'TextLayout','Word')
if strcmp(r.Text,char('_'))==1 | strcmp(r.Text,char('/'))==1
figure,imshow(n1);title('False image to be removed');
else
n2=imadd(n2,n1);figure,imshow(n2);title('uuu1');
end这是我的ocr结果-
r =
ocrText with properties:
Text: '/
'
CharacterBoundingBoxes: [3x4 double]
CharacterConfidences: [3x1 single]
Words: {'/'}
WordBoundingBoxes: [315 133 16 9]
WordConfidences: 0.7857因此,所识别的文本是/,所以它应该进入我的code.But的if部分--它总是进入else part.How --我能修复这个吗?
发布于 2015-06-24 14:16:35
据我所见,在r.Text的末尾有一些空格,在检查之前,您必须删除这些空格。或者,检查r.Text的第一个字符。
要从字符串中删除尾随空格和前导空格,可以使用:
str = strtrim(r.Text)若要只处理第一个可以使用的字符,请执行以下操作:
r.Text(1)因此,您的线路将是以下之一:
if strcmp(strtrim(r.Text),char('_'))==1 | strcmp(strtrim(r.Text),char('/'))==1
if strcmp(r.Text(1),char('_'))==1 | strcmp(r.Text(1),char('/'))==1 https://stackoverflow.com/questions/31028136
复制相似问题