检测键盘按键的网格的交叉点
对应示例程序:
measure_grid.hdev
目标:检测键盘按键的网格的交叉点
思路为:
1.读取图像
2.利用均值滤波 阈值分割 形态学处理 常用的Blob分析方法等,提取出网格区域
3.计算网格区域的骨架,并筛选出目标轮廓
4.根据轮廓拟合出所有的网格线,并根据角度将他们分成水平和垂直两个数组。再计算每条水平线和垂直线的交点,作为最终的结果。在例程中,还根据先验知识,对交点做了判断,如果交点到直线的距离小于某个值,才是正确的交点。目的是去掉拟合不正确导致的错误交点。
5.最后例程中提供了另一种思路,即根据提取出的骨架,直接取骨架线间的交点,作为最终的检测结果。
图像:
代码:
dev_update_off ()
*
* step: acquire image
*
read_image (Image, 'keypad')
get_image_pointer1 (Image, Pointer, Type, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'white', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Image)
*
* step: initialize visualization
*
dev_set_colored (3)
dev_set_draw ('fill')
*
* step:extract the region of the grid
*提取网格区域 阈值分割 形态学处理 常用的Blob分析方法mean_image (Image, ImageMean, 7, 7) //均值滤波
dyn_threshold (Image, ImageMean, RegionDynThresh, 4, 'dark') //局部阈值分割connection (RegionDynThresh, ConnectedRegions) //连通域分割
//筛选
select_shape (ConnectedRegions, SelectedRegions, ['max_diameter','contlength'], 'and', [200,800], [99999,99999])
closing_circle (SelectedRegions, RegionClosing, 1.5) //闭操作
dev_display (Image)
dev_display (RegionClosing)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* step:extract the contours of the grid
* 提取出网格轮廓
skeleton (RegionClosing, Skeleton) //取区域的骨架
gen_contours_skeleton_xld (Skeleton, ContoursSkeleton, 1, 'filter') //将骨架转换为XLD轮廓
segment_contours_xld (ContoursSkeleton, ContoursSplitSkeleton, 'lines', 5, 2, 1) //将XLD轮廓分成线段
select_contours_xld (ContoursSplitSkeleton, SelectedContours, 'contour_length', 30, 1000, -0.5, 0.5) //筛选
union_collinear_contours_xld (SelectedContours, UnionCollinearContours, 100, 10, 20, rad(10), 'attr_keep') //合并相近的XLD轮廓
dev_display (Image)
dev_display (UnionCollinearContours)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* step:fit lines to the contours
* 拟合网格线
count_obj (UnionCollinearContours, NumberContours)
gen_empty_obj (LinesHorizontal) //水平线的数组
gen_empty_obj (LinesVertical) //垂直线的数组
for i := 1 to NumberContours by 1select_obj (UnionCollinearContours, ObjectSelected, i) //对每条线进行处理//拟合直线fit_line_contour_xld (ObjectSelected, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin, RowEnd, ColEnd, Nr, Nc, Dist)//画线段gen_contour_polygon_xld (Contour, [RowBegin,RowEnd], [ColBegin,ColEnd])Phi := atan2(-Nr,Nc)if (abs(Phi) < rad(5)) //如果角度小于5度 就划分到垂直数组concat_obj (LinesVertical, Contour, LinesVertical)endifif (rad(85) < abs(Phi) and abs(Phi) < rad(95)) //如果角度大于85度,小于95个 就划分到水平数组concat_obj (LinesHorizontal, Contour, LinesHorizontal)endif
endfor*结果显示
dev_display (Image)
dev_set_color ('red')
dev_display (LinesVertical)
dev_set_color ('yellow')
dev_display (LinesHorizontal)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* step:extract junction points of the grid
* 取网格线之间的交点 要计算水平线和垂直线的全部交点 用双层循环
RowJunction := []
ColJunction := []
RowRealJunction := []
ColRealJunction := []
count_obj (LinesHorizontal, NumberLH) //统计水平线的数量
count_obj (LinesVertical, NumberLV) //统计垂直线的数量
for i := 1 to NumberLH by 1select_obj (LinesHorizontal, HorizontalLine, i)get_contour_xld (HorizontalLine, RowHorizontal, ColHorizontal) //取水平线的坐标for j := 1 to NumberLV by 1select_obj (LinesVertical, VerticalLine, j)get_contour_xld (VerticalLine, RowVertical, ColVertical) //取垂直线的坐标//计算水平线和垂直线的交点intersection_lines (RowHorizontal[0], ColHorizontal[0], RowHorizontal[1], ColHorizontal[1], RowVertical[0], ColVertical[0], RowVertical[1], ColVertical[1], Row, Column, IsOverlapping)//计算交点到直线的距离distance_ps (Row, Column, RowHorizontal[0], ColHorizontal[0], RowHorizontal[1], ColHorizontal[1], DistanceH, DistanceHMax)distance_ps (Row, Column, RowVertical[0], ColVertical[0], RowVertical[1], ColVertical[1], DistanceV, DistanceVMax)RowJunction := [RowJunction,Row] //把交点放进一个统一的数组中,用于后面的显示ColJunction := [ColJunction,Column]if ((DistanceH <= 30) and (DistanceV <= 30)) //只有距离小于30的点才是合理的 ,用于去掉错误结果RowRealJunction := [RowRealJunction,Row]ColRealJunction := [ColRealJunction,Column]endifendfor
endfor
dev_set_color ('white')
gen_cross_contour_xld (Cross, RowJunction, ColJunction, 12, 0.785398) //画十字交点
dev_display (Cross)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
dev_display (Image)
dev_set_color ('gray')
dev_display (LinesHorizontal)
dev_display (LinesVertical)
dev_set_color ('white')
gen_cross_contour_xld (Cross, RowRealJunction, ColRealJunction, 12, 0.785398)
dev_display (Cross)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*
* or via region processing, starting with the
* skeleton obtained above
* 或者通过区域处理,从上面获得的骨架开始
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Image)
junctions_skeleton (Skeleton, EndPoints, JuncPoints) //在骨架中查找连接点和端点
//骨架间的连接点就是所求的交叉点
get_region_points (JuncPoints, RowJunctionRegionProcessing, ColumnJunctionRegionProcessing)
//画十字交点
gen_cross_contour_xld (CrossCenter, RowJunctionRegionProcessing, ColumnJunctionRegionProcessing, 12, 0.785398)
dev_set_color ('gray')
dev_display (Skeleton)
dev_set_color ('white')
dev_display (CrossCenter)
disp_message (WindowHandle, 'Result of corresponding', 'window', 40, 10, 'white', 'false')
disp_message (WindowHandle, 'region processing', 'window', 90, 10, 'white', 'false')
用到的几个算子:
skeleton --取区域的骨架
union_collinear_contours_xld --合并相近的XLD轮廓
junctions_skeleton --在骨架中查找连接点和端点
检测键盘按键的网格的交叉点相关推荐
- 设置按键退出python pygame动画(animation)程序,python检测键盘按键
功能:设置按键退出python pygame动画(animation)程序,python3.6检测键盘按键 pygame运行起来,不弄个强行终止都刹不住....为此研究了一下怎么退出. 实现的效果是: ...
- [c语言]在程序中检测键盘按键
如何在程序中检测键盘 首先 我们直接上代码 #include <conio.h> #include <stdio.h> int main() { while (1) { swi ...
- html 按键检测,js如何检测键盘按键的ascii码?
本博客不欢迎:各种镜像采集行为,请尊重知识产权法律法规.大家都是程序员,不要闹得不开心. 每个键盘上的按键都对应一个ascii码,包括鼠标左键,右键,中键都是有ascii码的.具体的码值是什么,实践出 ...
- python检测键盘按键命令_python实时检测键盘输入函数的示例
在嵌入式.尤其是机器人的python编程中,经常需要实时检测用户的键盘输入来随时控制机器人,这段代码可以帮助我们提取用户输入的字符,并在按下键盘的时候作出反应. import sys import t ...
- php如何检测键盘按键,js键盘事件,判断按下的是哪个键
在写页面的时候,尤其是桌面端的时候,我们有时候要知道用户按下了那个按键,对于这个问题我们可以使用js提供的keyCode属性来操作,如: document.onkeydown = function ( ...
- python 检测键盘按键,随时停止程序
不是我原创的,但是原文我已经找不到在哪了.侵删. 很好用的函数.Linux ubuntu下可用.可能不适用于win10环境和多进程(非终端环境)环境.多进程的按键停止方法见:https://blog. ...
- Javascript 检测键盘按键
Javascript中 有3个事件句柄在对应键盘的输入状态:keydown.keypress和keyup. 分别对应的意思是:按键被按下(按下按键但还没有抬起).点击按键(按下并抬起按键).按键抬起( ...
- python检测键盘输入termios、等待按键超时检测
试了很多方案都不行或者不好用.win10+linux可以用的方法有pygame和termios pygame方法参考:https://blog.csdn.net/qxqxqzzz/article/de ...
- unity检测键盘的按键名称-JS
建立JS文档 var currentKey:KeyCode; function Start () {currentKey = KeyCode.Space; }function OnGUI(){if ( ...
最新文章
- 请你介绍下Logistic回归模型?
- 硬件信息统计_读取输出Excel_显示进度
- BZOJ2298 [HAOI2011]problem a
- 通过索引优化含ORDER BY的MySQL语句
- go flag包获取命令行参数使用示例
- android 开发中java.lang.verifyerror问题
- WPF LibraryBar去背景色
- UOJ.117.欧拉回路
- LeetCode 519. 随机翻转矩阵(哈希)
- Qt工作笔记-QTreeWidgetItem中type的基本用法
- [心得] 如何利用liquibase進行資料庫版本控制 - 實際練習
- 电脑发短信_让电脑自动给老婆发短信?!这个懒到极致的大神,我是服了...
- java 之 插入排序
- 同态加密 应用案例 入门
- sqlilte 判断当天日期_18个Java8处理日期的新花样,肯定没用过!
- java高级工程师简历模板,MySQL+Tomcat+JVM,看完还怕面试官
- ZIGBEE通过协议栈点对点通信流程
- C语言EasyX_2018中的putimage(x, y, w, h, img, x1, y1)函数
- 5G网络切片的七种武器(六)
- Pancake和import 语句——————————方法的重写