CN116681721B - Linear track detection and tracking method based on vision - Google Patents
Linear track detection and tracking method based on vision Download PDFInfo
- Publication number
- CN116681721B CN116681721B CN202310669655.7A CN202310669655A CN116681721B CN 116681721 B CN116681721 B CN 116681721B CN 202310669655 A CN202310669655 A CN 202310669655A CN 116681721 B CN116681721 B CN 116681721B
- Authority
- CN
- China
- Prior art keywords
- straight line
- edge
- image
- track
- trajectory
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/40—Image enhancement or restoration using histogram techniques
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/20—Analysis of motion
- G06T7/277—Analysis of motion involving stochastic approaches, e.g. using Kalman filters
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20092—Interactive image processing based on input by user
- G06T2207/20104—Interactive definition of region of interest [ROI]
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/30—Subject of image; Context of image processing
- G06T2207/30241—Trajectory
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/30—Subject of image; Context of image processing
- G06T2207/30248—Vehicle exterior or interior
- G06T2207/30252—Vehicle exterior; Vicinity of vehicle
- G06T2207/30256—Lane; Road marking
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02T—CLIMATE CHANGE MITIGATION TECHNOLOGIES RELATED TO TRANSPORTATION
- Y02T10/00—Road transport of goods or passengers
- Y02T10/10—Internal combustion engine [ICE] based vehicles
- Y02T10/40—Engine management systems
Landscapes
- Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Theoretical Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Multimedia (AREA)
- Image Analysis (AREA)
Abstract
Description
技术领域Technical Field
本发明属于计算机视觉与图像处理领域,具体涉及一种基于视觉的直线轨迹检测与跟踪方法。The invention belongs to the field of computer vision and image processing, and in particular relates to a vision-based straight line trajectory detection and tracking method.
背景技术Background Art
在车辆辅助驾驶、自动驾驶,机器人巡线运动等应用中,直线轨迹的检测与跟踪是关键的核心技术之一。由于目前绝大部分的直线轨迹是通过有颜色的涂料喷涂或印刷在地面上的,因此只能利用视觉图像采集设备获取直线轨迹的图像,通过对图像的处理和分析对其进行检测和跟踪。现有的基于颜色的直线轨迹检测方法,易受到光照、天气条件的影响,在复杂环境中检测和跟踪的鲁棒性较差。而基于直线检测的方法,无法处理直线轨迹中断、污染、磨损等情况,导致误检和漏检。In applications such as vehicle assisted driving, autonomous driving, and robot line patrol, the detection and tracking of straight line trajectories is one of the key core technologies. Since most of the straight line trajectories are currently sprayed or printed on the ground with colored paint, the image of the straight line trajectory can only be acquired using visual image acquisition equipment, and then detected and tracked by processing and analyzing the image. The existing color-based straight line trajectory detection method is easily affected by lighting and weather conditions, and has poor robustness in detection and tracking in complex environments. The method based on straight line detection cannot handle situations such as straight line trajectory interruption, pollution, and wear, resulting in false detection and missed detection.
随着深度学习技术的发展,基于深度学习的直线轨迹检测方法不断涌现。但这类方法普遍依赖大规模的带有真实标签的图像数据集进行训练。然而对于许多特殊的应用场景,如港口、工厂等,采集和制作包含多种天气和光照条件的直线轨迹检测图像数据集的成本十分高昂,这极大地限制了基于深度学习方法的应用。此外,这类方法的泛化能力有限,在某个特定场景数据集上训练得到的模型,无法应用到其他场景中。With the development of deep learning technology, straight line trajectory detection methods based on deep learning continue to emerge. However, such methods generally rely on large-scale image datasets with real labels for training. However, for many special application scenarios, such as ports and factories, the cost of collecting and producing straight line trajectory detection image datasets containing a variety of weather and lighting conditions is very high, which greatly limits the application of deep learning-based methods. In addition, the generalization ability of such methods is limited, and the model trained on a specific scene dataset cannot be applied to other scenarios.
在工业自动化、智能化的背景下,许多应用场景对直线轨迹检测的精度提出了更高的要求,甚至可达到几十微米的级别(如焊缝跟踪)。这就要求直线轨迹的检测算法具备更强的特征提取检测能力,并且能够利用环境信息对错误检测结果进行筛除。不仅如此,由于应用场景变化多样,检测算法必须能够根据光照、天气、标记线的状态等因素进行自适应调整,以提高检测和跟踪的鲁棒性。In the context of industrial automation and intelligence, many application scenarios have put forward higher requirements for the accuracy of linear trajectory detection, which can even reach the level of tens of microns (such as weld tracking). This requires the linear trajectory detection algorithm to have stronger feature extraction and detection capabilities, and to be able to use environmental information to filter out erroneous detection results. In addition, due to the diverse application scenarios, the detection algorithm must be able to make adaptive adjustments based on factors such as lighting, weather, and the status of the marking line to improve the robustness of detection and tracking.
综上所述,现有基于图像处理的直线轨迹检测方法精度和鲁棒性较差,难以满足复杂场景的使用需求;而基于深度学习的直线轨迹检测方法依赖大规模数据集,且泛化能力较差,限制了其在实际场景中的应用。针对这些问题,本发明提出一种基于视觉的直线轨迹检测与跟踪方法,可实现复杂天气和工况条件下,对单条、双条以及多条,连续或不连续直线型直线轨迹的检测与跟踪。In summary, the existing straight line trajectory detection methods based on image processing have poor accuracy and robustness, and are difficult to meet the use requirements of complex scenes; while the straight line trajectory detection methods based on deep learning rely on large-scale data sets and have poor generalization capabilities, which limits their application in actual scenes. In response to these problems, the present invention proposes a straight line trajectory detection and tracking method based on vision, which can realize the detection and tracking of single, double, and multiple, continuous or discontinuous straight line trajectories under complex weather and working conditions.
发明内容Summary of the invention
为解决上述问题,本发明提出一种基于视觉的直线轨迹检测与跟踪方法,该方法包括如下步骤:To solve the above problems, the present invention proposes a vision-based straight line trajectory detection and tracking method, which includes the following steps:
步骤S1:视觉图像采集装置拍摄直线轨迹图像;Step S1: the visual image acquisition device captures a straight line trajectory image;
步骤S2:对步骤S1拍摄到的直线轨迹图像进行增强,并提取梯度特征信息,根据梯度幅值信息,识别每条直线轨迹边缘得到边缘图;Step S2: enhancing the straight line track image captured in step S1, extracting gradient feature information, and identifying the edge of each straight line track according to the gradient amplitude information to obtain an edge map;
步骤S3:对步骤S2得到的边缘图采用逆透视变换方法消除图像拍摄过程中产生的透视效应,得到变换后的边缘图;Step S3: using an inverse perspective transformation method to eliminate the perspective effect produced during the image shooting process on the edge map obtained in step S2, and obtaining a transformed edge map;
步骤S4:采用滑动窗口法对步骤S3得到的变换后的逐条直线轨迹边缘进行检测,并筛选出符合要求的直线轨迹边缘,最终拟合得到符合要求的直线轨迹边缘所在直线的方程;Step S4: using a sliding window method to detect the edges of each of the transformed straight line tracks obtained in step S3, and screening out the straight line track edges that meet the requirements, and finally fitting to obtain the equation of the straight line where the straight line track edges that meet the requirements are located;
步骤S5:采用卡尔曼滤波器对连续拍摄的多幅图像中检测得到的每一条符合要求的直线轨迹进行跟踪,并根据直线轨迹边缘的检测置信度,自适应地调整卡尔曼增益。Step S5: using a Kalman filter to track each straight line trajectory that meets the requirements detected in the multiple images taken continuously, and adaptively adjusting the Kalman gain according to the detection confidence of the edge of the straight line trajectory.
进一步地,步骤S1具体包括如下步骤:Furthermore, step S1 specifically includes the following steps:
步骤1-1:所述视觉图像采集装置包括但不限于监控相机、工业相机及网络摄像机;Step 1-1: The visual image acquisition device includes but is not limited to a surveillance camera, an industrial camera and a network camera;
步骤1-2:将视觉图像采集装置部署在车辆或移动机器人的适当位置,以保证待检测和跟踪的直线轨迹处于视觉图像采集装置的视野范围内,视觉图像采集装置的光轴垂直于地面或呈γ角度向地面倾斜,γ∈[0°,90°],使用视觉图像采集装置拍摄直线轨迹的图像。Step 1-2: Deploy the visual image acquisition device at an appropriate position of the vehicle or mobile robot to ensure that the straight line trajectory to be detected and tracked is within the field of view of the visual image acquisition device. The optical axis of the visual image acquisition device is perpendicular to the ground or inclined to the ground at an angle γ, γ∈[0°,90°]. Use the visual image acquisition device to capture an image of the straight line trajectory.
进一步地,步骤S2具体包括如下步骤:Furthermore, step S2 specifically includes the following steps:
步骤2-1:逐一将视觉图像采集装置拍摄的直线轨迹图像作为输入,并使用固定尺寸矩形框,在输入图像中划分出直线轨迹所在的感兴趣区域;Step 2-1: taking the straight line trajectory images captured by the visual image acquisition device as input one by one, and using a fixed-size rectangular frame to divide the region of interest where the straight line trajectory is located in the input image;
步骤2-2:对感兴趣区域内的图像进行灰度化处理;Step 2-2: grayscale the image in the region of interest;
步骤2-3:对经过灰度化处理的图像进行图像增强;Step 2-3: Perform image enhancement on the grayscale processed image;
步骤2-4:利用Sobel算子分别提取增强后图像的水平和竖直方向上的梯度信息Gx和Gy:Step 2-4: Use the Sobel operator to extract the horizontal and vertical gradient information G x and G y of the enhanced image respectively:
其中*表示卷积运算,I表示经过灰度化处理和图像增强的感兴趣区域图像;Where * represents the convolution operation, and I represents the image of the region of interest after grayscale processing and image enhancement;
步骤2-5:根据下式计算每个像素的梯度幅值GM:Step 2-5: Calculate the gradient magnitude GM of each pixel according to the following formula:
GM(x,y)=|Gx(x,y)|GM(x,y)=|G x (x,y)|
其中Gx(x,y)表示坐标(x,y)处像素的梯度信息Gx;Where G x (x, y) represents the gradient information G x of the pixel at the coordinate (x, y);
步骤2-6:设置梯度幅值阈值TM,感兴趣区域图像中梯度幅值GM大于等于阈值TM的像素点为边缘像素点,得到边缘图E:Step 2-6: Set the gradient amplitude threshold TM . The pixels in the region of interest image whose gradient amplitude GM is greater than or equal to the threshold TM are edge pixels, and the edge map E is obtained:
进一步地,步骤S3具体包括如下步骤:Furthermore, step S3 specifically includes the following steps:
步骤3-1:对步骤S2得到的边缘图逆透视变换过程如下:Step 3-1: The process of inverse perspective transformation of the edge image obtained in step S2 is as follows:
其中A3×3表示逆透视变换矩阵,[u v 1]T表示原始图像中像素点的坐标,称之为源点坐标,[x y 1]T表示变换后的像素点坐标,称之为目标点坐标,需得到至少三组不共线的相对应的源点和目标点坐标,即可求解逆透视变换矩阵A3×3;Where A 3×3 represents the inverse perspective transformation matrix, [uv 1] T represents the coordinates of the pixels in the original image, which are called the source point coordinates, and [xy 1] T represents the coordinates of the pixels after transformation, which are called the target point coordinates. At least three sets of corresponding source and target point coordinates that are not collinear need to be obtained to solve the inverse perspective transformation matrix A 3×3 ;
步骤3-2:在初始化时,对于单条的细直线轨迹,通过手动选择的方式在图像中选取直线轨迹边缘与感兴趣区域上下边界的交点,并计算两个交点关于边缘图E水平方向中心线对称的两个点,作为四个源点;Step 3-2: During initialization, for a single thin straight line track, manually select the intersection points of the edge of the straight line track and the upper and lower boundaries of the region of interest in the image, and calculate two points symmetrical about the horizontal center line of the edge map E as four source points.
对于单条的粗直线轨迹,通过手动选择的方式在图像中选取直线轨迹左右两个边缘与感兴趣区域上下边界的交点,作为四个源点;For a single thick straight line trajectory, the intersection points of the left and right edges of the straight line trajectory and the upper and lower boundaries of the region of interest were selected in the image by manual selection as four source points;
对于多条相互平行的细直线轨迹,通过手动选择的方式在图像中选取左起第一条直线轨迹边缘和最后一条直线轨迹边缘与感兴趣区域上下边界的交点,作为四个源点;For multiple parallel thin straight line tracks, the intersection points of the edge of the first straight line track from the left and the edge of the last straight line track with the upper and lower boundaries of the region of interest were selected manually in the image as four source points;
对于多条相互平行的粗直线轨迹,通过手动选择的方式在图像中选取左起第一条直线轨迹的左侧边缘和最后一条直线轨迹的右侧边缘与感兴趣区域上下边界的交点,作为四个源点;For multiple parallel thick straight line tracks, the intersection points of the left edge of the first straight line track from the left and the right edge of the last straight line track from the left and the upper and lower boundaries of the region of interest are selected manually in the image as four source points;
从左下角的源点开始按逆时针顺序分别命名为LB、LU、RU和RB,其坐标分别为[uLBvLB 1]T、[uLU vLU 1]T、[uRU vRU 1]T和[uRB vRB 1]T;Starting from the source point in the lower left corner, they are named LB, LU, RU, and RB in counterclockwise order, and their coordinates are [u LB v LB 1] T , [u LU v LU 1] T , [u RU v RU 1] T , and [u RB v RB 1] T ;
步骤3-3:四个源点对应的目标点坐标分别为Step 3-3: The coordinates of the target points corresponding to the four source points are
步骤3-4:根据步骤3-2和3-3得到的源点与目标点坐标,求得步骤3-1中所述的逆透视变换矩阵A3×3,将步骤S2所得边缘图中所有的像素点的齐次坐标与A3×3相乘得到变换后的边缘图;Step 3-4: According to the coordinates of the source point and the target point obtained in steps 3-2 and 3-3, the inverse perspective transformation matrix A 3×3 described in step 3-1 is obtained, and the homogeneous coordinates of all the pixel points in the edge map obtained in step S2 are multiplied by A 3×3 to obtain the transformed edge map;
步骤3-5:对于包含多条相互平行的直线轨迹的图像,当前帧的源点坐标据前一帧图像的直线轨迹检测结果进行自动选择,进而实现逆透视变换矩阵的自适应调整;受透视效应的影响,原本保持平行关系的直线轨迹在图像中相交于消失点;利用前一帧图像中检测到的直线轨迹边缘所在的直线方程,通过最小二乘法计算得到其交点,即消失点坐标;然后对于细直线轨迹,分别连接消失点与左起第一条直线轨迹边缘和最后一条直线轨迹边缘的下侧端点,对于粗直线轨迹,分别连接消失点与左起第一条直线轨迹的左侧边缘和最后一条直线轨迹的右侧边缘的下侧端点;两条连接线与感兴趣区域上下边界的交点,即为当前帧图像的一组源点。Step 3-5: For an image containing multiple parallel straight line tracks, the source point coordinates of the current frame are automatically selected according to the straight line track detection result of the previous frame image, thereby realizing adaptive adjustment of the inverse perspective transformation matrix; affected by the perspective effect, the straight line tracks that originally maintained a parallel relationship intersect at the vanishing point in the image; using the straight line equation where the edge of the straight line track detected in the previous frame image is located, the intersection point, i.e., the vanishing point coordinates, is calculated by the least squares method; then, for the thin straight line track, the vanishing point is connected to the lower end points of the edge of the first straight line track from the left and the edge of the last straight line track, respectively; for the thick straight line track, the vanishing point is connected to the lower end points of the left edge of the first straight line track from the left and the right edge of the last straight line track, respectively; the intersection points of the two connecting lines with the upper and lower boundaries of the region of interest are a set of source points of the current frame image.
进一步地,步骤S4具体包括如下步骤:Furthermore, step S4 specifically includes the following steps:
步骤4-1:将逆透视变换后的边缘图分别向图像的横轴做投影,得到对应的统计直方图;Step 4-1: Project the edge map after inverse perspective transformation onto the horizontal axis of the image to obtain the corresponding statistical histogram;
步骤4-2:通过一维卷积的方式对统计直方图做均值滤波,消除数据中的噪声,并且只保留统计值超过统计结果最大值的TE%的点;Step 4-2: Perform mean filtering on the statistical histogram by one-dimensional convolution to eliminate the noise in the data, and only retain the points whose statistical values exceed TE % of the maximum value of the statistical result;
步骤4-3:经过滤波处理后,每幅直方图中的峰值点对应的横坐标表示当前边缘的初始基点坐标;Step 4-3: After filtering, the horizontal coordinate corresponding to the peak point in each histogram represents the initial base point coordinate of the current edge;
步骤4-4:以初始基点为起始点,采用固定的窗口尺寸h×w和步长s沿图像纵轴方向进行搜索,其中h是窗口的高度,w是窗口的宽度,在数值上等于粗直线与细直线划分的宽度阈值,如果窗口中的边缘像素点数量超过设定阈值TP,则认定该窗口为有效窗口,其内部的边缘像素点被看作有效边缘像素点,计算窗口内部所有边缘像素点横坐标的平均值,以此更新搜索窗口的基点坐标;Step 4-4: Starting from the initial base point, use a fixed window size h×w and step length s to search along the vertical axis of the image, where h is the height of the window and w is the width of the window, which is numerically equal to the width threshold dividing the thick straight line and the thin straight line. If the number of edge pixels in the window exceeds the set threshold TP , the window is considered a valid window, and the edge pixels inside it are regarded as valid edge pixels. The average value of the horizontal coordinates of all edge pixels inside the window is calculated to update the base point coordinates of the search window.
步骤4-5:如果窗口中的边缘像素点数量不超过设定阈值TP,则认定该窗口为无效窗口,保持基点坐标不变,继续沿纵轴方向搜索,直至达到预设的搜索次数N;Step 4-5: If the number of edge pixels in the window does not exceed the set threshold value TP , the window is deemed to be an invalid window, the base point coordinates are kept unchanged, and the search continues along the vertical axis until the preset search times N are reached;
步骤4-6:对于每条直线轨迹边缘,如果其对应的有效窗口数目大于阈值TW,则认定该直线轨迹边缘为候选边缘,对于单条细的或粗的直线轨迹,候选边缘即为符合要求的直线轨迹边缘;Step 4-6: For each straight track edge, if the number of valid windows corresponding to it is greater than the threshold T W , the straight track edge is identified as a candidate edge. For a single thin or thick straight track, the candidate edge is a straight track edge that meets the requirements;
对于多条相互平行的细的或粗的直线轨迹,需要对直线轨迹边缘进行配对后,结合同对候选边缘之间的距离约束,筛选出符合要求的候选边缘,具体包括步骤4-7:For multiple parallel thin or thick straight line tracks, it is necessary to pair the straight line track edges and select the candidate edges that meet the requirements in combination with the distance constraints between the same pair of candidate edges. The specific steps include steps 4-7:
步骤4-7:对于多条相互平行的细直线轨迹,第t对边缘图Grt=<Et,Et+1>中所有的候选边缘的初始基点坐标构成的集合分别Bt,Bt+1,t=1,2,...,T-1,则候选边缘的初始基点坐标必须满足以下条件:Step 4-7: For multiple parallel thin straight line trajectories, the set of initial base point coordinates of all candidate edges in the t-th edge graph Gr t = <E t ,E t+1 > is respectively B t ,B t+1 , t=1,2,...,T-1, then the initial base point coordinates of the candidate edges must satisfy the following conditions:
其中Dt为第t对直线轨迹边缘之间的固定距离,Tt为第t对直线轨迹边缘之间距离偏差阈值;对于满足上述条件的初始基点坐标集合B′t,B′t+1,t=1,2,...,T-1,有效的初始基点坐标为Where Dt is the fixed distance between the edges of the t-th pair of straight line tracks, and Tt is the distance deviation threshold between the edges of the t-th pair of straight line tracks. For the initial base point coordinate set B′t , B′t +1 , t=1, 2, ..., T-1 that meets the above conditions, the effective initial base point coordinates are
为对应的候选边缘为符合要求的直线轨迹边缘; The corresponding candidate edge is a straight line trajectory edge that meets the requirements;
对于多条相互平行的粗直线轨迹,第t对边缘图和中所有的候选边缘的初始基点坐标构成的集合分别则候选边缘的初始基点坐标必须满足以下条件:For multiple parallel thick straight line trajectories, the tth pair of edge graphs and The sets of initial base point coordinates of all candidate edges in are Then the initial base point coordinates of the candidate edge must meet the following conditions:
其中和分别为第t对直线轨迹左右侧边缘之间的固定距离,Tt L和Tt R分别为第t对直线轨迹左右侧边缘之间距离偏差阈值;对于满足上述条件的初始基点坐标集合有效的初始基点坐标为in and are the fixed distances between the left and right edges of the t-th pair of straight line tracks, T t L and T t R are the distance deviation thresholds between the left and right edges of the t-th pair of straight line tracks; for the initial base point coordinate set that meets the above conditions The valid initial base point coordinates are
为对应的候选边缘为符合要求的直线轨迹边缘; The corresponding candidate edge is a straight line trajectory edge that meets the requirements;
步骤4-8:对于每条符合要求的直线轨迹边缘,对其所包含的有效边缘像素点进行直线拟合,得到该边缘对应的直线方程。Step 4-8: For each straight line trajectory edge that meets the requirements, perform straight line fitting on the valid edge pixels contained therein to obtain the straight line equation corresponding to the edge.
进一步地,对直线轨迹边缘进行配对的具体方法是:Furthermore, the specific method for pairing the edges of the straight line tracks is:
对于多条相互平行的细直线轨迹,将直线轨迹沿图像水平方向从左向右依次划分为T条直线轨迹,T表示直线轨迹数量,并将边缘图E按照边缘所属的直线轨迹另存为T幅边缘图E1,E2,...,ET:For multiple parallel thin straight line tracks, the straight line tracks are divided into T straight line tracks from left to right along the horizontal direction of the image, where T represents the number of straight line tracks, and the edge map E is saved as T edge maps E 1 , E 2 , ..., E T according to the straight line tracks to which the edges belong:
按照相对位置关系,将相邻的两个直线轨迹边缘划分为一对Grt,划分方式如下:According to the relative position relationship, the edges of two adjacent straight track are divided into a pair of Gr t , and the division method is as follows:
Grt=<Et,Et+1>,t=1,2,...,T-1Gr t =<E t ,E t+1 >,t=1,2,...,T-1
对于输入图像中,对于粗直线轨迹,根据梯度方向信息,将直线轨迹边缘分成左侧、右侧和其他三类,具体步骤如下:For the rough straight line track in the input image, the straight line track edge is divided into three categories: left side, right side and others according to the gradient direction information. The specific steps are as follows:
根据下式计算每个像素的梯度方向特征GD:The gradient direction feature GD of each pixel is calculated according to the following formula:
其中Gx(x,y)和Gy(x,y)分别表示坐标(x,y)处像素的梯度信息Gx和Gy;Where G x (x, y) and G y (x, y) represent the gradient information G x and G y of the pixel at the coordinate (x, y) respectively;
根据方向特征GD将所有的边缘图E中的像素点分成左侧右侧和其他三个集合,划分方式如下:According to the directional feature GD, all the pixels in the edge map E are divided into the left and right Right and others The three sets are divided as follows:
属于其他类别的边缘像素点将被忽略,即如果则E(x,y)=0;属于左侧类别的像素点保存为左边缘图EL,即如果则EL(x,y)=255;属于右侧类别的像素点保存为右边缘图ER,即如果则ER(x,y)=255;Other The edge pixels of the category will be ignored, that is, if Then E(x,y)=0; belongs to the left side The pixel points of the category are saved as the left edge map EL , that is, if Then E L (x, y) = 255; belongs to the right side The pixel points of the category are saved as the right edge map ER , that is, if Then ER (x, y) = 255;
对于多条相互平行的粗直线轨迹,将直线轨迹沿图像水平方向从左向右依次划分为T条直线轨迹,T表示直线轨迹数量,并将边缘图E按照边缘所属的直线轨迹和边缘类别另存为2T幅边缘图 For multiple parallel thick straight line tracks, divide the straight line tracks into T straight line tracks from left to right along the horizontal direction of the image, where T represents the number of straight line tracks, and save the edge map E as 2T edge maps according to the straight line track and edge category to which the edge belongs.
按照相对位置关系,将相邻的两个直线轨迹的同类别边缘划分为一对或划分方式如下:According to the relative position relationship, the edges of the same category of two adjacent straight line trajectories are divided into a pair or The division is as follows:
进一步地,步骤4-4和4-5中所述的有效像素点数量阈值TP根据直线轨迹检测结果与搜索次数进行自适应调整:Furthermore, the effective pixel number threshold TP in steps 4-4 and 4-5 is adaptively adjusted according to the straight line trajectory detection result and the number of searches:
其中,N表示预设搜索次数,Px表示搜索窗口范围内有效边缘像素点统计值之和,且Where N represents the preset number of searches, P x represents the sum of the statistical values of valid edge pixels within the search window, and
其中,表示统计直方图中坐标i对应的统计值,x表示初始基点的横坐标值。in, It represents the statistical value corresponding to the coordinate i in the statistical histogram, and x represents the horizontal coordinate value of the initial base point.
进一步地,步骤S5具体包括如下步骤:Furthermore, step S5 specifically includes the following steps:
步骤5-1:步骤4-6所述的有效窗口数目反映了当前候选边缘检测的可靠程度,有效窗口数量越多,则表示该候选边缘检测置信度越高;Step 5-1: The number of valid windows described in step 4-6 reflects the reliability of the current candidate edge detection. The more valid windows there are, the higher the confidence of the candidate edge detection.
对于细直线轨迹,检测置信度的计算方法为:For thin straight line trajectories, the detection confidence is calculated as:
其中ct表示第t条符合要求的直线轨迹边缘对应的检测置信度,nt表示该边缘的有效窗口的数量,N表示预设搜索次数,β表示修正系数,T表示符合要求的直线轨迹总数;Where c t represents the detection confidence corresponding to the tth straight line track edge that meets the requirements, nt represents the number of valid windows of the edge, N represents the preset number of searches, β represents the correction coefficient, and T represents the total number of straight line tracks that meet the requirements;
对于粗直线轨迹,检测置信度的计算方法为:For a rough straight line trajectory, the detection confidence is calculated as:
其中和分别表示第t条符合要求的直线轨迹左右边缘对应的检测置信度,和分别表示第t条符合要求的直线轨迹左右边缘的有效窗口的数量,N表示预设搜索次数,β表示修正系数,T表示符合要求的直线轨迹总数;in and They represent the detection confidence corresponding to the left and right edges of the tth straight line trajectory that meets the requirements, and They represent the number of valid windows on the left and right edges of the tth straight line trajectory that meets the requirements, N represents the preset number of searches, β represents the correction coefficient, and T represents the total number of straight line trajectories that meet the requirements;
步骤5-2:对于细直线轨迹,每条符合要求的直线轨迹边缘所在直线与感兴趣区域上下界形成两个交点,其对应的置信度分别为和且则根据置信度构建修正系数矩阵 Step 5-2: For thin straight line trajectories, the straight line where the edge of each straight line trajectory that meets the requirements is located and the upper and lower boundaries of the region of interest form two intersection points, and their corresponding confidence levels are and and Then construct the correction coefficient matrix according to the confidence level
对于粗直线轨迹,每条符合要求的直线轨迹的左右边缘所在直线与感兴趣区域上下界形成四个交点,其对应的置信度分别为和且 则根据置信度构建修正系数矩阵For the rough straight line trajectory, the straight lines where the left and right edges of each straight line trajectory that meets the requirements are located and the upper and lower boundaries of the region of interest form four intersection points, and their corresponding confidence levels are and and Then construct the correction coefficient matrix according to the confidence level
步骤5-3:计算修正后的测量误差协方差矩阵R'Step 5-3: Calculate the corrected measurement error covariance matrix R'
R'=diag(Ck)RR' = diag(C k )R
其中diag(·)表示对角化操作,R表示初始测量误差协方差矩阵,R=sR×U,sR表示放缩系数,U表示单位阵;Where diag(·) represents the diagonalization operation, R represents the initial measurement error covariance matrix, R = s R × U, s R represents the scaling factor, and U represents the unit matrix;
步骤5-4:修正后的卡尔曼增益Kk为Step 5-4: The modified Kalman gain K k is
Kk=PkMT(MPkMT+R')-1 K k =P k M T (MP k M T +R') -1
其中Pk表示第k帧图像的先验估计误差的协方差矩阵,初始化为P0=U,M表示测量矩阵,对于细直线轨迹,对于粗直线轨迹,其中第i行,第j列的元素Mij如下 Where Pk represents the covariance matrix of the prior estimation error of the k-th frame image, initialized to P0 = U, M represents the measurement matrix, for a thin straight line trajectory, For a rough straight line trajectory, The element Mij in the i-th row and j-th column is as follows
步骤5-5:步骤5-4所述先验估计误差的协方差矩阵Pk的计算方法为Step 5-5: The calculation method of the covariance matrix P k of the prior estimation error in step 5-4 is:
其中Q表示过程噪声的协方差矩阵,Q=sQ×U,sQ表示放缩系数,上标T表示矩阵的转置,A表示转移状态矩阵,Where Q represents the covariance matrix of process noise, Q = s Q × U, s Q represents the scaling factor, the superscript T represents the transpose of the matrix, and A represents the transfer state matrix.
对于细直线轨迹:For thin straight lines:
对于粗直线轨迹:For a rough straight line trajectory:
表示第k-1帧的后验估计误差的协方差矩阵,其更新过程如下 Represents the covariance matrix of the posterior estimation error of the k-1th frame, and its update process is as follows
其中U表示单位矩阵;Where U represents the identity matrix;
步骤5-6:对于细直线轨迹,步骤4-8所得符合要求的第t条直线轨迹边缘所在的直线与感兴趣区域的上下边界形成2个交点,交点的横坐标分别为和构成第k帧测量值矩阵 Step 5-6: For the thin straight line trajectory, the straight line where the edge of the tth straight line trajectory that meets the requirements obtained in step 4-8 is located forms two intersection points with the upper and lower boundaries of the region of interest. The horizontal coordinates of the intersection points are and Construct the k-th frame measurement matrix
对于粗直线轨迹,步骤4-8所得符合要求的第t条直线轨迹左右边缘所在的直线与感兴趣区域的上下边界形成4个交点,交点的横坐标分别为和构成第k帧测量值矩阵 For the rough straight line trajectory, the straight lines where the left and right edges of the tth straight line trajectory that meets the requirements obtained in steps 4-8 and the upper and lower boundaries of the region of interest form four intersection points, and the horizontal coordinates of the intersection points are and Construct the k-th frame measurement matrix
第k帧测量值矩阵Zk计算方式如下:The k-th frame measurement matrix Z k is calculated as follows:
Zk=MXk Z k =MX k
其中,Xk表示第k帧状态估计值矩阵;Where Xk represents the state estimation matrix of the kth frame;
步骤5-7:对于细直线轨迹:其中和分别表示第t条直线轨迹边缘所在的直线与感兴趣区域的上下边界形成的2个交点的横坐标的估计值,是由上一帧图像的预测结果估计得到的;表示相邻两帧之间的变化量,表示相邻两帧之间的变化量;Steps 5-7: For thin straight track: in and They respectively represent the estimated values of the horizontal coordinates of the two intersection points formed by the straight line where the edge of the t-th straight line trajectory is located and the upper and lower boundaries of the region of interest, which are estimated from the prediction result of the previous frame image; Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between
对于粗直线轨迹,直线轨迹的宽度值将作为一个额外的约束条件用于对直线轨迹进行跟踪:其中和分别表示第t条直线轨迹左右边缘所在的直线与感兴趣区域的上下边界形成的4个交点的横坐标的估计值,是由上一帧图像的预测结果估计得到的;表示相邻两帧之间的变化量,表示相邻两帧之间的变化量,表示相邻两帧之间的变化量,表示相邻两帧之间的变化量;表示直线轨迹顶部的宽度,表示相邻两帧宽度的变化量,表示直线轨迹底部的宽度,表示相邻两帧宽度的变化量;For thick straight line tracks, the width of the straight line track will be used as an additional constraint to track the straight line track: in and The estimated values of the horizontal coordinates of the four intersection points formed by the straight lines where the left and right edges of the t-th straight line trajectory are located and the upper and lower boundaries of the region of interest are estimated from the prediction results of the previous frame image; Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between represents the width of the top of the straight line track, Indicates the change in width between two adjacent frames. Indicates the width of the bottom of the straight line track, Indicates the change in width between two adjacent frames;
步骤5-8:第k帧状态估计值矩阵Xk计算方式如下:Step 5-8: The k-th frame state estimation matrix X k is calculated as follows:
其中表示第k-1帧的后验状态估计值矩阵,计算方式如下:in Represents the posterior state estimate matrix of the k-1th frame, which is calculated as follows:
对于细直线轨迹,初始值为第一帧图像的直线轨迹边缘端点横坐标的检测结果;对于粗直线轨迹,初始值为第一帧图像的直线轨迹边缘端点横坐标和直线轨迹宽度的检测结果;For thin straight line trajectories, the initial value is the detection result of the horizontal coordinate of the edge endpoint of the straight line trajectory of the first frame image; for the rough straight line trajectory, the initial value is the detection result of the horizontal coordinates of the edge endpoints of the straight line track and the width of the straight line track of the first frame image;
步骤5-9:直线轨迹跟踪的最终输出结果为计算方式如下:Step 5-9: The final output of the straight line trajectory tracking is The calculation is as follows:
有益效果:采用基于图像增强的梯度特征提取方法,能够增强直线轨迹边缘检测对于光照和天气变化的鲁棒性,提高对复杂环境的适应能力;使用基于滑动窗口的直线轨迹检测方法,能够有效地解决标记线中断、污染、磨损等问题;根据直线轨迹检测结果,自适应调整卡尔曼增益,增强了车道线跟踪的稳定性。本发明提出的直线轨迹检测方法无需依赖数据集训练,且具备较高的检测精度和鲁棒性,能够实现复杂环境和工况下,单条或者多条相互平行的细的或粗的连续或不连续的直线轨迹进行检测与跟踪。Beneficial effects: The gradient feature extraction method based on image enhancement can enhance the robustness of the straight line trajectory edge detection to changes in lighting and weather, and improve the adaptability to complex environments; the straight line trajectory detection method based on sliding windows can effectively solve problems such as marker line interruption, pollution, and wear; according to the straight line trajectory detection results, the Kalman gain is adaptively adjusted to enhance the stability of lane line tracking. The straight line trajectory detection method proposed by the present invention does not need to rely on data set training, and has high detection accuracy and robustness, and can realize the detection and tracking of single or multiple parallel thin or thick continuous or discontinuous straight line trajectories in complex environments and working conditions.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
图1是港口轮胎式龙门吊车上监控相机安装示意图;Figure 1 is a schematic diagram of the installation of a monitoring camera on a port rubber-tyred gantry crane;
图2是监控相机拍摄的直线轨迹(车道线)的图像;Figure 2 is an image of a straight line track (lane line) captured by a surveillance camera;
图3是本发明所涉及的流程图;FIG3 is a flow chart of the present invention;
图4是边缘检测结果图;Fig. 4 is an edge detection result diagram;
图5是逆透视变换后的第二条直线轨迹的右侧边缘图;FIG5 is a right edge diagram of the second straight line track after inverse perspective transformation;
图6是基于消失点选取源点坐标的方法示意图;FIG6 is a schematic diagram of a method for selecting source point coordinates based on vanishing points;
图7是经滤波处理的第二条直线轨迹的右侧边缘对应的统计直方图;FIG7 is a statistical histogram corresponding to the right edge of the second straight line track after filtering;
图8是第二条直线轨迹的右侧边缘对应的统计直方图;FIG8 is a statistical histogram corresponding to the right edge of the second straight line track;
图9是基于滑动窗口法检测直线轨迹的方法示意图;FIG9 is a schematic diagram of a method for detecting a straight line trajectory based on a sliding window method;
图10是移动机器人结构示意图;FIG10 is a schematic diagram of the structure of a mobile robot;
图11是工业相机拍摄的焊缝图像。Figure 11 is a weld image taken by an industrial camera.
具体实施方式DETAILED DESCRIPTION
为充分阐述本发明在不同的视觉采集设备部署方式和不同的直线轨迹形式条件下的检测与跟踪过程,本发明介绍了两个具体的实施例:港口轮胎式龙门吊车车道线检测和移动机器人焊缝跟踪,以下结合附图对本发明作进一步详细说明。In order to fully explain the detection and tracking process of the present invention under different visual acquisition equipment deployment modes and different straight line trajectory conditions, the present invention introduces two specific embodiments: port tire gantry crane lane line detection and mobile robot weld tracking. The present invention is further described in detail below with reference to the accompanying drawings.
发明实施例1:Invention Example 1:
如图1所示,本发明的基于视觉的直线轨迹检测与跟踪方法,在港口轮胎式龙门吊车车道线检测实施例中所基于的硬件基础为:港口轮胎式龙门吊车的立柱2位于两条直线轨迹3的中间,视觉图像采集设备1安装在港口轮胎式龙门吊车的立柱2上,设备1的光轴与立柱成45°夹角,向地面倾斜。As shown in FIG1 , the vision-based straight-line trajectory detection and tracking method of the present invention is based on the hardware foundation in the embodiment of lane line detection of a port tire-type gantry crane as follows: the column 2 of the port tire-type gantry crane is located in the middle of two straight-line trajectories 3, and the visual image acquisition device 1 is installed on the column 2 of the port tire-type gantry crane, and the optical axis of the device 1 forms an angle of 45° with the column and is inclined toward the ground.
基于上述硬件系统,本实施例的基于视觉的直线轨迹检测与跟踪方法,包含如下步骤:Based on the above hardware system, the visual-based straight line trajectory detection and tracking method of this embodiment includes the following steps:
步骤1:视觉图像采集装置拍摄直线轨迹图像;Step 1: The visual image acquisition device captures the straight line trajectory image;
步骤1-1:所述视觉图像采集装置包括但不限于监控相机、工业相机及网络摄像机,在本实施例中采用的是监控相机;Step 1-1: The visual image acquisition device includes but is not limited to a surveillance camera, an industrial camera, and a network camera. In this embodiment, a surveillance camera is used;
步骤1-2:将监控相机部署在港口轮胎式龙门吊车的立柱上,以保证待检测和跟踪的直线轨迹处于监控相机的视野范围内,监控相机的光轴与立柱成γ=45°夹角,向地面倾斜;Step 1-2: Deploy the surveillance camera on the column of the port rubber-tyred gantry crane to ensure that the straight line trajectory to be detected and tracked is within the field of view of the surveillance camera. The optical axis of the surveillance camera forms an angle of γ = 45° with the column and is tilted toward the ground.
步骤1-3:使用监控相机拍摄直线轨迹的图像,如图2所示。在本发明实施例中,需检测和跟踪的直线轨迹为两条车道线,车道线为两条平行的黄色直线,宽度为12cm,车道线内侧边缘之间的距离为60cm;经测量每条车道线在图像水平方向上的宽度为25个像素,大于本发明实施例设定的阈值w=15个像素,因此该直线轨迹属于多条相互平行的粗直线轨迹。Step 1-3: Use a surveillance camera to capture an image of a straight line trajectory, as shown in Figure 2. In the embodiment of the present invention, the straight line trajectory to be detected and tracked is two lane lines, which are two parallel yellow straight lines with a width of 12 cm and a distance of 60 cm between the inner edges of the lane lines; the measured width of each lane line in the horizontal direction of the image is 25 pixels, which is greater than the threshold value w=15 pixels set in the embodiment of the present invention, so the straight line trajectory belongs to a plurality of parallel thick straight line trajectories.
本发明所涉及方法的流程图如图3所示,包括以下步骤:The flow chart of the method involved in the present invention is shown in FIG3 , and comprises the following steps:
步骤2:对步骤1拍摄到的直线轨迹图像进行增强,并提取梯度特征信息,根据梯度幅值信息,识别每条直线轨迹边缘得到边缘图;Step 2: Enhance the straight line trajectory image captured in step 1, extract gradient feature information, and identify the edge of each straight line trajectory according to the gradient amplitude information to obtain an edge map;
步骤2-1:逐一将视觉图像采集装置拍摄的直线轨迹图像作为输入,并使用固定尺寸矩形框,在输入图像中划分出直线轨迹所在的感兴趣区域;Step 2-1: taking the straight line trajectory images captured by the visual image acquisition device as input one by one, and using a fixed-size rectangular frame to divide the region of interest where the straight line trajectory is located in the input image;
步骤2-2:对感兴趣区域内的图像进行灰度化处理,本实施例所采用的灰度化处理方式如下:Step 2-2: grayscale the image in the region of interest. The grayscale processing method used in this embodiment is as follows:
I(x,y)=λ1R(x,y)+λ2G(x,y)+λ3B(x,y)I(x,y)=λ 1 R(x,y)+λ 2 G(x,y)+λ 3 B(x,y)
其中权重向量λ=[λ1,λ2,λ3]=[0.3,0.3,-0.3],R(x,y),G(x,y),B(x,y)分别表示坐标为(x,y)的像素对应的R,G,B颜色分量,I(x,y)表示变换后的灰度值;Wherein the weight vector λ = [λ 1 ,λ 2 ,λ 3 ] = [0.3,0.3,-0.3], R(x,y), G(x,y), B(x,y) represent the R, G, B color components corresponding to the pixel with coordinates (x,y), and I(x,y) represents the gray value after transformation;
步骤2-3:对经过灰度化处理的图像进行图像增强,本实施例采用限制对比度的自适应直方图均衡算法(CLAHE)进行图像增强处理,通过将整幅图像划分成若干个区域,对每个区域分别进行直方图均衡,再利用双线性插值的方式进行融合,能够有效地提高图像的对比度。Step 2-3: Perform image enhancement on the grayscaled image. This embodiment uses a contrast-limited adaptive histogram equalization algorithm (CLAHE) to perform image enhancement processing. By dividing the entire image into several regions, performing histogram equalization on each region separately, and then fusing them using bilinear interpolation, the contrast of the image can be effectively improved.
步骤2-4:利用Sobel算子分别提取增强后图像的水平方向和竖直方向上的梯度信息Gx和Gy:Step 2-4: Use the Sobel operator to extract the gradient information G x and G y in the horizontal and vertical directions of the enhanced image respectively:
其中*表示卷积运算,I表示经过灰度化处理和图像增强的感兴趣区域图像;Where * represents the convolution operation, and I represents the image of the region of interest after grayscale processing and image enhancement;
步骤2-5:根据下式计算每个像素的梯度幅值GM:Step 2-5: Calculate the gradient magnitude GM of each pixel according to the following formula:
GM(x,y)=|Gx(x,y)|GM(x,y)=|G x (x,y)|
其中Gx(x,y)表示坐标(x,y)处像素的梯度信息Gx;Where G x (x, y) represents the gradient information G x of the pixel at the coordinate (x, y);
步骤2-6:设置梯度幅值阈值TM,本发明实施例取TM=20,感兴趣区域图像中梯度幅值GM大于等于阈值TM的像素点为边缘像素点,得到边缘图E,如图4所示:Step 2-6: Set the gradient amplitude threshold TM . In the embodiment of the present invention, TM = 20. The pixels in the image of the region of interest whose gradient amplitude GM is greater than or equal to the threshold TM are edge pixels. The edge map E is obtained, as shown in FIG4 :
对于粗直线轨迹,根据梯度方向信息,将直线轨迹边缘分成左侧、右侧和其他三类,具体步骤如下:For the rough straight line track, the straight line track edge is divided into three categories: left side, right side and others according to the gradient direction information. The specific steps are as follows:
根据下式计算每个像素的梯度方向特征GD:The gradient direction feature GD of each pixel is calculated according to the following formula:
其中Gx(x,y)和Gy(x,y)分别表示坐标(x,y)处像素的梯度信息Gx和Gy;Where G x (x, y) and G y (x, y) represent the gradient information G x and G y of the pixel at the coordinate (x, y) respectively;
根据方向特征GD将所有的边缘图E中的像素点分成左侧右侧和其他三个集合,划分方式如下:According to the directional feature GD, all the pixels in the edge map E are divided into the left and right Right and others The three sets are divided as follows:
本发明实施例中取属于其他类别的边缘像素点将被忽略,即如果则E(x,y)=0;属于左侧类别的像素点保存为左边缘图EL,即如果则EL(x,y)=255;属于右侧类别的像素点保存为右边缘图ER,即如果则ER(x,y)=255;In the embodiment of the present invention, Other The edge pixels of the category will be ignored, that is, if Then E(x,y)=0; belongs to the left side The pixel points of the category are saved as the left edge map EL , that is, if Then E L (x, y) = 255; belongs to the right side The pixel points of the category are saved as the right edge map ER , that is, if Then ER (x, y) = 255;
对于多条相互平行的粗直线轨迹,将直线轨迹沿图像水平方向从左向右依次划分为T条直线轨迹,T表示直线轨迹数量,本发明实施例中T=2,并将边缘图E按照边缘所属的直线轨迹和边缘类别另存为4幅边缘图 For multiple parallel thick straight line tracks, the straight line tracks are divided into T straight line tracks from left to right along the horizontal direction of the image, where T represents the number of straight line tracks. In the embodiment of the present invention, T=2, and the edge map E is saved as 4 edge maps according to the straight line track to which the edge belongs and the edge category.
按照相对位置关系,将相邻的两个直线轨迹的同类别边缘划分为一对或划分方式如下:According to the relative position relationship, the edges of the same category of two adjacent straight line trajectories are divided into a pair or The division is as follows:
步骤3:对步骤2得到的边缘图采用逆透视变换方法消除图像拍摄过程中产生的透视效应,得到变换后的边缘图;Step 3: Using the inverse perspective transformation method on the edge map obtained in step 2 to eliminate the perspective effect generated during the image shooting process, and obtain a transformed edge map;
步骤3-1:对步骤2得到的边缘图逆透视变换过程如下:Step 3-1: The process of inverse perspective transformation of the edge image obtained in step 2 is as follows:
其中A3×3表示逆透视变换矩阵,[u v 1]T表示原始图像中像素点的坐标,称之为源点坐标,[x y 1]T表示变换后的像素点坐标,称之为目标点坐标,需得到至少三组不共线的相对应的源点和目标点坐标,即可求解逆透视变换矩阵A3×3;Where A 3×3 represents the inverse perspective transformation matrix, [uv 1] T represents the coordinates of the pixels in the original image, which are called the source point coordinates, and [xy 1] T represents the coordinates of the pixels after transformation, which are called the target point coordinates. At least three sets of corresponding source and target point coordinates that are not collinear need to be obtained to solve the inverse perspective transformation matrix A 3×3 ;
步骤3-2:在初始化时,对于多条相互平行的粗直线轨迹,通过手动选择的方式在图像中选取左起第一条直线轨迹的左侧边缘和最后一条直线轨迹的右侧边缘与感兴趣区域上下边界的交点,作为四个源点;Step 3-2: During initialization, for multiple parallel thick straight line tracks, manually select the intersection points of the left edge of the first straight line track from the left and the right edge of the last straight line track with the upper and lower boundaries of the region of interest in the image as four source points;
从左下角的源点开始按逆时针顺序分别命名为LB、LU、RU和RB,其坐标分别为[uLBvLB 1]T、[uLU vLU 1]T、[uRU vRU 1]T和[uRB vRB 1]T;Starting from the source point in the lower left corner, they are named LB, LU, RU, and RB in counterclockwise order, and their coordinates are [u LB v LB 1] T , [u LU v LU 1] T , [u RU v RU 1] T , and [u RB v RB 1] T ;
步骤3-3:四个源点对应的目标点坐标分别为Step 3-3: The coordinates of the target points corresponding to the four source points are
步骤3-4:根据步骤3-2和3-3得到的源点与目标点坐标,求得步骤3-1中所述的逆透视变换矩阵A3×3,将步骤S2所得边缘图中所有的像素点的齐次坐标与A3×3相乘得到变换后的边缘图;以第二条直线轨迹的右侧边缘为例,变换后的边缘图如图5所示,图中横纵坐标轴分别表示图像的横纵坐标;Step 3-4: According to the coordinates of the source point and the target point obtained in steps 3-2 and 3-3, the inverse perspective transformation matrix A 3×3 described in step 3-1 is obtained, and the homogeneous coordinates of all the pixel points in the edge map obtained in step S2 are multiplied by A 3×3 to obtain the transformed edge map; taking the right edge of the second straight line trajectory as an example, the transformed edge map is shown in FIG5 , in which the horizontal and vertical axes represent the horizontal and vertical coordinates of the image respectively;
步骤3-5:对于包含多条相互平行的直线轨迹的图像,当前帧的源点坐标据前一帧图像的直线轨迹检测结果进行自动选择,进而实现逆透视变换矩阵的自适应调整;如图6所示,受透视效应的影响,原本保持平行关系的直线轨迹在图像中相交于消失点(图中的五角星标识);利用前一帧图像中检测到的直线轨迹边缘所在的直线方程,通过最小二乘法计算得到其交点,即消失点坐标;然后对于粗直线轨迹,分别连接消失点与左起第一条直线轨迹的左侧边缘和最后一条直线轨迹的右侧边缘的下侧端点;两条连接线与感兴趣区域(图中的矩形框)上下边界的交点(图中十字标识),即为当前帧图像的一组源点。Step 3-5: For an image containing multiple parallel straight line tracks, the source point coordinates of the current frame are automatically selected according to the straight line track detection result of the previous frame image, thereby realizing adaptive adjustment of the inverse perspective transformation matrix; as shown in FIG6 , affected by the perspective effect, the straight line tracks that originally maintained a parallel relationship intersect at the vanishing point in the image (the five-pointed star mark in the figure); using the straight line equation where the edge of the straight line track detected in the previous frame image is located, the intersection point, i.e., the vanishing point coordinates, is calculated by the least squares method; then for the rough straight line track, the vanishing point is connected to the left edge of the first straight line track from the left and the lower end point of the right edge of the last straight line track respectively; the intersection point (the cross mark in the figure) of the two connecting lines and the upper and lower boundaries of the region of interest (the rectangular box in the figure) is a set of source points of the current frame image.
步骤4:采用滑动窗口法对步骤S3得到的变换后的逐条直线轨迹边缘进行检测,并筛选出符合要求的直线轨迹边缘,最终拟合得到符合要求的直线轨迹边缘所在直线的方程;Step 4: Use the sliding window method to detect the edges of the transformed straight line tracks obtained in step S3 one by one, and select the straight line track edges that meet the requirements, and finally fit the equation of the straight line where the straight line track edges that meet the requirements are located;
步骤4-1:将逆透视变换后的边缘图分别向图像的横轴做投影,得到对应的统计直方图;以第二条直线轨迹的右侧边缘为例,统计直方图如图7所示,图中横坐标轴表示图像的横坐标,纵坐标轴表示边缘像素点数量的统计值,单位:个;Step 4-1: Transform the edge map after inverse perspective Project the images onto the horizontal axis to obtain the corresponding statistical histograms. Taking the right edge of the second straight line track as an example, the statistical histogram is shown in FIG7 , where the horizontal axis represents the horizontal axis of the image, and the vertical axis represents the statistical value of the number of edge pixels, in units of pieces.
步骤4-2:通过一维卷积的方式对统计直方图做均值滤波,消除数据中的噪声,并且只保留统计值超过统计结果最大值的TE%的点,本发明实施例中取TE%=25%,以第二条直线轨迹的右侧边缘为例,滤波后的直方图如图8所示,图中横坐标轴表示图像的横坐标,纵坐标轴表示边缘像素点数量的统计值,单位:个;Step 4-2: Perform mean filtering on the statistical histogram by means of one-dimensional convolution to eliminate the noise in the data, and only retain the points whose statistical values exceed TE % of the maximum value of the statistical result. In the embodiment of the present invention, TE %=25%. Taking the right edge of the second straight line track as an example, the filtered histogram is shown in FIG8 , where the horizontal axis represents the horizontal axis of the image, and the vertical axis represents the statistical value of the number of edge pixel points, in units of pieces;
步骤4-3:经过滤波处理后,每幅直方图中的峰值点对应的横坐标表示当前边缘的初始基点坐标;Step 4-3: After filtering, the horizontal coordinate corresponding to the peak point in each histogram represents the initial base point coordinate of the current edge;
步骤4-4:以初始基点为起始点,采用固定的窗口尺寸h×w和步长s沿图像纵轴方向进行搜索,其中h是窗口的高度,w是窗口的宽度,在数值上等于粗直线与细直线划分的宽度阈值。本发明实施例中,w=15(像素),窗口的高度h与步长s相等,其计算方法如下Step 4-4: Starting from the initial base point, search along the vertical axis of the image using a fixed window size h×w and step length s, where h is the height of the window and w is the width of the window, which is numerically equal to the width threshold dividing the thick straight line and the thin straight line. In the embodiment of the present invention, w=15 (pixels), the height of the window h is equal to the step length s, and the calculation method is as follows
其中H表示感兴趣区域的高度,N表示预设搜索次数,在本发明实施例中取H=344(像素),N=10;Wherein H represents the height of the region of interest, N represents the preset number of searches, and in the embodiment of the present invention, H=344 (pixels), N=10;
如果窗口中的边缘像素点数量超过设定阈值TP,则认定该窗口为有效窗口,其内部的边缘像素点被看作有效边缘像素点,计算窗口内部所有边缘像素点横坐标的平均值,以此更新搜索窗口的基点坐标。有效像素点数量阈值TP可根据直线轨迹检测结果与搜索次数进行自适应调整:If the number of edge pixels in the window exceeds the set threshold TP , the window is considered a valid window, and the edge pixels inside it are regarded as valid edge pixels. The average value of the horizontal coordinates of all edge pixels inside the window is calculated to update the base point coordinates of the search window. The threshold TP for the number of valid pixels can be adaptively adjusted according to the straight line trajectory detection results and the number of searches:
其中in
其中,表示统计直方图中坐标i对应的统计值,x表示初始基点的横坐标值;in, represents the statistical value corresponding to the coordinate i in the statistical histogram, and x represents the horizontal coordinate value of the initial base point;
步骤4-5:如果窗口中的边缘像素点数量不超过设定阈值TP,则认定该窗口为无效窗口,保持基点坐标不变,继续沿纵轴方向搜索,直至达到预设的搜索次数N,如图9所示,图中横纵坐标轴分别表示图像的横纵坐标;Step 4-5: If the number of edge pixels in the window does not exceed the set threshold value TP , the window is deemed to be an invalid window, the base point coordinates are kept unchanged, and the search continues along the vertical axis until the preset search times N are reached, as shown in FIG9 , where the horizontal and vertical axes represent the horizontal and vertical coordinates of the image respectively;
步骤4-6:对于每条直线轨迹边缘,如果其对应的有效窗口数目大于阈值TW,本发明实施例取TW=4,则认定该直线轨迹边缘为候选边缘;对于多条相互平行的粗直线轨迹,需要对直线轨迹边缘进行配对后,结合同对候选边缘之间的距离约束,筛选出符合要求的候选边缘,具体包括步骤4-7:Step 4-6: For each straight track edge, if the number of valid windows corresponding to it is greater than the threshold value T W , in the embodiment of the present invention, T W = 4, then the straight track edge is identified as a candidate edge; for multiple parallel thick straight track edges, it is necessary to pair the straight track edges, and combine the distance constraints between the same pair of candidate edges to screen out the candidate edges that meet the requirements, which specifically includes step 4-7:
步骤4-7:步骤4-6所述的候选边缘可能存在错误检测的结果,若多条直线轨迹之间的距离是固定的,则可以通过各个候选边缘之间的距离约束,筛除错误检测的候选边缘。四幅边缘图中所有的候选边缘的初始基点坐标构成的集合分别则候选边缘的初始基点坐标必须满足以下条件:Step 4-7: The candidate edges described in step 4-6 may have the result of false detection. If the distances between multiple straight line trajectories are fixed, the falsely detected candidate edges can be screened out by using the distance constraints between the candidate edges. The sets of initial base point coordinates of all candidate edges in the four edge images are respectively Then the initial base point coordinates of the candidate edge must meet the following conditions:
其中和分别为第一对直线轨迹左右侧边缘之间的固定距离,T1 L和T1 R分别为第一对直线轨迹左右侧边缘之间距离偏差阈值;本发明实施例取对于满足上述条件的初始基点坐标集合有效的初始基点坐标为in and are respectively the fixed distances between the left and right edges of the first pair of straight track, T 1 L and T 1 R are respectively the distance deviation thresholds between the left and right edges of the first pair of straight track; For the initial base point coordinate set that meets the above conditions The valid initial base point coordinates are
对应的候选边缘为符合要求的直线轨迹边缘; The corresponding candidate edge is a straight line trajectory edge that meets the requirements;
步骤4-8:对于每条符合要求的直线轨迹边缘,对其所包含的有效边缘像素点进行直线拟合,得到该边缘对应的直线方程。Step 4-8: For each straight line trajectory edge that meets the requirements, perform straight line fitting on the valid edge pixels contained therein to obtain the straight line equation corresponding to the edge.
步骤5:采用卡尔曼滤波器对连续拍摄的多幅图像中检测得到的每一条符合要求的直线轨迹进行跟踪,并根据直线轨迹边缘的检测置信度,自适应地调整卡尔曼增益。Step 5: Use the Kalman filter to track each straight line trajectory that meets the requirements detected in multiple images taken continuously, and adaptively adjust the Kalman gain according to the detection confidence of the edge of the straight line trajectory.
步骤5-1:步骤4-6所述的有效窗口数目反映了当前候选边缘检测的可靠程度,有效窗口数量越多,则表示该候选边缘检测置信度越高。对于粗直线轨迹,检测置信度的计算方法为:Step 5-1: The number of valid windows described in step 4-6 reflects the reliability of the current candidate edge detection. The more valid windows there are, the higher the confidence of the candidate edge detection. For a rough straight line trajectory, the calculation method of the detection confidence is:
其中和分别表示第t条符合要求的直线轨迹左右边缘对应的检测置信度,和分别表示第t条符合要求的直线轨迹左右边缘的有效窗口的数量,N表示预设搜索次数,β表示修正系数,本发明实施例取β=100;in and They represent the detection confidence corresponding to the left and right edges of the tth straight line trajectory that meets the requirements, and represents the number of valid windows on the left and right edges of the t-th straight line track that meets the requirements, N represents the preset number of searches, β represents the correction coefficient, and β=100 is taken in the embodiment of the present invention;
步骤5-2:对于粗直线轨迹,每条符合要求的直线轨迹的左右边缘所在直线与感兴趣区域上下界形成四个交点,其对应的置信度分别为和且 则根据置信度构建修正系数矩阵Step 5-2: For the rough straight line trajectory, the left and right edges of each straight line trajectory that meets the requirements form four intersection points with the upper and lower boundaries of the region of interest, and their corresponding confidence levels are and and Then construct the correction coefficient matrix according to the confidence level
步骤5-3:计算修正后的测量误差协方差矩阵R'Step 5-3: Calculate the corrected measurement error covariance matrix R'
R'=diag(Ck)RR' = diag(C k )R
其中diag(·)表示对角化操作,R表示初始测量误差协方差矩阵,R=sR×U,sR表示放缩系数,本发明实施例取sR=500,U表示单位阵;Wherein diag(·) represents a diagonalization operation, R represents the initial measurement error covariance matrix, R=s R ×U, s R represents a scaling factor, and in the embodiment of the present invention, s R =500 is taken, and U represents a unit matrix;
步骤5-4:修正后的卡尔曼增益为Step 5-4: The corrected Kalman gain is
Kk=PkMT(MPkMT+R')-1 K k =P k M T (MP k M T +R') -1
其中Pk表示第k帧图像的先验估计误差的协方差矩阵,初始化为P0=U,表示测量矩阵,其中第i行,第j列的元素Mij如下Where P k represents the covariance matrix of the prior estimation error of the k-th frame image, which is initialized to P 0 = U, Represents the measurement matrix, where the element Mij in the i-th row and j-th column is as follows
步骤5-5:步骤5-4所述先验估计误差的协方差矩阵Pk的计算方法为Step 5-5: The calculation method of the covariance matrix P k of the prior estimation error in step 5-4 is:
其中Q表示过程噪声的协方差矩阵,Q=sQ×U,sQ表示放缩系数,本发明实施例取sQ=0.1。A表示转移状态矩阵Where Q represents the covariance matrix of process noise, Q = s Q × U, s Q represents the scaling factor, and in the embodiment of the present invention, s Q = 0.1. A represents the transfer state matrix
表示第k-1帧的后验估计误差的协方差矩阵,其更新过程如下 Represents the covariance matrix of the posterior estimation error of the k-1th frame, and its update process is as follows
其中U表示单位矩阵;Where U represents the identity matrix;
步骤5-6:对于粗直线轨迹,步骤4-8所得符合要求的第t条直线轨迹左右边缘所在的直线与感兴趣区域的上下边界形成4个交点,交点的横坐标分别为和构成第k帧测量值矩阵 Step 5-6: For the rough straight line trajectory, the straight lines where the left and right edges of the tth straight line trajectory that meets the requirements obtained in step 4-8 and the upper and lower boundaries of the region of interest form four intersection points, and the horizontal coordinates of the intersection points are and Construct the k-th frame measurement matrix
第K帧测量值矩阵Zk计算方式如下:The calculation method of the K-th frame measurement matrix Z k is as follows:
Zk=MXk;Z k =MX k ;
步骤5-7:对于粗直线轨迹,直线轨迹的宽度值将作为一个额外的约束条件用于对直线轨迹进行跟踪:其中和分别表示第t条直线轨迹左右边缘所在的直线与感兴趣区域的上下边界形成的4个交点的横坐标的估计值,是由上一帧图像的预测结果估计得到的;表示相邻两帧之间的变化量,表示相邻两帧之间的变化量,表示相邻两帧之间的变化量,表示相邻两帧之间的变化量;表示直线轨迹顶部的宽度,表示相邻两帧宽度的变化量,表示直线轨迹底部的宽度,表示相邻两帧宽度的变化量;Step 5-7: For the thick straight line track, the width value of the straight line track will be used as an additional constraint to track the straight line track: in and The estimated values of the horizontal coordinates of the four intersection points formed by the straight lines where the left and right edges of the t-th straight line trajectory are located and the upper and lower boundaries of the region of interest are estimated from the prediction results of the previous frame image; Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between Indicates the width of the top of the straight line track, Indicates the change in width between two adjacent frames. Indicates the width of the bottom of the straight line track, Indicates the change in width between two adjacent frames;
步骤5-8:第k帧状态估计值矩阵Xk计算方式如下:Step 5-8: The k-th frame state estimation matrix X k is calculated as follows:
表示第K-1帧的后验状态估计值矩阵,计算方式如下: Represents the posterior state estimate matrix of the K-1th frame, which is calculated as follows:
初始值为第一帧图像的直线轨迹边缘端点横坐标和直线轨迹宽度的检测结果;Initial Value is the detection result of the horizontal coordinates of the edge endpoints of the straight line track and the width of the straight line track of the first frame image;
步骤5-9:直线轨迹跟踪的最终输出结果为计算方式如下:Step 5-9: The final output of the straight line trajectory tracking is The calculation is as follows:
发明实施例2:Invention Example 2:
如图10所示,本发明的基于视觉的直线轨迹检测与跟踪方法,基于的硬件基础为:视觉图像采集设备1安装在移动机器人平台2的横梁上,视觉图像采集设备1的光轴垂直于地面,直线轨迹3位于视觉图像采集设备1的视野中央。As shown in Figure 10, the vision-based straight line trajectory detection and tracking method of the present invention is based on the hardware foundation: the visual image acquisition device 1 is installed on the crossbeam of the mobile robot platform 2, the optical axis of the visual image acquisition device 1 is perpendicular to the ground, and the straight line trajectory 3 is located in the center of the field of view of the visual image acquisition device 1.
基于上述硬件系统,本实施例的基于视觉的直线轨迹检测与跟踪方法,包含如下步骤:Based on the above hardware system, the visual-based straight line trajectory detection and tracking method of this embodiment includes the following steps:
步骤1:视觉图像采集装置拍摄直线轨迹图像;Step 1: The visual image acquisition device captures the straight line trajectory image;
步骤1-1:所述视觉图像采集设备包括但不限于监控相机、工业相机及网络摄像机,在本发明实施例中采用的是工业相机;Step 1-1: The visual image acquisition device includes but is not limited to a surveillance camera, an industrial camera and a network camera. In the embodiment of the present invention, an industrial camera is used;
步骤1-2:将工业相机部署在移动机器人的横梁上,以保证待检测和跟踪的直线轨迹处于工业相机的视野范围内,工业相机的光轴垂直于地面;使用工业相机拍摄直线轨迹的图像,如图11所示。在本发明实施例中,需检测和跟踪的直线轨迹为单条焊缝,焊缝宽度为0.1-0.2mm,经测量焊缝在图像水平方向上的宽度为10个像素,小于阈值w=60(像素),因此该直线轨迹属于单条细直线轨迹。Step 1-2: Deploy an industrial camera on the crossbar of the mobile robot to ensure that the linear trajectory to be detected and tracked is within the field of view of the industrial camera, and the optical axis of the industrial camera is perpendicular to the ground; use the industrial camera to capture an image of the linear trajectory, as shown in Figure 11. In the embodiment of the present invention, the linear trajectory to be detected and tracked is a single weld seam with a weld seam width of 0.1-0.2 mm. The measured width of the weld seam in the horizontal direction of the image is 10 pixels, which is less than the threshold value w=60 (pixels), so the linear trajectory belongs to a single thin linear trajectory.
本发明所涉及方法的流程图如图3所示,包括以下步骤:The flow chart of the method involved in the present invention is shown in FIG3 , and comprises the following steps:
步骤2:对步骤S1拍摄到的直线轨迹图像进行增强,并提取梯度特征信息,根据梯度幅值信息,识别每条直线轨迹边缘得到边缘图;Step 2: Enhance the straight line track image captured in step S1, extract gradient feature information, and identify the edge of each straight line track according to the gradient amplitude information to obtain an edge map;
步骤2-1:逐一将视觉图像采集装置拍摄的直线轨迹图像作为输入,并使用固定尺寸矩形框,在输入图像中划分出直线轨迹所在的感兴趣区域;Step 2-1: taking the straight line trajectory images captured by the visual image acquisition device as input one by one, and using a fixed-size rectangular frame to divide the region of interest where the straight line trajectory is located in the input image;
步骤2-2:对感兴趣区域内的图像进行灰度化处理,本实施例所采用的灰度化处理方式如下:Step 2-2: grayscale the image in the region of interest. The grayscale processing method used in this embodiment is as follows:
I(x,y)=λ1R(x,y)+λ2G(x,y)+λ3B(x,y)I(x,y)=λ 1 R(x,y)+λ 2 G(x,y)+λ 3 B(x,y)
其中权重向量λ=[λ1,λ2,λ3]=[0.3,0.3,-0.3],R(x,y),G(x,y),B(x,y)分别表示坐标为(x,y)的像素对应的R,G,B颜色分量,I(x,y)表示变换后的灰度值;Wherein the weight vector λ = [λ 1 ,λ 2 ,λ 3 ] = [0.3,0.3,-0.3], R(x,y), G(x,y), B(x,y) represent the R, G, B color components corresponding to the pixel with coordinates (x,y), and I(x,y) represents the gray value after transformation;
步骤2-3:对经过灰度化处理的图像进行图像增强,本实施例采用限制对比度的自适应直方图均衡算法(CLAHE)进行图像增强处理,通过将整幅图像划分成若干个区域,对每个区域分别进行直方图均衡,再利用双线性插值的方式进行融合,能够有效地提高图像的对比度。Step 2-3: Perform image enhancement on the grayscaled image. This embodiment uses a contrast-limited adaptive histogram equalization algorithm (CLAHE) to perform image enhancement processing. By dividing the entire image into several regions, performing histogram equalization on each region separately, and then fusing them using bilinear interpolation, the contrast of the image can be effectively improved.
利用Sobel算子分别提取增强后图像的水平方向和竖直方向上的梯度信息Gx和Gy:The Sobel operator is used to extract the gradient information G x and G y in the horizontal and vertical directions of the enhanced image respectively:
其中*表示卷积运算,I表示经过灰度化处理和图像增强的感兴趣区域图像;Where * represents the convolution operation, and I represents the image of the region of interest after grayscale processing and image enhancement;
步骤2-5:根据下式计算每个像素的梯度幅值GM:Step 2-5: Calculate the gradient magnitude GM of each pixel according to the following formula:
GM(x,y)=|Gx(x,y)|GM(x,y)=|G x (x,y)|
其中Gx(x,y)表示坐标(x,y)处像素的梯度信息Gx;Where G x (x, y) represents the gradient information G x of the pixel at the coordinate (x, y);
步骤2-6:设置梯度幅值阈值TM,感兴趣区域图像中梯度幅值GM大于等于阈值TM的像素点为边缘像素点,得到边缘图E:Step 2-6: Set the gradient amplitude threshold TM . The pixels in the region of interest image whose gradient amplitude GM is greater than or equal to the threshold TM are edge pixels, and the edge map E is obtained:
步骤3:由于相机光轴垂直于地面,焊缝所在平面与相机成像平面平行,不受透视效应影响,无需进行逆透视变换;Step 3: Since the camera optical axis is perpendicular to the ground, the plane where the weld is located is parallel to the camera imaging plane and is not affected by the perspective effect, so there is no need to perform inverse perspective transformation;
步骤4:采用滑动窗口法对步骤S3得到的变换后的逐条直线轨迹边缘进行检测,并筛选出符合要求的直线轨迹边缘,最终拟合得到符合要求的直线轨迹边缘所在直线的方程;Step 4: Use the sliding window method to detect the edges of the transformed straight line tracks obtained in step S3 one by one, and select the straight line track edges that meet the requirements, and finally fit the equation of the straight line where the straight line track edges that meet the requirements are located;
步骤4-1:将边缘图E向图像横轴方向做投影,得到对应的统计直方图;Step 4-1: Project the edge map E onto the horizontal axis of the image to obtain the corresponding statistical histogram;
步骤4-2:通过一维卷积的方式对统计直方图做均值滤波,消除数据中的噪声,并且只保留统计值超过统计结果最大值的TE%的点,本发明实施例中取TE%=25%;Step 4-2: Perform mean filtering on the statistical histogram by one-dimensional convolution to eliminate the noise in the data, and only retain the points whose statistical values exceed TE % of the maximum value of the statistical result. In the embodiment of the present invention, TE %=25%;
步骤4-3:经过滤波处理后,每幅直方图中的峰值点对应的横坐标表示当前边缘的初始基点坐标;Step 4-3: After filtering, the horizontal coordinate corresponding to the peak point in each histogram represents the initial base point coordinate of the current edge;
步骤4-4:以初始基点为起始点,采用固定的窗口尺寸h×w和步长s沿图像纵轴方向进行搜索其中h是窗口的高度,w是窗口的宽度,在数值上等于粗直线与细直线划分的宽度阈值,。本发明实施例中,搜索窗口的宽度w=60(像素),窗口的高度h与步长s相等,其计算方法如下Step 4-4: Starting from the initial base point, search along the vertical axis of the image using a fixed window size h×w and step length s, where h is the height of the window and w is the width of the window, which is numerically equal to the width threshold dividing the thick straight line and the thin straight line. In the embodiment of the present invention, the width of the search window w=60 (pixels), the height of the window h is equal to the step length s, and the calculation method is as follows
其中H表示感兴趣区域的高度,N表示预设搜索次数,在本发明实施例中取H=2592(像素),N=10;Wherein H represents the height of the region of interest, N represents the preset number of searches, and in the embodiment of the present invention, H=2592 (pixels), N=10;
如果窗口中的边缘像素点数量超过设定阈值TP,则认定该窗口为有效窗口,其内部的边缘像素点被看作有效边缘像素点。计算窗口内部所有边缘像素点横坐标的平均值,以此更新搜索窗口的基点坐标;有效像素点数量阈值TP可根据直线轨迹检测结果与搜索次数进行自适应调整:If the number of edge pixels in the window exceeds the set threshold TP , the window is considered a valid window, and the edge pixels inside it are considered valid edge pixels. The average value of the horizontal coordinates of all edge pixels inside the window is calculated to update the base point coordinates of the search window; the threshold TP of the number of valid pixels can be adaptively adjusted according to the straight line trajectory detection results and the number of searches:
其中in
其中,表示统计直方图中坐标i对应的统计值,x表示初始基点的横坐标值;in, represents the statistical value corresponding to the coordinate i in the statistical histogram, and x represents the horizontal coordinate value of the initial base point;
步骤4-5:如果窗口中的边缘像素点数量不超过设定阈值TP,则认定该窗口为无效窗口,保持基点坐标不变,继续沿纵轴方向搜索,直至达到预设的搜索次数N;Step 4-5: If the number of edge pixels in the window does not exceed the set threshold value TP , the window is deemed to be an invalid window, the base point coordinates are kept unchanged, and the search continues along the vertical axis until the preset search times N are reached;
步骤4-6:对于每条直线轨迹边缘,如果其对应的有效窗口数目大于阈值TW,本发明实施例取TW=4,则认定该直线轨迹边缘为候选直线轨迹边缘;对于单条细直线轨迹,候选边缘即为符合要求的直线轨迹边缘;Step 4-6: For each straight track edge, if the number of valid windows corresponding to it is greater than the threshold value T W , in the embodiment of the present invention, T W = 4, then the straight track edge is identified as a candidate straight track edge; for a single thin straight track, the candidate edge is a straight track edge that meets the requirements;
步骤4-8:对于每条符合要求的直线轨迹边缘,对其所包含的有效边缘像素点进行直线拟合,得到该边缘对应的直线方程。Step 4-8: For each straight line trajectory edge that meets the requirements, perform straight line fitting on the valid edge pixels contained therein to obtain the straight line equation corresponding to the edge.
步骤5:采用卡尔曼滤波器对连续图像中的直线轨迹进行跟踪,并根据直线轨迹边缘的检测置信度,调整卡尔曼增益;Step 5: Use the Kalman filter to track the straight line trajectory in the continuous image, and adjust the Kalman gain according to the detection confidence of the edge of the straight line trajectory;
步骤5-1:步骤4-6所述的有效窗口数目反映了当前候选边缘检测的可靠程度,有效窗口数量越多,则表示该候选边缘检测置信度越高。对于细直线轨迹,检测置信度的计算方法为:Step 5-1: The number of valid windows described in step 4-6 reflects the reliability of the current candidate edge detection. The more valid windows there are, the higher the confidence of the candidate edge detection. For a thin straight line trajectory, the calculation method of the detection confidence is:
其中c1表示符合要求的直线轨迹边缘对应的检测置信度,n1表示该边缘的有效窗口的数量,N表示预设搜索次数,β表示修正系数,本发明实施例取β=100;Wherein c 1 represents the detection confidence corresponding to the edge of the straight track that meets the requirements, n 1 represents the number of valid windows of the edge, N represents the preset number of searches, β represents the correction coefficient, and in the embodiment of the present invention, β=100;
步骤5-2:对于细直线轨迹,符合要求的直线轨迹边缘所在直线与感兴趣区域上下界形成两个交点,其对应的置信度分别为和且则根据置信度构建修正系数矩阵 Step 5-2: For the thin straight line trajectory, the straight line where the edge of the straight line trajectory meets the requirements and the upper and lower boundaries of the region of interest form two intersection points, and their corresponding confidence levels are and and Then construct the correction coefficient matrix according to the confidence level
步骤5-3:计算修正后的测量误差协方差矩阵R'Step 5-3: Calculate the corrected measurement error covariance matrix R'
R'=diag(Ck)RR' = diag(C k )R
其中diag(·)表示对角化操作,R表示初始测量误差协方差矩阵,R=sR×U,sR表示放缩系数,本发明实施例取sR=500,U表示单位阵;Wherein diag(·) represents a diagonalization operation, R represents the initial measurement error covariance matrix, R=s R ×U, s R represents a scaling factor, and in the embodiment of the present invention, s R =500 is taken, and U represents a unit matrix;
步骤5-4:修正后的卡尔曼增益为Step 5-4: The corrected Kalman gain is
Kk=PkMT(MPkMT+R')-1 K k =P k M T (MP k M T +R') -1
其中Pk表示第k帧图像的先验估计误差的协方差矩阵,初始化为P0=U,表示测量矩阵Where Pk represents the covariance matrix of the prior estimation error of the k-th frame image, which is initialized to P0 = U. Represents the measurement matrix
步骤5-5:步骤5-4所述先验估计误差的协方差矩阵Pk的计算方法为Step 5-5: The calculation method of the covariance matrix P k of the prior estimation error in step 5-4 is:
其中Q表示过程噪声的协方差矩阵,Q=sQ×U,sQ表示放缩系数,本发明实施例取sQ=0.1。A表示转移状态矩阵Where Q represents the covariance matrix of process noise, Q = s Q × U, s Q represents the scaling factor, and in the embodiment of the present invention, s Q = 0.1. A represents the transfer state matrix
表示第k-1帧的后验估计误差的协方差矩阵,其更新过程如下 Represents the covariance matrix of the posterior estimation error of the k-1th frame, and its update process is as follows
其中U表示单位矩阵;Where U represents the identity matrix;
步骤5-6:对于细直线轨迹,步骤4-8所得符合要求的直线轨迹边缘所在的直线与感兴趣区域的上下边界形成2个交点,交点的横坐标分别为和构成第k帧测量值矩阵第K帧测量值矩阵Zk计算方式如下:Step 5-6: For the thin straight line trajectory, the straight line where the edge of the straight line trajectory that meets the requirements obtained in step 4-8 is located forms two intersection points with the upper and lower boundaries of the area of interest. The horizontal coordinates of the intersection points are and Construct the k-th frame measurement matrix The calculation method of the K-th frame measurement matrix Z k is as follows:
Zk=MXk Z k =MX k
其中,Xk表示第k帧状态估计值矩阵;Where Xk represents the state estimation matrix of the kth frame;
步骤5-7:对于细直线轨迹:其中和分别表示直线轨迹边缘所在的直线与感兴趣区域的上下边界形成的2个交点的横坐标的估计值,是由上一帧图像的预测结果估计得到的;表示相邻两帧之间的变化量,表示相邻两帧之间的变化量;Steps 5-7: For thin straight track: in and The estimated values of the horizontal coordinates of the two intersection points formed by the straight line where the edge of the straight track is located and the upper and lower boundaries of the region of interest are estimated from the prediction result of the previous frame image; Indicates two adjacent frames The amount of change between Indicates two adjacent frames The amount of change between
步骤5-8:第k帧状态估计值矩阵Xk计算方式如下:Step 5-8: The k-th frame state estimation matrix X k is calculated as follows:
其中表示第k-1帧的后验状态估计值矩阵,计算方式如下:in Represents the posterior state estimate matrix of the k-1th frame, which is calculated as follows:
对于细直线轨迹,初始值为第一帧图像的直线轨迹边缘端点横坐标的检测结果;For thin straight line trajectories, the initial value is the detection result of the horizontal coordinates of the edge endpoints of the straight line track of the first frame image;
步骤5-9:直线轨迹跟踪的最终输出结果为计算方式如下:Step 5-9: The final output of the straight line trajectory tracking is The calculation is as follows:
最后应当说明的是:以上实施例仅用于说明本申请的技术方案而非对其保护范围的限制,尽管参照上述实施例对本申请进行了详细的说明,所属领域的普通技术人员应当理解:本领域技术人员阅读本申请后依然可对申请的具体实施方式进行种种变更、修改或者等同替换,但这些变更、修改或者等同替换,均在申请待批的权利要求保护范围之内。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application rather than to limit its protection scope. Although the present application has been described in detail with reference to the above embodiments, ordinary technicians in the relevant field should understand that after reading the present application, those skilled in the art can still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the protection scope of the claims to be approved.
Claims (7)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310669655.7A CN116681721B (en) | 2023-06-07 | 2023-06-07 | Linear track detection and tracking method based on vision |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310669655.7A CN116681721B (en) | 2023-06-07 | 2023-06-07 | Linear track detection and tracking method based on vision |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN116681721A CN116681721A (en) | 2023-09-01 |
| CN116681721B true CN116681721B (en) | 2023-12-29 |
Family
ID=87783265
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310669655.7A Active CN116681721B (en) | 2023-06-07 | 2023-06-07 | Linear track detection and tracking method based on vision |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116681721B (en) |
Families Citing this family (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN117274205B (en) * | 2023-09-27 | 2024-08-02 | 深圳市六六六国际旅行社有限公司 | Quadrilateral detection method based on novel data annotation and data enhancement |
Citations (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103839264A (en) * | 2014-02-25 | 2014-06-04 | 中国科学院自动化研究所 | Detection method of lane line |
| CN104318258A (en) * | 2014-09-29 | 2015-01-28 | 南京邮电大学 | Time domain fuzzy and kalman filter-based lane detection method |
| CN104408460A (en) * | 2014-09-17 | 2015-03-11 | 电子科技大学 | A lane line detecting and tracking and detecting method |
| WO2017096759A1 (en) * | 2015-12-07 | 2017-06-15 | 腾讯科技(深圳)有限公司 | Method, device and system for detecting information card in image |
| CN107180228A (en) * | 2017-05-02 | 2017-09-19 | 开易(北京)科技有限公司 | A kind of grad enhancement conversion method and system for lane detection |
| CN107679520A (en) * | 2017-10-30 | 2018-02-09 | 湖南大学 | A kind of lane line visible detection method suitable for complex condition |
| CN111626180A (en) * | 2020-05-22 | 2020-09-04 | 清华大学 | Lane line detection method and device based on polarization imaging |
| CN111738071A (en) * | 2020-05-15 | 2020-10-02 | 南京航空航天大学 | An Inverse Perspective Transformation Method Based on Motion Change of Monocular Camera |
| CN112270690A (en) * | 2020-10-12 | 2021-01-26 | 淮阴工学院 | Self-adaptive night lane line detection method based on improved CLAHE and sliding window search |
| CN112884816A (en) * | 2021-03-23 | 2021-06-01 | 武汉理工大学 | Vehicle feature deep learning recognition track tracking method based on image system |
| CN113269098A (en) * | 2021-05-27 | 2021-08-17 | 中国人民解放军军事科学院国防科技创新研究院 | Multi-target tracking positioning and motion state estimation method based on unmanned aerial vehicle |
| CN114219842A (en) * | 2021-12-14 | 2022-03-22 | 东南大学 | Visual recognition, ranging and positioning methods in port container automatic loading and unloading operations |
| CN116092035A (en) * | 2023-01-13 | 2023-05-09 | 一汽解放汽车有限公司 | Lane line detection method, lane line detection device, computer equipment and storage medium |
Family Cites Families (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP6334735B2 (en) * | 2014-05-06 | 2018-05-30 | ナント・ホールデイングス・アイ・ピー・エル・エル・シー | Image feature detection using edge vectors |
-
2023
- 2023-06-07 CN CN202310669655.7A patent/CN116681721B/en active Active
Patent Citations (13)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN103839264A (en) * | 2014-02-25 | 2014-06-04 | 中国科学院自动化研究所 | Detection method of lane line |
| CN104408460A (en) * | 2014-09-17 | 2015-03-11 | 电子科技大学 | A lane line detecting and tracking and detecting method |
| CN104318258A (en) * | 2014-09-29 | 2015-01-28 | 南京邮电大学 | Time domain fuzzy and kalman filter-based lane detection method |
| WO2017096759A1 (en) * | 2015-12-07 | 2017-06-15 | 腾讯科技(深圳)有限公司 | Method, device and system for detecting information card in image |
| CN107180228A (en) * | 2017-05-02 | 2017-09-19 | 开易(北京)科技有限公司 | A kind of grad enhancement conversion method and system for lane detection |
| CN107679520A (en) * | 2017-10-30 | 2018-02-09 | 湖南大学 | A kind of lane line visible detection method suitable for complex condition |
| CN111738071A (en) * | 2020-05-15 | 2020-10-02 | 南京航空航天大学 | An Inverse Perspective Transformation Method Based on Motion Change of Monocular Camera |
| CN111626180A (en) * | 2020-05-22 | 2020-09-04 | 清华大学 | Lane line detection method and device based on polarization imaging |
| CN112270690A (en) * | 2020-10-12 | 2021-01-26 | 淮阴工学院 | Self-adaptive night lane line detection method based on improved CLAHE and sliding window search |
| CN112884816A (en) * | 2021-03-23 | 2021-06-01 | 武汉理工大学 | Vehicle feature deep learning recognition track tracking method based on image system |
| CN113269098A (en) * | 2021-05-27 | 2021-08-17 | 中国人民解放军军事科学院国防科技创新研究院 | Multi-target tracking positioning and motion state estimation method based on unmanned aerial vehicle |
| CN114219842A (en) * | 2021-12-14 | 2022-03-22 | 东南大学 | Visual recognition, ranging and positioning methods in port container automatic loading and unloading operations |
| CN116092035A (en) * | 2023-01-13 | 2023-05-09 | 一汽解放汽车有限公司 | Lane line detection method, lane line detection device, computer equipment and storage medium |
Non-Patent Citations (4)
| Title |
|---|
| Improved Lane Line Detection Algorithm Based on Hough Transform;Fang Zheng等;Applied Problems;第28卷;254–260 * |
| Inverse perspective mapping and optic flow: A calibration method and a quantitative analysis;Sovira Tan等;Image and Vision Computing;第24卷(第2期);153-165 * |
| 基于结构化道路的车道线检测方法研究;赵峰;中国优秀硕士学位论文全文数据库 工程科技Ⅱ辑;C035-52 * |
| 融合形态学与特征点检测的建筑物自动三维重建关键技术研究;谢雨宁;中国优秀硕士学位论文全文数据库 工程科技Ⅱ辑;C038-400 * |
Also Published As
| Publication number | Publication date |
|---|---|
| CN116681721A (en) | 2023-09-01 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN104134209B (en) | A kind of feature extracting and matching method and system in vision guided navigation | |
| Kluge | Extracting road curvature and orientation from image edge points without perceptual grouping into features | |
| Kong et al. | General road detection from a single image | |
| Zhou et al. | Efficient road detection and tracking for unmanned aerial vehicle | |
| CN104408460B (en) | A kind of lane detection and tracking detection method | |
| CN112381890B (en) | RGB-D vision SLAM method based on dotted line characteristics | |
| CN112201078B (en) | Automatic parking space detection method based on graph neural network | |
| Steger | Subpixel-precise extraction of lines and edges | |
| CN110084830B (en) | Video moving object detection and tracking method | |
| CN110796010A (en) | Video image stabilization method combining optical flow method and Kalman filtering | |
| CN109785291A (en) | A kind of lane line self-adapting detecting method | |
| CN107170011B (en) | A robot visual tracking method and system | |
| CN102103753A (en) | Method and terminal for detecting and tracking moving object using real-time camera motion | |
| CN110717934B (en) | A STRCF-Based Anti-Occlusion Target Tracking Method | |
| CN106874884A (en) | Human body recognition methods again based on position segmentation | |
| CN114241438A (en) | A Fast and Accurate Recognition Method of Traffic Signals Based on Prior Information | |
| CN101650829B (en) | Method for tracing covariance matrix based on grayscale restraint | |
| CN108074251A (en) | Mobile Robotics Navigation control method based on monocular vision | |
| CN110119670A (en) | A kind of vision navigation method based on Harris Corner Detection | |
| CN116681721B (en) | Linear track detection and tracking method based on vision | |
| Feng et al. | Robust accurate lane detection and tracking for automated rubber-tired gantries in a container terminal | |
| CN111241911A (en) | An Adaptive Lane Line Detection Method | |
| Tu et al. | An efficient crop row detection method for agriculture robots | |
| Gupta et al. | Robust lane detection using multiple features | |
| CN117058018A (en) | Method for repairing suspended impurity vision shielding area facing underwater structure detection |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |