我在MATLAB中进行板的数字提取。有两种号牌,一种是带有pwd符号的另一种没有它。我输出8个字符。如果输出中没有pwd符号,则我的预期输出为6个字符,否则从右到左依次为7。我的示例输出是14184940和0PwDsymbol012345。我正在使用' strfind'检查输出中是否显示pwddymbol。如何截断输出字符?此代码用于识别号码。
function strPlate = Recognition(Objects,ImgChar)
% clc;
% clear all;
global templates;
load templates;
strPlate=[];
I=imread('images.jpg');
% I=imread('2222.jpg');
figure,imshow(I);
[ImgPlate] = LocationPlate(I);
[Objects,ImgChar]=Segmentation(ImgPlate);
num_letras=size(templates,2);
for i=1:Objects
char=ImgChar(:,:,i);
char=imresize(char,[100 100]);
char = medfilt2(char,[3 3]);
figure,imshow(char);title('filtered')
% use adaptive histogram equalisation
char = adapthisteq(char);
% contrast stretching
char = imadjust(char);
se=strel('disk',1); % Structural element (disk of radius 1) for morphological processing.
chari=imdilate(char,se); % Dilating the gray image with the structural element.
% figure,imshow(chari);
% title('chari')
chare=imerode(char,se); % Eroding the gray image with structural element.
gdiff=mat2gray(chare); % Converting the class to double.
gdiff=conv2(gdiff,[1 1;1 1]);
gdiff=imadjust(gdiff,[0.5 0.7],[0 1],0.1); % Intensity scaling between the range 0 to 1.
H=bwmorph(gdiff,'thin',1);
final=imresize(H,[100,100]);
letter=read_letter(final,num_letras);
strPlate=[strPlate letter ];
end
locations = strfind(strPlate, 'PwDsymbol');
fid = fopen('noPlate.txt', 'wt');
if isempty(locations)
fprintf(fid,'%s\n','number plate has no PwD symbol hence violation.\n');
else
fprintf(fid,'%s\n','number plate has PwD symbol hence no violation.\n');
end
fclose(fid);
winopen('noPlate.txt')
答案 0 :(得分:1)
您没有指定截断是否必须在字符串的开头或结尾处发生。无论如何,一旦你知道如何执行截断,这是一个边缘问题。
假设您要从字符串中删除第一个字符(确切地说,是字符数组):
s = '0PwDsymbol012345';
s = s(2:end); % Output: 'PwDsymbol012345'
假设您想要从字符数组中删除最后两个字符:
s = '14184940';
s = s(1:end-2); % Output: '141849'
这就是全部。现在,您可以根据需要自由调整字符串截断过程。无论如何,在继续进行截断之前,建议对字符串长度进行健全性检查,这样您的输出就不会被弄乱...即使截断溢出产生空字符串:
s = '12345';
s = s(1:end-10); % Output: ''