from:http://blog.sina.com.cn/s/blog_736aa0540101kzqb.html

clc; clear; close all;

% Haar-like特征矩形计算

board = 24                                              % 检测窗口宽度
num = 24                                                % 检测窗口分划数

show = 1;                                               % 1为作图
time = 0.001;                                           % 作图间隔

%%

if mod(board,num)~=0
    error('检测窗口宽度必须是分划数的整数倍')
else
    delta = board/num                                   % 滑动步进值 
end

%% Haar特征1:左白,右黑,(s,t)=(1,2)

s = 1;
t = 2;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征1:左白,右黑,(s,t)=(1,2) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                   % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r];                                     % 矩形坐标初始化
        Py0 = [0 c/2 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
               
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(Px,repmat(Py',1,2),'r','LineWidth',5)
                    plot(repmat(Px,2,1),repmat([Py(1) Py(end)]',1,2),'r','LineWidth',5); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征2:上白,下黑,(s,t)=(2,1)

s = 2;
t = 1;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征2:上白,下黑,(s,t)=(2,1) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r/2 r];                                 % 矩形坐标初始化
        Py0 = [0 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;

if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(repmat(Px,2,1),repmat(Py',1,length(Px)),'r','LineWidth',3);
                    plot(repmat([Px(1) Px(end)]',1,2),repmat(Py,2,1),'r','LineWidth',3); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征3:左右白,中间黑,(s,t)=(1,3)

s = 1;
t = 3;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征3:左右白,中间黑,(s,t)=(1,3) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r];                                     % 矩形坐标初始化
        Py0 = [0 c/3 c*2/3 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
               
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(Px,repmat(Py',1,2),'r','LineWidth',5)
                    plot(repmat(Px,2,1),repmat([Py(1) Py(end)]',1,2),'r','LineWidth',5); hold off
                    pause(time)
                end

end
        end
       
    end
end
NUM

%% Haar特征4:左右白,中间黑(2倍宽度),(s,t)=(1,4)

s = 1;
t = 4;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征4:左右白,中间黑(2倍宽度),(s,t)=(1,4) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r];                                     % 矩形坐标初始化
        Py0 = [0 c/4 c*3/4 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
       
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(Px,repmat(Py',1,2),'r','LineWidth',5)
                    plot(repmat(Px,2,1),repmat([Py(1) Py(end)]',1,2),'r','LineWidth',5); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征5:上下白,中间黑,(s,t)=(3,1)

s = 3;
t = 1;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征5:上下白,中间黑,(s,t)=(3,1) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r/3 r*2/3 r];                           % 矩形坐标初始化
        Py0 = [0 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
               
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(repmat(Px,2,1),repmat(Py',1,length(Px)),'r','LineWidth',3);
                    plot(repmat([Px(1) Px(end)]',1,2),repmat(Py,2,1),'r','LineWidth',3); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征6:上下白,中间黑(2倍宽度),(s,t)=(4,1)

s = 4;
t = 1;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征6:上下白,中间黑(2倍宽度),(s,t)=(4,1) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                 % Haar窗口宽
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 列方向移动个数
       
        Px0 = [0 r/4 r*3/4 r];                           % 矩形坐标初始化
        Py0 = [0 c];
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;

if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(repmat(Px,2,1),repmat(Py',1,length(Px)),'r','LineWidth',3);
                    plot(repmat([Px(1) Px(end)]',1,2),repmat(Py,2,1),'r','LineWidth',3); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征7:左上右下白,其它黑,(s,s)=(2,2)

s = 2;
t = 2;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征7:左上右下白,其它黑,(s,s)=(2,2) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口高
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 行方向移动个数
       
        Px0 = [0 r/2 r];                           % 矩形坐标初始化
        Py0 = [0 c/2 c];                           % 矩形坐标初始化
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
               
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(repmat(Px,3,1),repmat(Py',1,length(Px)),'r','LineWidth',3);
                    plot(repmat([Px(1) Px(end)]',1,3),repmat(Py,2,1),'r','LineWidth',3); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

%% Haar特征8:四周白,中间黑,(s,s)=(3,3)

s = 3;
t = 3;
R = s:s:floor(num/s)*s;                                 % Haar窗口高
C = t:t:floor(num/t)*t;                                 % Haar窗口宽
NUM = 0;                                                % Haar特征总数

'---- Haar特征8:四周白,中间黑,(s,s)=(3,3) ---'
for I = 1:length(R)
    for J = 1:length(C)
       
        r = R(I)*delta;                                  % Haar窗口高
        c = C(J)*delta;                                  % Haar窗口高
        nr = num-R(I)+1;                                 % 行方向移动个数
        nc = num-C(J)+1;                                 % 行方向移动个数
       
        Px0 = [0 r/3 r*2/3 r];                           % 矩形坐标初始化
        Py0 = [0 c/3 c*2/3 c];                           % 矩形坐标初始化
        for i = 1:nr
            for j = 1:nc
                Px = Px0+(i-1)*delta;                    % 滑动取点
                Py = Py0+(j-1)*delta;
                NUM = NUM+1;
               
                if show
                    plot([0 board],repmat((0:delta:board)',1,2),'k'); hold on;
                    plot(repmat((0:delta:board)',1,2),[0 board],'k'); axis tight; axis square;
                    title('Haar矩形遍历演示');xlabel('x');ylabel('y');
                   
                    plot(repmat(Px,4,1),repmat(Py',1,length(Px)),'r','LineWidth',3);
                    plot(repmat([Px(1) Px(end)]',1,4),repmat(Py,2,1),'r','LineWidth',3); hold off
                    pause(time)
                end
               
            end
        end
       
    end
end
NUM

% 毕业院校:海军工程大学,水声工程专业,博士
% 精通方向:数字信号(图像、视频)处理,人工智能与模式识别,群体智能优化,非线性与混沌,支持向量机,Matlab与VC++混编
% 现任岗位:沈阳聚德视频技术有限公司,图像处理及模式识别研发工程师
% 工作职责:车牌识别,视频目标跟踪等算法开发,C/C++实现,DSP植入
% 兴趣爱好:金融时序的程式化交易
%
% 主要成果:
% [1] 实现车牌识别C/C实现,DSP植入,识别率:汉字不低于99%,数字字母不低于99.5%,整牌不低于97%
% [2] 精通数字信号(图像、视频)“特征提取”与“模式识别”的研究与开发,开展了“支持向量机”应用研究,原创文章有《四种支持向量机工具箱使用要点》,独立开发了“支持向量机Matlab工具箱Version1.0”。结题项目有:语音信号处理与识别,遥感图像的特征提取与分类,人脸识别,主被动声纳信号处理与识别等
% [3] 精通“群体智能优化”,原创工具箱有“群体智能算法”Matlab工具箱 Version2.0”,误差精度优于现有公开发表文献,工程中解决了各种高维复杂问题的优化计算
% [4] 精通“时间序列混沌建模和预测”,基于Matlab和VC 混编平台,独立开发了混沌分析和预测软件包“混沌时间序列分析与预测工具箱 Version2.9”。结题项目有:金融数据波动性分析与程式化交易,银行反洗钱异常检测系统,混沌背景弱信号检测,海洋混响背景弱目标检测等
% [5] 精通Matlab与VC 混合编程:(a)以VC 为界面,核心算法采用Matlab函数,原创文章有《如何将Matlab7.0函数转换成VC 6.0动态链接库》;(b)以Matlab为界面,耗时算法在VC 环境中采用Mexfunction编译。
%
% 联系方式

电子邮件:luzhenbo2@qq.com

个人博客: http://blog.sina.com.cn/luzhenbo2

(转)Haar-like矩形遍历检测窗口演示Matlab源代码的更多相关文章

  1. paper 69:Haar-like矩形遍历检测窗口演示Matlab源代码[转载]

    Haar-like矩形遍历检测窗口演示Matlab源代码 clc; clear; close all; % Haar-like特征矩形计算 board = 24 % 检测窗口宽度 num = 24 % ...

  2. 基于Haar特征Adaboost人脸检测级联分类

    基于Haar特征Adaboost人脸检测级联分类 基于Haar特征Adaboost人脸检测级联分类,称haar分类器. 通过这个算法的名字,我们能够看到这个算法事实上包括了几个关键点:Haar特征.A ...

  3. WPF Window异形窗口演示

    我们先通过简单的效果展示,切换展示不同图片: 我们先定义图片资源文件,我们可以在window资源中定义,下面的在app.xaml文件来定义: <Application x:Class=" ...

  4. 链表创建和链表遍历算法的演示_C语言

    今天搞了一个多小时,头是疼的,应该是没休息好吧,学习了数据结构这一节,感觉收益良多,下面贴上代码和心得: /*24_链表创建和链表遍历算法的演示*/ # include <stdio.h> ...

  5. OpenCV 矩形轮廓检测

    转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 基础介绍 OpenCV里提取目 ...

  6. Silverlight子窗口(ChildWindow)传递参数到父窗口演示

    在企业级项目中,子窗口(ChildWindow)是一个常用控件,其展示方式是以弹出窗口来显示信息. 这里我将演示,子窗口传递参数到父窗口的方法.由于我的开发环境都是英文环境,所以部分中文可能显示不正常 ...

  7. 遍历windows窗口

    原文 1. GetDesktopWindow GetNextWindow HWND hAll = ::GetDesktopWindow(); HWND hCurrent = ::GetNextWind ...

  8. python3+openCV实现图片的人脸人眼检测,原理+参数+源代码

    上学时候用matlab学过一些图像处理的基础知识,当时课程作业是用haar实现人脸检测 but当时是心思根本不在图像处理上,so找了个同学帮忙做的,自己没上心 然鹅天道好轮回,现在捡起来了原来的算法一 ...

  9. OpenCV角点检测goodFeaturesToTrack()源代码分析

    上面一篇博客分析了HARRIS和ShiTomasi角点检测的源代码.而为了提取更准确的角点,OpenCV中提供了goodFeaturesToTrack()这个API函数,来获取更加准确的角点位置.这篇 ...

随机推荐

  1. 在阿里云服务器上安装git

    https://git-scm.com/book/zh/v1/%E8%B5%B7%E6%AD%A5-%E5%AE%89%E8%A3%85-Git 有yum的系统执行下列命令(已测试) $ yum in ...

  2. Nginx解决错误413 Request Entity Too Large

    最近一个项目当中,要求上传图片,并且限制图片大小,虽然在laravel当中已经添加了相关的表单验证来阻止文件过大的上传,然而当提交表单时,还没轮到laravel处理,nginx就先报错了.当你仔细看报 ...

  3. GWT中自定义你的"cell"

    GWT内部提供了CellTable组件,它允许自由增加column以及cell,在设定column之后就是在其中填充cell了.但GWT所提供的CellTable样式确实不敢恭维,为了解决这一问题,在 ...

  4. HDU5475(线段树)

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  5. 【转】link_to中delete无效的问题解决

    问题一 1.问题描述:点击[删除]链接之后,跳到了show页面,完全没有弹出框提示 <%= link_to "删除", product_path(product.id), : ...

  6. [更新中]【South使用总结】django开发中使用South进行数据库迁移

    Django开发中使用South进行数据库迁移的使用总结 South的详细资料可产看官方文档http://south.readthedocs.org/en/latest South安装配置 pip i ...

  7. java selenium webdriver第二讲 页面元素定位

    自动化测试实施过程中,测试程序中常用的页面操作有三个步骤 1.定位网页上的页面元素,并存储到一个变量中 2.对变量中存储的页面元素进行操作,单击,下拉或者输入文字等 3.设定页面元素的操作值,比如,选 ...

  8. linux中安装sqlmap

    wget https://codeload.github.com/sqlmapproject/sqlmap/legacy.tar.gz/master //下载sqlmap tar zxvf maste ...

  9. html乱码原因与网页乱码解决方法

    造成html网页乱码原因主要是html源代码内中文字内容与html编码不同造成.但无论是哪种情况造成乱码在网页开始时候都需要设置网页编码. charset编码设置 html网页乱码效果截图 一.乱码造 ...

  10. 如何设置Win10文件资源管理器默认打开“这台电脑”

    摘录自:http://www.ithome.com/html/win10/126066.htm