最近一直在看工作方面的书籍,把论文的事情搁置了,之前承诺的贴代码的事一直拖。现在把代码整理发上来,只有核心部分的,都不是我写的,我是网上整理下载的,matlab代码的效果比较差。

全部文件网盘下载地址:http://pan.baidu.com/s/1qWwNMfM;

1.C++代码

下载地址:

需要先安装opencv和boost库。

boost库下载地址:http://www.boost.org/users/download/

boost的安装:http://www.cnblogs.com/pangxiaodong/archive/2011/05/05/2037006.html

装这个boost库,我只是把文件复制到vs安装目录的include文件夹下。

GitHub repository:https://github.com/aperrau/DetectText

2.matlab代码
function [ swtMap ] = swt( im, searchDirection )
%swt Preforms stoke width transform on input image
% A novel image operator that seeks to find the value of stroke width
% for each image pixel. It's use is meant for the task of text
% detection in natural images.
%
% im = RGB input image of size m x n x
% searchDirection = gradient direction is either to detect dark text on light
% background or - to detect light text on dark background.
%
% swtMap = resulting mapping of stroke withs for image pixels % Convert image to gray scale
im = im2double(rgb2gray(im));
%figure, imshow(im), title('Black and White Image'); % Find edges using canny edge dector
edgeMap = edge(im, 'canny');
%figure, imshow(edgeMap), title('Edges Using Canny'); % Get all edge pixel postitions
[edgePointRows, edgePointCols] = find(edgeMap); % Find gradient horizontal and vertical gradient
sobelMask = fspecial('sobel');
dx = imfilter(im,sobelMask);
dy = imfilter(im,sobelMask');
%figure, imshow(dx, []), title('Horizontal Gradient Image');
%figure, imshow(dy, []), title('Vertical Gradient Image'); % Initializing matrix of gradient direction
theta = zeros(size(edgeMap,),size(edgeMap,)); % Calculating theta, gradient direction, for each pixel on the image.
% ***This can be optimized by using edgePointCols and edgePointRows
% instead.***
for i=:size(edgeMap,)
for j=:size(edgeMap,)
if edgeMap(i,j) ==
theta(i,j) = atan2(dy(i,j),dx(i,j));
end
end
end % Getting size of the image
[m,n] = size(edgeMap); % Initializing Stoke Width array with infinity
swtMap = zeros(m,n);
for i=:m
for j=:n
swtMap(i,j) = inf;
end
end % Set the maximum stroke width, this number is variable for now but must be
% made to be more dynamic in the future
maxStrokeWidth = ; % Initialize container for all stoke points found
strokePointsX = zeros(size(edgePointCols));
strokePointsY = zeros(size(strokePointsX));
sizeOfStrokePoints = ; % Iterate through all edge points and compute stoke widths
for i=:size(edgePointRows)
step = ;
initialX = edgePointRows(i);
initialY = edgePointCols(i);
isStroke = ;
initialTheta = theta(initialX,initialY);
sizeOfRay = ;
pointOfRayX = zeros(maxStrokeWidth,);
pointOfRayY = zeros(maxStrokeWidth,); % Record first point of the ray
pointOfRayX(sizeOfRay+) = initialX;
pointOfRayY(sizeOfRay+) = initialY; % Increase the size of the ray
sizeOfRay = sizeOfRay + ; % Follow the ray
while step < maxStrokeWidth
nextX = round(initialX + cos(initialTheta) * searchDirection * step);
nextY = round(initialY + sin(initialTheta) * searchDirection * step); step = step + ; % Break loop if out of bounds. For some reason this is really
% slow.
if nextX < | nextY < | nextX > m | nextY > n
break
end % Record next point of the ray
pointOfRayX(sizeOfRay+) = nextX;
pointOfRayY(sizeOfRay+) = nextY; % Increase size of the ray
sizeOfRay = sizeOfRay + ; % Another edge pixel has been found
if edgeMap(nextX,nextY) oppositeTheta = theta(nextX,nextY); % Gradient direction roughtly opposite
if abs(abs(initialTheta - oppositeTheta) - pi) < pi/
isStroke = ;
strokePointsX(sizeOfStrokePoints+) = initialX;
strokePointsY(sizeOfStrokePoints+) = initialY;
sizeOfStrokePoints = sizeOfStrokePoints + ;
end break
end
end % Edge pixel is part of stroke
if isStroke % Calculate stoke width
strokeWidth = sqrt((nextX - initialX)^ + (nextY - initialY)^); % Iterate all ray points and populate with the minimum stroke width
for j=:sizeOfRay
swtMap(pointOfRayX(j),pointOfRayY(j)) = min(swtMap(pointOfRayX(j),pointOfRayY(j)),strokeWidth);
end
end
end %figure, imshow(swtMap, []), title('Stroke Width Transform: First Pass'); % Iterate through all stoke points for a refinement pass. Refer to figure
% 4b in the paper. for i=:sizeOfStrokePoints
step = ;
initialX = strokePointsX(i);
initialY = strokePointsY(i);
initialTheta = theta(initialX,initialY);
sizeOfRay = ;
pointOfRayX = zeros(maxStrokeWidth,);
pointOfRayY = zeros(maxStrokeWidth,);
swtValues = zeros(maxStrokeWidth,);
sizeOfSWTValues = ; % Record first point of the ray
pointOfRayX(sizeOfRay+) = initialX;
pointOfRayY(sizeOfRay+) = initialY; % Increase the size of the ray
sizeOfRay = sizeOfRay + ; % Record the swt value of first stoke point
swtValues(sizeOfSWTValues+) = swtMap(initialX,initialY);
sizeOfSWTValues = sizeOfSWTValues + ; % Follow the ray
while step < maxStrokeWidth
nextX = round(initialX + cos(initialTheta) * searchDirection * step);
nextY = round(initialY + sin(initialTheta) * searchDirection * step); step = step + ; % Record next point of the ray
pointOfRayX(sizeOfRay+) = nextX;
pointOfRayY(sizeOfRay+) = nextY; % Increase size of the ray
sizeOfRay = sizeOfRay + ; % Record the swt value of next stoke point
swtValues(sizeOfSWTValues+) = swtMap(nextX,nextY);
sizeOfSWTValues = sizeOfSWTValues + ; % Another edge pixel has been found
if edgeMap(nextX,nextY)
break
end
end % Calculate stoke width as the median value of all swtValues seen.
strokeWidth = median(swtValues(:sizeOfSWTValues)); % Iterate all ray points and populate with the minimum stroke width
for j=:sizeOfRay
swtMap(pointOfRayX(j),pointOfRayY(j)) = min(swtMap(pointOfRayX(j),pointOfRayY(j)),strokeWidth);
end end %figure, imshow(swtMap, []), title('Stroke Width Transform: Second Pass'); end

笔画宽度变化(C++和matlab算法)的更多相关文章

  1. 应用笔画宽度变换(SWT)来检测自然场景中的文本

    Introduction: 应用背景:是盲人辅助系统,城市环境中的机器导航等计算机视觉系统应用的重要一步.获取文本能够为许多视觉任务提供上下文的线索,并且,图像检索算法的性能很大部分都依赖于对应的文本 ...

  2. 遗传学详解及Matlab算法实现

    遗传学算法概述 从之前转载的博客<非常好的理解遗传算法的例子>中可以知道,遗传学算法主要有6个步骤: 1. 个体编码 2. 初始群体 3. 适应度计算 4. 选择运算 5. 交叉运算 6. ...

  3. 通过sessionStorage来根据屏幕宽度变化来加载不同的html页面

    因为项目需要,分别写了移动端和PC端的两个html页面,现在需要根据不同的屏幕宽度来加载对应的页面. 先说一下本人的思路-- 刚开始我直接在加载页面的时候判断屏幕宽度,然后加载相应的页面,大家是不是也 ...

  4. 边缘检测matlab算法汇总

    边缘检测matlab算法汇总 1.      基于一阶微分算子检测边缘图像 一阶微分边缘算子又称梯度边缘算子,它是利用图像在边缘处的阶跃性,及图像梯度在边缘去得极大值得特征性进行边缘检测. Sobel ...

  5. matlab算法转为c语言注意事项

    matlab算法转为c语言后,影响c语言效率的关键在于multiword的产生,基于此会有multiword加减法和乘除法,极大消耗资源,减少甚至消除multiword很重要,需注意的是:算法中尽量减 ...

  6. vue 如何重绘父组件,当子组件的宽度变化时候

    vue 如何重绘父组件,当子组件的宽度变化时候 vue & dynamic el-popover position demo https://codepen.io/xgqfrms/pen/wv ...

  7. matlab算法

    流水线型车间作业调度问题遗传算法Matlab源码流水线型车间作业调度问题可以描述如下:n个任务在流水线上进行m个阶段的加工,每一阶段至少有一台机器且至少有一个阶段存在多台机器,并且同一阶段上各机器的处 ...

  8. 数字图像处理:基于MATLAB的车牌识别项目 标签: 图像处理matlab算法 2017-06-24 09:17 98人阅读 评论(0)

    学过了数字图像处理,就进行一个综合性强的小项目来巩固一下知识吧.前阵子编写调试了一套基于MATLAB的车牌识别的项目的代码.今天又重新改进了一下代码,识别的效果好一点了,也精简了一些代码.这里没有使用 ...

  9. 将caffe训练时loss的变化曲线用matlab绘制出来

    1. 首先是提取 训练日志文件; 2. 然后是matlab代码: clear all; close all; clc; log_file = '/home/wangxiao/Downloads/43_ ...

随机推荐

  1. Hive 作业优化

    1.Join原则将条目少的表/子查询放在 Join的左边. 原因是在 Join 操作的 Reduce 阶段,位于 Join左边的表的内容会被加载进内存,将条目少的表放在左边,可以有效减少发生内存溢出的 ...

  2. Atitit.收银系统模块架构attilax 总结

    Atitit.收银系统模块架构attilax 总结 1. 常规收银系统模块结构1 1.1. 商品管理1 1.2. 会员系统1 1.3. 报表系统1 1.4. 会员卡系统1 1.5. 库存管理1 2.  ...

  3. Android 4.4 全套源代码及子模块源代码的下载方法

    博文<Android源代码下载--用git clone实现单个文件夹下载>介绍了採用git clone方法下载Android单个文件夹源代码的方法,这篇文章已经有四年的历史,这期间Goog ...

  4. WCF信道工厂Channel Factory

    ChannelFactory<TChannel> 类 一个创建不同类型通道的工厂,客户端使用这些通道将消息发送到不同配置的服务终结点. 命名空间: System.ServiceModel ...

  5. Navicat for MySQL 之数据库迁移

    1.将数据库下的表迁移出来 2.将表全部迁入另一个数据库 重新连接数据库看看吧!

  6. mongodb更新器

    Name Description $inc Increments the value of the field by the specified amount. $mul Multiplies the ...

  7. hdu5800 To My Girlfriend dp 需要比较扎实的dp基础。

    To My Girlfriend Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. 大数据(5) - HDFS中的常用API操作

    一.安装java 二.IntelliJ IDEA(2018)安装和破解与初期配置 参考链接 1.进入官网下载IntelliJ IDEA https://www.jetbrains.com/idea/d ...

  9. 视频输出hdtv和sdtv

    SDTV和HDTV人们分别把它们叫标准清晰度数字电视和高清晰度数字电视,SDTV电视节目很早在欧洲就开始广播,如,DVB-S(卫星数字视频广播).DVB-C(有线数字视频广播).DVB-T(地面数字视 ...

  10. iOS JSON字符串转化为字典-字典转Json字符串-

    1. JSON字符串转化为字典 + (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString = ...