从自然图像中提取文本
Text Extraction from natural images
我在执行这段代码时遇到问题。我想从图像中提取文本这是我的代码
i = imread('handicapped.jpg');
i1 = rgb2gray(i);
imshow(i1);
i2 = edge(i1,'canny',0.3);
imshow(i2);
se = strel('square',2);
i3 = imdilate(i2,se);
imshow(i3);
i4 = imfill(i3,'holes');
imshow(i4);
[Ilabel num] = bwlabel(i4);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 92]);
imshow(i);
hold on;
for cnt = 1:92
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end
我在第 19 行有错误
Error using reshape
To RESHAPE the number of elements must not change.
Error in test11 (line 19)
Ibox = reshape(Ibox,[4 92]);
谁能帮帮我???
您假设 总是 找到 92 个边界框。您收到错误消息,因为情况显然并非总是如此。 reshape
不是指定第二个维度,而是 you can pass an empty array 以便 reshape
计算出合适的维度。
%// 4 Rows with numel(Ibox)/4 columns
Ibox = reshape(Ibox, 4, []);
您的 for 循环采用与 92 相同的假设,因此您也需要更改它
for cnt = 1:size(Ibox, 2)
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end
我在执行这段代码时遇到问题。我想从图像中提取文本这是我的代码
i = imread('handicapped.jpg');
i1 = rgb2gray(i);
imshow(i1);
i2 = edge(i1,'canny',0.3);
imshow(i2);
se = strel('square',2);
i3 = imdilate(i2,se);
imshow(i3);
i4 = imfill(i3,'holes');
imshow(i4);
[Ilabel num] = bwlabel(i4);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 92]);
imshow(i);
hold on;
for cnt = 1:92
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end
我在第 19 行有错误
Error using reshape
To RESHAPE the number of elements must not change.
Error in test11 (line 19)
Ibox = reshape(Ibox,[4 92]);
谁能帮帮我???
您假设 总是 找到 92 个边界框。您收到错误消息,因为情况显然并非总是如此。 reshape
不是指定第二个维度,而是 you can pass an empty array 以便 reshape
计算出合适的维度。
%// 4 Rows with numel(Ibox)/4 columns
Ibox = reshape(Ibox, 4, []);
您的 for 循环采用与 92 相同的假设,因此您也需要更改它
for cnt = 1:size(Ibox, 2)
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end