最近一直在看工作方面的书籍,把论文的事情搁置了,之前承诺的贴代码的事一直拖。现在把代码整理发上来,只有核心部分的,都不是我写的,我是网上整理下载的,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. ajaxform 提交,返回JSON时,IE提示下载的问题解决

    在使用AJAXform提交表单时,返回的数据格式为JSON,头文件是application/json 时,在 火狐.ie9和谷歌下都能正常解析,在ie7下会提示下载. 解决方法:指定返回页的头文件为& ...

  2. 用nw.js开发markdown编辑器-已完成功能介绍

    这里文章都是从个人的github博客直接复制过来的,排版可能有点乱. 原始地址 http://benq.im/2015/10/29/hexomd-introduction   文章目录 1. 功能列表 ...

  3. 论C++STL源代码中关于堆算法的那些事

    关于堆,我们肯定熟知的就是它排序的时间复杂度在几个排序算法里面算是比較靠上的O(nlogn)常常会拿来和高速排序和归并排序讨论,并且它还有个长处是它的空间复杂度为O(1), 可是STL中没有给我们提供 ...

  4. Atitit.wrmi web rmi框架新特性

    Atitit.wrmi web rmi框架新特性 1. V1d  新特性1 1.1. 增加了精确参数1 1.2. 增加了req参数,命名参数模式..1 1.3. 增加了globale  传递隐含参数r ...

  5. Java配置文件读取和路径设置

    记录几种读取配置文件的方法,以及配置文件的放置路径. 1.使用PropertiesLoaderUtils工具类(springframework包提供) 优点:实时加载配置文件,修改后立即生效,不必重启 ...

  6. 5 月 35 日临近,Google 无法访问,可以使用 Google IP 来解决。

    每年都会有几天那啥,你懂的. 直接使用 Google 的域名访问经常会打不开,而使用 Google 的 IP 就会很顺畅. 使用 Chrome 浏览器我们经常都会在地址栏直接搜索,所以我们只要添加一个 ...

  7. TCP/IP笔记(一)网络基础知识

    计算机与网络发展 计算机自诞生伊始,经历了一系列演变与发展.大型通用机计算机.超级计算机.小型机.个人电脑.工作站.便携式电以及现如今的智能手机终端都是这一过程的产物.它们性能逐年增强,价格却逐年下降 ...

  8. LINUX内核升级-更新网卡驱动

    因项目需要,将当前内核(2.6.32-220.el6.x86_64)升级到目标内核(2.6.33-110.el6.x86_64),但是编译的目标 内核(2.6.33-110.el6.x86_64)的对 ...

  9. Sublime 中 SFTP插件的使用

    首先说明的是Sumblime Text 3,下载安装后,打开软件, 按下Ctrl+Shift+P调出命令面板, 按回车键后弹出下面的 然后 点击左上角的 文件 >SFTP/FTP > Se ...

  10. python XML实例

    案例:使用XPath的爬虫 现在我们用XPath来做一个简单的爬虫,我们尝试爬取某个贴吧里的所有帖子,并且将该这个帖子里每个楼层发布的图片下载到本地. # tieba_xpath.py #!/usr/ ...