A method for detecting a rectangular frame of a laser line region
By extracting rows of laser line images at equal intervals along the column direction and calculating the pixel values around the image, threshold segmentation and rectangular box extraction are performed, solving the problems of large computational load and external interference in the existing technology, and achieving efficient and accurate laser line detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHENGDU XIONGGU JIASHI ELECTRICAL
- Filing Date
- 2026-03-13
- Publication Date
- 2026-05-19
AI Technical Summary
Existing technologies suffer from high computational complexity, low processing efficiency, and susceptibility to external interference during laser line contour extraction, leading to unstable detection results.
By extracting rows of laser line images at equal intervals along the column direction, calculating the average pixel value around the image, threshold segmentation and rectangular box extraction are performed to reduce the computational load of irrelevant areas and suppress external interference.
It improves the accuracy and processing efficiency of laser line contour extraction, reduces the influence of external interference, and enhances the stability of detection results.
Smart Images

Figure CN121837280B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image detection, and more specifically, to a method for detecting rectangular boxes of laser line regions. Background Technology
[0002] Laser line vision inspection technology has been widely used in welding tracking, structured light measurement, and industrial inspection. By processing laser line images and extracting laser line contour information, it is possible to obtain the spatial shape or position information of target objects, which is an important foundation for realizing automated control and measurement.
[0003] In existing technologies, laser line contour extraction typically involves pixel-level analysis of the entire image, using methods such as grayscale thresholding, centerline extraction, edge detection, or sub-pixel localization to calculate the features of the laser line. Given that the laser line usually occupies a small area in an image, these methods often require a pixel-by-pixel traversal of the entire image to determine the position and distribution of the laser line's center pixel. This results in high computational complexity and low processing efficiency. This problem can easily become a bottleneck for system performance, especially in high-resolution images or real-time processing scenarios.
[0004] Furthermore, in practical industrial applications, laser line images are often affected by interference factors such as splashes, reflections, arcing, or environmental noise. When traversing and processing the entire image, interference information unrelated to the laser line is easily introduced into the contour calculation process. This not only increases the amount of unnecessary computation but may also adversely affect the accurate extraction of the laser line contour, reducing the stability and reliability of the detection results.
[0005] Therefore, existing technologies generally suffer from problems such as excessively large computational range, low processing efficiency, and susceptibility to interference from non-laser regions during laser line contour extraction. Summary of the Invention
[0006] The purpose of this invention is to provide a method for detecting the rectangular frame of a laser line region, which ensures the accuracy of laser line contour extraction, reduces the amount of computation in irrelevant areas, improves processing efficiency, and suppresses the influence of external interference.
[0007] To achieve the objective of this invention, the technical solution adopted is as follows: a method for detecting a rectangular frame of a laser line region, comprising the following steps:
[0008] Step 1: Acquire the laser line image;
[0009] Step 2: Extract rows of the laser line image at equal intervals along the column direction to form a thumbnail;
[0010] Step 3: Calculate the average pixel value around the laser line image and calculate the image segmentation threshold;
[0011] Step 4: Use the image segmentation threshold calculated in Step 3 to perform threshold segmentation on the thumbnail from Step 2 to obtain a binary image;
[0012] Step 5: Traverse the binary image row by row and calculate the length of the continuous white region in each row. Set the pixel value of the continuous white region whose length exceeds the preset region length to 0.
[0013] Step 6: Sum the columns of the binary image processed in Step 5 to obtain a one-dimensional vector;
[0014] Step 7: Traverse the one-dimensional vector obtained in Step 6, find the first position greater than the preset vector segmentation threshold and the last position greater than the preset vector segmentation threshold, and use these two positions as the left and right boundaries of the rectangle; at the same time, use the first row and the last row of the binary image as the upper and lower boundaries of the rectangle, thus obtaining the rectangle of the laser region.
[0015] Furthermore, the interval value in step two is a preset value, and the range of the interval value is from one-twentieth to one-fiftieth of the height of the laser line image.
[0016] Furthermore, in step three, the image segmentation threshold is 1.5 times the average value of the pixels around the laser line image.
[0017] Furthermore, the method for calculating the length of the continuous white region in each row in step five is as follows:
[0018] During the process of traversing the binary image row by row, when the current pixel value is 255 and its previous pixel value is 0, or when the current pixel is located at the beginning of the row, it is determined that a white continuous region has been detected, and the column coordinate of the pixel is recorded as the starting column of the white continuous region.
[0019] Continue traversing the binary image to the right along the row. When a pixel value of 0 is detected, or when the end of the row is reached, the white continuous region is determined to be over, and the position of the white pixel before the end is recorded as the termination column of the white continuous region.
[0020] The length of the white continuous region is calculated based on the starting and ending columns.
[0021] Furthermore, in step five, during the calculation of the length of the continuous white region in each row, when the length of the continuous white region is greater than the preset region length, the pixel value between the start point and the end point of the row is set to 0, and the scanning of subsequent pixels in the row continues until each row is scanned.
[0022] Furthermore, the preset area length is 15 pixels wide.
[0023] Furthermore, in step seven, the preset vector segmentation threshold is the sum of 3 to 5 white pixel values.
[0024] The beneficial effects of this invention are:
[0025] This invention incorporates the effects of interference factors such as splashing, reflection, arcing, or environmental noise on pixels. While ensuring the accuracy of laser line contour extraction, it reduces the computational load of irrelevant areas, improves processing efficiency, and suppresses the influence of external interference. Attached Figure Description
[0026] Figure 1 This is a schematic diagram of the process for detecting the rectangular frame of the laser line region according to the present invention. Detailed Implementation
[0027] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present invention are shown in the accompanying drawings.
[0028] It should be noted that, unless otherwise specified, the embodiments and features described in this invention can be combined with each other. The invention will now be described in detail with reference to the accompanying drawings and embodiments.
[0029] like Figure 1 As shown, the present invention provides a method for detecting a rectangular frame of a laser line region, comprising the following steps:
[0030] Step 1: Obtain the laser line image.
[0031] Step 2: Based on the preset interval value, extract rows of the image at equal intervals along the column direction of the laser line image to form a thumbnail. In this step, in order to reduce the amount of calculation while ensuring the stability of recognition, the preset interval value ranges from one-twentieth to one-fiftieth of the height of the laser line image.
[0032] Step 3: Calculate the average pixel value around the perimeter of the laser line image. This average value represents the pixel value of the black background noise, and the image segmentation threshold is calculated using this average value. Since the pixel value fluctuation of black background noise is generally small, when calculating the image segmentation threshold using the average pixel value around the perimeter of the laser line image under black background noise, 1.5 times this average value can be used as the image segmentation threshold. At the same time, since only the areas of laser, welding spatter, reflection, and arc light are generally bright in the laser line image, and these areas usually do not appear around the perimeter of the laser line image, or even if they do appear around the perimeter, they only account for a small proportion, in this case, the pixel value around the perimeter of the laser line image can be ignored after averaging.
[0033] Step 4: Use the image segmentation threshold calculated in Step 3 to perform threshold segmentation on the thumbnail in Step 2 to obtain a binary image; in the binary image, the value of white pixels is 255 and the value of black pixels is 0.
[0034] Step 5: Traverse the binary image row by row. When traversing any row of the binary image, sequentially traverse each pixel in the horizontal direction within that row. When a pixel with a value of 255 (white) is detected and its preceding pixel has a value of 0 (black), or when the current pixel is at the beginning of the row, a continuous white region is detected, and the column coordinate of this pixel is recorded as the starting column of the continuous white region. Then, continue traversing pixels to the right along the row. If the current pixel value remains 255 (white), it is considered that the current pixel is still within the continuous white region. When a pixel with a value of 0 (black) is detected, or when the end of the row is reached, the continuous white region is determined to end, and the column coordinate of the pixel before the end is recorded as the ending column of the continuous white region. Calculate the length of the continuous white region based on the starting and ending columns. When the length of the continuous white region is greater than the preset region length, set the pixel values between the starting and ending points of the row to 0, and continue scanning the subsequent pixels in the row until each row is processed. During the traversal of the binary image, the preset region length is the width of the laser stripe, specifically 15 pixels wide.
[0035] Step Six: Sum the values of the binary image processed in Step Five column by column to obtain a one-dimensional vector. Typically, the vector value corresponding to the column containing the laser line is a relatively high sum; in other columns, since Step Five eliminated the interference of black background noise, the vector values corresponding to these columns are generally very small or almost zero. At this point, by using a preset vector segmentation threshold, the location of the laser line can be easily identified. Here, the preset vector segmentation threshold is the sum of 3 to 5 white pixel values.
[0036] Step 7: Traverse the one-dimensional vector obtained in Step 6, find the first position greater than the preset vector segmentation threshold and the last position greater than the preset vector segmentation threshold, and use these two positions as the left and right boundaries of the rectangle; at the same time, use the first row and the last row of the binary image as the upper and lower boundaries of the rectangle, thus obtaining the rectangle of the laser region.
[0037] Those skilled in the art should understand that the above embodiments are merely for illustrating the present invention and are not intended to limit the scope of the invention. Those skilled in the art can make other changes or modifications based on the above disclosure, and these changes or modifications still fall within the scope of the present invention.
Claims
1. A method for detecting a rectangular frame of a laser line region, characterized in that, Includes the following steps: Step 1: Acquire the laser line image; Step 2: Extract rows of the laser line image at equal intervals along the column direction to form a thumbnail; Step 3: Calculate the average pixel value around the laser line image and calculate the image segmentation threshold; Step 4: Use the image segmentation threshold calculated in Step 3 to perform threshold segmentation on the thumbnail from Step 2 to obtain a binary image; Step 5: Traverse the binary image row by row and calculate the length of the continuous white region in each row. Set the pixel value of the continuous white region whose length exceeds the preset region length to 0. Step 6: Sum the columns of the binary image processed in Step 5 to obtain a one-dimensional vector; Step 7: Traverse the one-dimensional vector obtained in Step 6, find the first position greater than the preset vector segmentation threshold and the last position greater than the preset vector segmentation threshold, and use these two positions as the left and right boundaries of the rectangle; at the same time, use the first row and the last row of the binary image as the upper and lower boundaries of the rectangle, thus obtaining the rectangle of the laser region.
2. The method for detecting a rectangular frame of a laser line region according to claim 1, characterized in that, The interval value in step two is a preset value, and the range of the interval value is one-twentieth to one-fiftieth of the height of the laser line image.
3. The method for detecting a rectangular frame of a laser line region according to claim 1, characterized in that, In step three, the image segmentation threshold is 1.5 times the average value of the pixels around the laser line image.
4. The method for detecting a rectangular frame of a laser line region according to claim 1, 2, or 3, characterized in that, The method for calculating the length of the continuous white region in each row in step five is as follows: During the process of traversing the binary image row by row, when the current pixel value is 255 and its previous pixel value is 0, or when the current pixel is located at the beginning of the row, it is determined that a white continuous region has been detected, and the column coordinate of the pixel is recorded as the starting column of the white continuous region. Continue traversing the binary image to the right along the row. When a pixel value of 0 is detected, or when the end of the row is reached, the white continuous region is determined to be over, and the position of the white pixel before the end is recorded as the termination column of the white continuous region. The length of the white continuous region is calculated based on the starting and ending columns.
5. The method for detecting a rectangular frame of a laser line region according to claim 4, characterized in that, In step five, when calculating the length of the continuous white region in each row, if the length of the continuous white region is greater than the preset region length, the pixel value between the start point and the end point of the row is set to 0, and the scanning of subsequent pixels in the row continues until each row is scanned.
6. The method for detecting a rectangular frame of a laser line region according to claim 5, characterized in that, The preset area length is 15 pixels wide.
7. The method for detecting a rectangular frame of a laser line region according to claim 1, 2, or 3, characterized in that, In step seven, the preset vector segmentation threshold is the sum of 3 to 5 white pixel values.