Character positioning and segmenting method for cable character detection
Through the linear array industrial camera and visual interface combined with adaptive threshold binarization and angle correction methods, the problems of inaccurate positioning and poor segmentation effects in cable character detection are solved, and efficient and accurate character detection in complex environments are achieved.
Patent Information
- Application Number
- CN202510535892.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-08-12
AI Technical Summary
In the prior art cable character detection, there are problems such as inaccurate character positioning, poor segmentation effect and poor adaptability, and it is difficult to efficiently and accurately identify characters on the cable surface in complex industrial environments.
The linear array industrial camera and visual interface are used to collect color images through bar light sources, and adaptive threshold binarization and expansion operations are performed. Combined with angle correction and contour screening, accurate character positioning and segmentation are achieved, and dynamic adjustments are used to adapt to environmental changes through historical templates.
It realizes efficient and accurate character positioning and segmentation on cables of different specifications and materials, improves the adaptability and recognition accuracy of detection, and can cope with complex environmental factors such as lighting changes and stains.
Smart Images

Figure CN120472469A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of intelligent detection, and in particular relates to a character positioning and segmentation method for cable character detection. Background Art
[0002] In industrial production, cables are often printed with characters (such as model, specification, and production batch). These characters are an important basis for cable identification and quality traceability. Traditional character detection methods rely mainly on manual visual inspection, which has problems such as low efficiency, prone to errors, and high costs. In recent years, machine vision-based character detection technology has gradually been applied, but the following problems still exist:
[0003] 1. Inaccurate character positioning: Due to the jitter of the cable in the transmission channel, the inkjet printer may deviate from the inkjet printing position when printing. In addition, there are problems such as reflection, stains or blurred characters on the cable surface. Traditional image processing methods are difficult to accurately locate the character area.
[0004] 2. Poor character segmentation: Low contrast between characters and background, or characters that are stuck or broken, can lead to unsatisfactory segmentation and affect subsequent recognition accuracy.
[0005] 3. Poor adaptability: Existing methods have poor robustness to environmental factors such as lighting changes and cable bending, and are difficult to adapt to complex industrial environments.
[0006] Therefore, there is an urgent need for an efficient and accurate character positioning and segmentation method to improve positioning accuracy and segmentation effect, thereby improving the accuracy and efficiency of cable character detection. Summary of the Invention
[0007] In view of the above technical problems existing in the prior art, the present invention proposes a character positioning and segmentation method for cable character detection, which has a reasonable design, overcomes the shortcomings of the prior art, and has good effects.
[0008] In order to achieve the above object, the present invention adopts the following technical solutions:
[0009] A character positioning and segmentation method for cable character detection uses a linear array industrial camera, an inkjet printer, and a visual interface; the method includes the following steps:
[0010] Step 1: Image acquisition: A bar light source is used to illuminate the cable surface at a fixed tilt angle, and a linear array industrial camera is used to capture a color image of the cable surface in real time.
[0011] Step 2: Image preprocessing: Convert the color image into a grayscale image, use the adaptive threshold algorithm to binarize the grayscale image, and enhance the character outline through the dilation operation;
[0012] Step 3: Angle correction: Perform horizontal projection analysis on the binarized image, calculate the character tilt angle, and perform rotation correction with the image center as the rotation center;
[0013] Step 4: Contour extraction and screening: Extract all contours in the corrected image and screen valid character contours based on preset area thresholds and height thresholds;
[0014] Step 5: String aggregation: Sort valid contours by horizontal position, aggregate adjacent contours into strings based on the character spacing threshold, and expand the aggregated area horizontally and vertically;
[0015] Step 6: Dynamic detection and recognition: Compare the number of character areas currently detected with the number of historical template presets, and update the template or reallocate the image area according to the printer command status;
[0016] Step 7: Output the result: Output the segmented character image in a preset format for use by the subsequent character recognition module;
[0017] Step 8: Online debugging: The intermediate processing results are displayed in real time through a visual interface, and parameters can be dynamically adjusted to optimize the segmentation effect.
[0018] Preferably, the image preprocessing in step 2 specifically includes the following steps:
[0019] Step 2.1: Convert the color image to grayscale image by weighted averaging method, as shown in formula (1):
[0020] Gray=0.299×R+0.587×G+0.114×B (1);
[0021] Among them, R, G, and B are the red, green, and blue channel pixel values respectively;
[0022] Step 2.2: Use the adaptive threshold algorithm to binarize the grayscale image, as shown in formula (2):
[0023]
[0024] Where I(x,y) is the pixel value of the grayscale image at the coordinate (x,y), T(x,y) is the adaptive threshold at that point, and f(x,y) is the pixel value of the binarized image at that point.
[0025] Step 2.3: Use rectangular structure elements to perform multiple dilation operations on the binary image to enhance the continuity of characters.
[0026] Preferably, the angle correction in step 3 specifically includes the following steps:
[0027] Step 3.1: Perform horizontal projection on the expanded image, count the sum of pixel values in each row, and calculate the distance d between adjacent peaks;
[0028] Step 3.2: Estimate the tilt angle of the character according to formula (3);
[0029]
[0030] Where W is the width of the image;
[0031] Step 3.3: With the center point of the image as the rotation center, perform rotation correction on the expanded image according to the detected tilt angle θ; during the rotation process, perform coordinate transformation on each point on the image according to the rotation formula (4) to make the character in a horizontal state;
[0032]
[0033] Preferably, the conditions for contour screening in step 4 are:
[0034] Use appropriate contour extraction algorithm to process the rotation-corrected image, find all the contours in the image, calculate the area A and height h of the circumscribed rectangle of each contour; compare the area A with the preset minimum area threshold A. min Compare the height h with the preset minimum height threshold h min Compare; if area A is less than A min or the height h is less than h min , the area corresponding to the contour is considered to be an invalid area and is filtered out from subsequent processing.
[0035] Preferably, the string aggregation in step 5 specifically includes the following steps:
[0036] Step 5.1: Sort the filtered valid contours by horizontal position
[0037] Step 5.2: Calculate the spacing g between adjacent outline circumscribed rectangles in sequence; compare the spacing g with the preset character spacing threshold g threshold Compare, if g is less than g threshold , then the characters corresponding to the two contours are regarded as components of the same string and aggregated together; by traversing all valid contours, the string aggregation operation is completed;
[0038] Step 5.3: For each aggregated string region, expand x horizontally to both sides based on the left and right boundaries of the region. inflate pixels; in the vertical direction, based on the upper and lower boundaries of the area, expand to both sides by y pixels. inflate pixels.
[0039] Preferably, the specific contents of dynamic detection and identification in step 6 are as follows:
[0040] Through historical template data, the number and characteristics of each detected character region are recorded. After each string aggregation is completed, the number of currently detected character regions is compared with the number in the historical template.
[0041] If the number of character areas after segmentation does not match the preset number of the template and the printer command changes, the automatic update mechanism will be activated to update the recognition template in a timely manner;
[0042] If the number of character areas after segmentation does not match the preset number of the template and the printer command has not changed, the image area will be reallocated according to the detection frame area information corresponding to the character segmentation in the recognition template.
[0043] Preferably, in step 7, the processed and segmented character image is sorted and output according to the requirements of the subsequent character recognition module; the output format can be adjusted according to actual needs, and the output character image can be used as valid input data for the subsequent character recognition module.
[0044] Preferably, in step 8, the results of each step of the segmentation and recognition process are displayed through a visual interface, including a grayscale image, a binary image, an expanded image, an image after rotation correction, an extracted contour, and an aggregated string area; the user can observe these results in real time, discover problems in a timely manner according to actual conditions, and adjust the parameters of each step.
[0045] The beneficial technical effects brought about by the present invention are:
[0046] The character positioning and segmentation method for cable character detection employed in this invention can accurately locate the character area on the cable surface, effectively addressing issues such as lighting variations, stains, blurred characters, and adhesion. The method can be applied to character detection on cables of varying specifications and materials, demonstrating strong versatility. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 Schematic diagram for cable character collection;
[0048] Figure 2 is the original image collected;
[0049] Figure 3 This is the image preprocessing effect diagram;
[0050] Figure 4 This is the image correction effect diagram;
[0051] Figure 5 Extract, filter and aggregate renderings for contours;
[0052] Figure 6 This is a schematic diagram of the online debugging interface. DETAILED DESCRIPTION
[0053] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments:
[0054] 1) Image acquisition
[0055] like Figure 1 As shown, a bar light source illuminates the cable sprayed by the inkjet printer at a fixed tilt angle, and the cable surface is captured in real time by a linear array industrial camera;
[0056] 2) Image preprocessing
[0057] After obtaining the color image of the cable surface Figure 2 As shown, it is converted into a grayscale image. During the conversion process, each pixel is calculated according to the weighted average method formula Gray = 0.299 × R + 0.587 × G + 0.114 × B to obtain the corresponding grayscale value, thereby converting the color image into a grayscale image containing only one channel information.
[0058] For grayscale images, an adaptive threshold algorithm is used for binarization. First, a neighborhood block of appropriate size is selected for each pixel, the mean or weighted mean of the pixels in the neighborhood block is calculated, and then the preset constant C is subtracted to obtain the adaptive threshold of the pixel. Next, the relationship between the pixel value of each pixel and the adaptive threshold is determined according to the binarization formula. Points with pixel values greater than or equal to the threshold are set to 255 (white), and points with values less than the threshold are set to 0 (black), completing the binarization process. The binarization formula is:
[0059]
[0060] Where I(x,y) is the pixel value of the grayscale image at coordinate (x,y), T(x,y) is the adaptive threshold at that point, and f(x,y) is the pixel value of the binarized image at that point.
[0061] Determine the shape and size of the structural element according to the actual situation. Taking the rectangular structural element as an example, select the appropriate side length to generate the structural element for the subsequent expansion operation. Use the generated structural element to perform the expansion operation on the binarized image. The number of expansion operations can be adjusted according to the specific situation of the character. Through multiple expansions, the outline of the character is enhanced, and the continuity and integrity of the character are improved. During the expansion process, according to the expansion operation formula Processing, the effect is as follows Figure 3 shown.
[0062] 3) Angle correction
[0063] like Figure 3 As shown, the expanded image is horizontally projected, and the sum of the pixel values of each row is counted to obtain the horizontal projection curve. Analyze the peak distribution of the horizontal projection curve, find the horizontal distance d between adjacent peaks, and obtain the width W of the image at the same time, and then use the formula Estimate the slant angle of characters.
[0064] Determine the center point of the image as the rotation center, and perform rotation correction on the expanded image according to the detected tilt angle θ. During the rotation process, according to the rotation formula Perform coordinate transformation on each point on the image so that the characters are in a horizontal state.
[0065] 3) Contour extraction and screening
[0066] Use appropriate contour extraction algorithms to process the rotation-corrected image and find all the contours in the image. These contours represent the boundaries of continuous areas with the same pixel values, which are important for subsequent character positioning and segmentation. For each extracted contour, calculate the area A and height h of its circumscribed rectangle; compare the area A with the preset minimum area threshold A. min Compare the height h with the preset minimum height threshold h min Compare; if area A is less than A min or the height h is less than h min , the area corresponding to the contour is considered to be an invalid area and is filtered out from subsequent processing.
[0067] 4) String aggregation
[0068] like Figure 4 As shown, the filtered valid contours are sorted according to the horizontal position, and then the spacing g between the adjacent contour circumscribed rectangles is calculated in sequence; the spacing g is compared with the preset character spacing threshold g threshold Compare, if g is less than g threshold , the characters corresponding to the two contours are regarded as components of the same string and are aggregated together; the string aggregation operation is completed by traversing all valid contours.
[0069] For each string region after aggregation, in the horizontal direction, based on the left and right boundaries of the region, expand x to both sides respectively. inflate pixels; in the vertical direction, based on the upper and lower boundaries of the area, expand to both sides by y pixels. inflate The expanded area can contain more character context information, which is beneficial to improving the accuracy of subsequent character recognition.
[0070] 5) Dynamic recognition
[0071] The program maintains a historical template data, recording the number and characteristics of each detected character region. After completing step 4) string aggregation, the number of character regions currently detected is compared with the number in the historical template. If the number of segmented character regions is inconsistent with the preset number in the template, and the command received from the printer has changed compared to the previous one, it means that a new character arrangement pattern has appeared. At this time, the program activates the automatic update mechanism to promptly update the recognition template to ensure that subsequent detection can adapt to the new arrangement pattern.
[0072] Conversely, if the number of segmented character areas doesn't match the preset number in the template, and the printer command remains unchanged, an anomaly has occurred during the inspection process. The system then reallocates the image area based on the detection frame area information corresponding to the character segments in the recognition template. This approach corrects problems caused by inaccurate positioning and segmentation errors, minimizes false detection rates, and improves the accuracy and reliability of inspection results.
[0073] 6) Output results
[0074] The processed and segmented character images are organized and output according to the requirements of the subsequent character recognition module. The output format can be adjusted according to actual needs to ensure that the output character images can serve as valid input data for the subsequent character recognition module. The advantage of outputting the characters as independent detection boxes is that the user can set the recognition rules for each detection box separately.
[0075] 7) Online debugging
[0076] like Figure 5 As shown in the figure, during the system operation, the results of each step of the segmentation and recognition process are displayed through a visual interface, including grayscale images, binary images, dilated images, rotation-corrected images, extracted contours, aggregated string regions, etc. Users can observe these results in real time, find problems in time according to actual conditions, and adjust the parameters of each step, such as the distance interval g. threshold , ignore dimension A min Ignore the height h min etc., to optimize the segmentation and recognition effects and ensure that the system can meet the needs of actual production
[0077] Of course, the above description is not a limitation of the present invention, and the present invention is not limited to the above examples. Changes, modifications, additions or substitutions made by technicians in this technical field within the essential scope of the present invention should also fall within the scope of protection of the present invention.
Claims
1. A character positioning and segmentation method for cable character detection, characterized in that: Using a linear array industrial camera, inkjet printer, and visual interface; including the following steps: Step 1: Image acquisition: A bar light source is used to illuminate the cable surface at a fixed tilt angle, and a linear array industrial camera is used to capture a color image of the cable surface in real time. Step 2: Image preprocessing: Convert the color image into a grayscale image, use the adaptive threshold algorithm to binarize the grayscale image, and enhance the character outline through the dilation operation; Step 3: Angle correction: Perform horizontal projection analysis on the binarized image, calculate the character tilt angle, and perform rotation correction with the image center as the rotation center; Step 4: Contour extraction and screening: Extract all contours in the corrected image and screen valid character contours based on preset area thresholds and height thresholds; Step 5: String aggregation: Sort valid contours by horizontal position, aggregate adjacent contours into strings based on the character spacing threshold, and expand the aggregated area horizontally and vertically; Step 6: Dynamic detection and recognition: Compare the number of character areas currently detected with the number of historical template presets, and update the template or reallocate the image area according to the printer command status; Step 7: Output the result: Output the segmented character image in a preset format for use by the subsequent character recognition module; Step 8: Online debugging: The intermediate processing results are displayed in real time through a visual interface, and parameters can be dynamically adjusted to optimize the segmentation effect.
2. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: The image preprocessing in step 2 specifically includes the following steps: Step 2.1: Convert the color image to grayscale image by weighted averaging method, as shown in formula (1): Gray=0.299×R+0.587×G+0.114×B (1); Among them, R, G, and B are the red, green, and blue channel pixel values respectively; Step 2.2: Use the adaptive threshold algorithm to binarize the grayscale image, as shown in formula (2): Where I(x,y) is the pixel value of the grayscale image at the coordinate (x,y), T(x,y) is the adaptive threshold at that point, and f(x,y) is the pixel value of the binarized image at that point. Step 2.3: Use rectangular structure elements to perform multiple dilation operations on the binary image to enhance the continuity of characters.
3. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: The angle correction in step 3 specifically includes the following steps: Step 3.1: Perform horizontal projection on the expanded image, count the sum of pixel values in each row, and calculate the distance d between adjacent peaks; Step 3.2: Estimate the tilt angle of the character according to formula (3); Where W is the width of the image; Step 3.3: With the center point of the image as the rotation center, perform rotation correction on the expanded image according to the detected tilt angle θ; during the rotation process, perform coordinate transformation on each point on the image according to the rotation formula (4) to make the character in a horizontal state; 4. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: The conditions for contour screening in step 4 are: Use appropriate contour extraction algorithm to process the image after rotation correction, find all the contours in the image, calculate the area A and height h of the circumscribed rectangle of each contour; compare the area A with the preset minimum area threshold A min Compare the height h with the preset minimum height threshold h min Compare; if area A is less than A min or the height h is less than h min , the area corresponding to the contour is considered to be an invalid area and is filtered out from subsequent processing.
5. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: The string aggregation in step 5 specifically includes the following steps: Step 5.1: Sort the filtered valid contours by horizontal position Step 5.2: Calculate the spacing g between adjacent outline circumscribed rectangles in sequence; compare the spacing g with the preset character spacing threshold g threshold Compare, if g is less than g threshold , then the characters corresponding to the two contours are regarded as components of the same string and aggregated together; by traversing all valid contours, the string aggregation operation is completed; Step 5.3: For each aggregated string region, expand x horizontally to both sides based on the left and right boundaries of the region. inflate pixels; in the vertical direction, based on the upper and lower boundaries of the area, expand to both sides by y pixels. inflate pixels.
6. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: The specific contents of dynamic detection and identification in step 6 are as follows: Through historical template data, the number and characteristics of each detected character region are recorded. After each string aggregation is completed, the number of currently detected character regions is compared with the number in the historical template. If the number of character areas after segmentation does not match the preset number of the template and the printer command changes, the automatic update mechanism will be activated to update the recognition template in a timely manner; If the number of character areas after segmentation does not match the preset number of the template and the printer command has not changed, the image area will be reallocated according to the detection frame area information corresponding to the character segmentation in the recognition template.
7. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: In step 7, the processed and segmented character images are sorted and output according to the requirements of the subsequent character recognition module; the output format can be adjusted according to actual needs, and the output character images can be used as valid input data for the subsequent character recognition module.
8. The character positioning and segmentation method for cable character detection according to claim 1, characterized in that: In step 8, the results of each step of the segmentation and recognition process are displayed through a visual interface, including the grayscale image, the binary image, the expanded image, the rotation-corrected image, the extracted contours, and the aggregated string regions. Users can observe these results in real time, identify problems in a timely manner based on actual conditions, and adjust the parameters of each step.