clc;
clear;
close all;
warning off;
addpath(genpath(pwd));
P = imread('st10.jpg');
%B=imresize(colorImage,[,300]);
I = rgb2gray(P);
% Detecting MSER features using detectMSERfeartures function.
[mserRegions, mserConnComp] = detectMSERFeatures(I, ...
'RegionAreaRange',[200 8000],'ThresholdDelta',4);
figure
imshow(I)
hold on
plot(mserRegions, 'showPixelList', true,'showEllipses',false)
title('MSER regions')
hold off
% Measuring the MSER properties
mserStats = regionprops(mserConnComp, 'BoundingBox', 'Eccentricity', ...
'Solidity', 'Extent', 'Euler', 'Image');
% Calculating the aspect ratio using bounding box.
bbox = vertcat(mserStats.BoundingBox);
w = bbox(:,3);
h = bbox(:,4);
aspectRatio = w./h;
% DeterminIng which regions to remove.
filterregions = aspectRatio' > 3;
filterregions = filterregions | [mserStats.Eccentricity] > .995 ;
filterregions = filterregions | [mserStats.Solidity] < .3;
filterregions = filterregions | [mserStats.Extent] < 0.2 | [mserStats.Extent] > 0.9;
filterregions = filterregions | [mserStats.EulerNumber] < -4;
% Remove regions
mserStats(filterregions) = [];
mserRegions(filterregions) = [];
figure
imshow(I)
hold on
plot(mserRegions, 'showPixelList', true,'showEllipses',false)
title('After Removing Non-Text Regions Based On Geometric Properties')
hold off
% zero padding and binarization
regionImage = mserStats(6).Image;
regionImage = padarray(regionImage, [1 1]);
% Compute the stroke width image.
imagedistance = bwdist(~regionImage);
skeletonImage = bwmorph(regionImage, 'thin', inf);
strokeWidthImage = imagedistance;
strokeWidthImage(~skeletonImage) = 0;
% Show the region image alongside the stroke width image.
figure
subplot(1,2,1)
imagesc(regionImage)
title('Region Image')
subplot(1,2,2)
imagesc(strokeWidthImage)
title('Stroke Width Image')
% stroke width variation metric
strokeWidthValues = imagedistance(skeletonImage);
strokeWidthMetric = std(strokeWidthValues)/mean(strokeWidthValues);
% stroke width variation metric
strokeWidthThreshold = 0.4;
strokeWidthFilterIdx = strokeWidthMetric > strokeWidthThreshold;
% Processing the remaining regions
for j = 1:numel(mserStats)
regionImage = mserStats(j).Image;
regionImage = padarray(regionImage, [1 1], 0);
imagedistance = bwdist(~regionImage);
skeletonImage = bwmorph(regionImage, 'thin', inf);
strokeWidthValues = imagedistance(skeletonImage);
strokeWidthMetric = std(strokeWidthValues)/mean(strokeWidthValues);
strokeWidthFilterIdx(j) = strokeWidthMetric > strokeWidthThreshold;
end
% Remove regions based on the stroke width variation
mserRegions(strokeWidthFilterIdx) = [];
mserStats(strokeWidthFilterIdx) = [];
% Show remaining regions
figure
imshow(I)
hold on
plot(mserRegions, 'showPixelList', true,'showEllipses',false)
title('After Removing Non-Text Regions Based On Stroke Width Variation')
hold off
% Get bounding boxes for all the regions
bboxes = vertcat(mserStats.BoundingBox);
xmin = bboxes(:,1);
ymin = bboxes(:,2);
xmax = xmin + bboxes(:,3) - 1;
ymax = ymin + bboxes(:,4) - 1;
% Expanding the bounding boxes
%expansionamount=0.004;
expansionAmount = 0.017;
xmin = (1-expansionAmount) * xmin;
ymin = (1-expansionAmount) * ymin;
xmax = (1+expansionAmount) * xmax;
ymax = (1+expansionAmount) * ymax;
xmin = max(xmin, 1);
ymin = max(ymin, 1);
xmax = min(xmax, size(I,2));
ymax = min(ymax, size(I,1));
% Showing the expanded bounding boxes
expandedBBoxes = [xmin ymin xmax-xmin+1 ymax-ymin+1];
IExpandedBBoxes = insertShape(P,'Rectangle',expandedBBoxes,'LineWidth',3);
figure
imshow(IExpandedBBoxes)
title('Expanded Bounding Boxes Text')
% Compute the overlap ratio
overlapRatio = bboxOverlapRatio(expandedBBoxes, expandedBBoxes);
% simplify the graph representation.
n = size(overlapRatio,1);
overlapRatio(1:n+1:n^2) = 0;
g = graph(overlapRatio);
% Finding the connected text regions
componentIndices = conncomp(g);
% Merging the boxes
xmin = accumarray(componentIndices', xmin, [], @min);
ymin = accumarray(componentIndices', ymin, [], @min);
xmax = accumarray(componentIndices', xmax, [], @max);
ymax = accumarray(componentIndices', ymax, [], @max);
text = [xmin ymin xmax-xmin+1 ymax-ymin+1];
numRegionsInGroup = histcounts(componentIndices);
text(numRegionsInGroup == 1, :) = [];
% Show the final text detection result.
ITextRegion = insertShape(P, 'Rectangle', text,'LineWidth',3);
figure
imshow(ITextRegion)
title('Detected Text')
ocrtxt = ocr(I, text);
[ocrtxt.Text]
fpga和matlab
- 粉丝: 18w+
- 资源: 2639
最新资源
- 基于神经网络的天牛害虫识别技术开发与设计论文
- 五子棋程序,个人学习整理,仅供参考
- 网络五子棋程序源代码,个人学习整理,仅供参考
- springboot+vue前后端分离项目社区物业管理系统设计与实现源码+数据库
- 基于模型参考自适应的单相脉冲整流器无网压传感器控制方法的复现 使用了传统的Pwm整流器控制方法,只复现了lunwen中的电压估计,角频率估计使用基于sogi的锁相环 估计方案和lunwen基本一致
- 五子棋源程序vc,个人学习整理,仅供参考
- 五子棋源代码代码,个人学习整理,仅供参考
- 视频编码领域的VVC分数插值近似滤波器硬件实现及其低功耗特性研究
- 一个实用的五子棋程序,个人学习整理,仅供参考
- 由于找不到iUtils.dll,无法继续执行代码。重新安装程序可能会解决此问题。
- 汽车二自由度模型和汽车三自由度模型, 本案例采用三种不同方法进行搭建搭汽车线性二自由度simulink模型, 内容包含: 具体的车辆参数数值,详细的设计说明文档,附带关于汽车simulink仿真实例及
- 学生管理系统(SSH+Mysql)
- linux基础知识框架
- 学生信息管理啊系统,个人学习整理,仅供参考
- 基于python实现的爱心代码(python代码)
- 机械设计纽扣装袋输送机creo5.0非常好的设计图纸100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈