news 2026/7/30 2:26:13

【图像检测】基于LSD算法直线检测matlab代码

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
【图像检测】基于LSD算法直线检测matlab代码

1 简介

提出了一种中国象棋棋盘角点检测的算法.首先采用LSD算法检测出棋盘灰度图像中的大部分直线,然后通过使用基于灰度值区域的投影直方图和基于LSD算法的直线交点检测两种方法,精确地检测出象棋棋盘的角点.最后通过实验,验证了算法的有效性和实时性,对于棋盘的亮度变化、棋盘畸变和边缘模糊具有良好的适应性.

​通过观察 LSD 算法的结果可以发现,棋盘角点大部分都是位于棋盘边线的交点或者交点附近,所 以,可以通过检测出的直线求得这些直线的交点,从而确定象棋棋盘角点的位置.首先,在 LSD 算法检测出的棋盘上的直线后,从直线方向的分布上知道棋盘中信息点( 图 1( a) 中标出的两个点称之为信息点) 处于一些斜线的交点处,而且棋盘上其他角点处于方向位于 90 度,180 度左右直线的交点上,因此,可以通过对 LSD 算法检测出的直线进行分组,先求出这些斜线的交点即信息点的准确位置,然后,通过这两个点的位置可以大致确定棋盘其他角点的近似位置,由于这些直线的信息都是已知的,那么可以找到这些近似位置附近直线的交点,另外,由信息点得到的近似位置是比较接近真实棋盘角点的位置,所以,找到距离近似位置最近的交点的位置即为棋盘角点的位置.

2 部分代码

%{ Finds the angles and the gradients of the image. Generates a list of pseudo ordered points. * * @param scaled_image the image after guassian blur and resize * @param threshold The minimum value of the angle that is considered defined, otherwise NOTDEF * @param n_bins The number of bins with which gradients are ordered by, using bucket sort. * @param list Return: Vector of coordinate points that are pseudo ordered by magnitude. * Pixels would be ordered by norm value, up to a precision given by max_grad/n_bins. %} %list = [y, x, gradient] ordered by gradient %angles & modgrad: img_height * img_width matrix function [angles, modgrad, list] = ll_angle(scaled_image, threshold, n_bins) [height, width, dim] = size(scaled_image); % [modgrad,angles] = imgradient(scaled_image); % max_grad = max(max(modgrad)); % define arrays for store angles and gradient angles = zeros(height, width); modgrad = zeros(height, width); %Undefined the down and right boundaries angles(height, :) = -1024.0; angles(:, width) = -1024.0; max_grad = -1; %Computing gradient for remaining piexls for y = 1 : height-1 for addr = 1 : width-1 % DA = (scaled_image(y+1, addr+1) - scaled_image(y, addr)); % BC = (scaled_image(y+1, addr) - scaled_image(y, addr+1)); DA = (scaled_image(y+1, addr+1) - scaled_image(y, addr)); BC = (scaled_image(y+1, addr) - scaled_image(y, addr+1)); gx = DA + BC; % gx = double(gx); gy = DA - BC; % gy = double(gy); norm = sqrt((gx^2 + gy^2)/4); modgrad(y, addr) = norm; %set angles to nodefine for small gradient if norm <= threshold angles(y, addr) = -1024.0; else angles(y, addr) = atan2(gx,-gy); if norm > max_grad max_grad = norm; end end end end %computing histogram of gradient values count = 1; if max_grad > 0 bin_coef = (n_bins - 1) / max_grad; else bin_coef = 0; end unsorted_list = zeros(height*width,3); for y = 1 : height for x = 1 : width if x < width && y < height i = modgrad(y, x) * bin_coef; else i = -1024; end unsorted_list(count, 1) = y; unsorted_list(count, 2) = x; unsorted_list(count, 3) = i; count= count+1; end end % list = unsorted_list; % sort [a, index] = sort(unsorted_list(:,3),'descend'); list = unsorted_list(index, [1,2 ,3]); % % figure, imshow(angles); % figure, imshow(modgrad); %

3 仿真结果

4 参考文献

[1]段汕, 贺兴, 娄联堂, 徐文, & 罗敬. (2013). 一种基于灰度投影的中国象棋棋盘角点检测算法. 中南民族大学学报:自然科学版, 32(4), 5.

**部分理论引用网络文献,若有侵权联系博主删除。**

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/30 2:24:48

AI论文降重工具对比:千笔与SpeedAI实测指南

1. 毕业论文降AI率工具深度评测&#xff1a;千笔降AIGC助手 VS SpeedAI最近在指导本科生论文时&#xff0c;发现学生们普遍面临一个棘手问题&#xff1a;查重系统对AI生成内容的识别越来越严格。传统降重方法耗时耗力&#xff0c;而专门针对AI生成内容的降重工具开始涌现。本文…

作者头像 李华
网站建设 2026/7/30 2:24:10

彻底告别DLL错误!5步快速修复Windows软件兼容性问题终极指南

彻底告别DLL错误&#xff01;5步快速修复Windows软件兼容性问题终极指南 【免费下载链接】vcredist AIO Repack for latest Microsoft Visual C Redistributable Runtimes 项目地址: https://gitcode.com/gh_mirrors/vc/vcredist 你是否曾经遇到过"找不到MSVCP140.…

作者头像 李华
网站建设 2026/7/30 2:23:05

解决OpenCvSharp NativeMethods初始化异常:从依赖排查到部署实战

1. 问题现场&#xff1a;当OpenCvSharp的NativeMethods对你“Say No”今天调试一个图像处理模块&#xff0c;代码刚跑起来&#xff0c;一个熟悉的异常又蹦了出来&#xff0c;让我心头一紧。这次不是业务逻辑的Bug&#xff0c;而是那个让人又爱又恨的底层依赖——OpenCvSharp。异…

作者头像 李华
网站建设 2026/7/30 2:22:42

C语言scanf函数报错全解析:从缓冲区陷阱到安全输入实践

1. 从“Hello, World!”到第一个拦路虎&#xff1a;为什么是scanf&#xff1f;学C语言&#xff0c;几乎所有人的起点都是那个经典的“Hello, World!”。当你成功在屏幕上打印出这行字&#xff0c;成就感还没捂热乎&#xff0c;下一个任务——让程序“听懂”你输入的内容——就立…

作者头像 李华
网站建设 2026/7/30 2:21:04

小红书数据采集终极指南:快速获取公开数据的完整方案

小红书数据采集终极指南&#xff1a;快速获取公开数据的完整方案 【免费下载链接】xhs 基于小红书 Web 端进行的请求封装。https://reajason.github.io/xhs/ 项目地址: https://gitcode.com/gh_mirrors/xh/xhs 在当今社交媒体分析领域&#xff0c;小红书已经成为内容创作…

作者头像 李华