A method for calculating alignment based on image analysis
Through image analysis based on image analysis, using camera and image processing technology, the alignment between the extender cylinder and the compressor punch is accurately extracted, solving the problems of low efficiency and insufficient accuracy of traditional manual detection, and achieving high-precision automated alignment detection.
Patent Information
- Application Number
- CN202411646614.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2044-11-18
AI Technical Summary
The existing method of pinch-extension machine center detection relies on manual measurement, is inefficient and susceptible to human factors, making it difficult to achieve high-precision automated detection, and image analysis methods reduce image quality and difficulty in extracting feature under complex backgrounds and noise.
Using an image analysis-based method, image information is obtained through the camera, combined with median filtering, image differential and thresholding processing, key features are accurately extracted and the mean is calculated, including installing two cameras to capture images on the X-axis and Y-axis, performing pixel-by-pixel difference calculation and rectangle extraction, and calculating the offset and meanness of the inner rectangle relative to the center of the outer rectangle.
Improves centering accuracy, ensures stable operation and production efficiency of equipment, and provides reliable automated inspection support.
Smart Images

Figure CN119399263B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing, and in particular relates to a method for calculating centering degree based on image analysis. Background Art
[0002] As a critical piece of equipment in product production, the operating status of a press directly impacts product quality and production efficiency. In particular, deviations in the alignment between the medicine cylinder and the press punch can lead to equipment failure and production halts. However, due to long-term operation under high loads and complex working conditions, the equipment's alignment accuracy is easily affected by wear, thermal expansion, and other external factors, resulting in misalignment.
[0003] Traditional alignment inspection methods rely primarily on manual measurement and visual inspection to determine the alignment status of equipment. This approach is not only inefficient but also susceptible to human error, making it difficult to achieve high-precision automated inspection. In recent years, with the advancement of image processing technology, automated alignment inspection methods based on image analysis have gained increasing attention. These methods can improve the accuracy and efficiency of alignment inspection through image recognition and analysis.
[0004] However, existing image analysis methods often face problems of image quality degradation and difficulty in feature extraction when dealing with complex backgrounds and noise. Summary of the Invention
[0005] To overcome the shortcomings of existing technologies, this invention provides an alignment calculation method based on image analysis. This method uses camera-generated image information combined with advanced image processing techniques, including median filtering, image differencing, and thresholding, to accurately extract key features and calculate alignment. This method effectively improves alignment accuracy and provides reliable technical support for stable equipment operation and production efficiency.
[0006] The technical solutions adopted by the present invention to solve the technical problems are as follows:
[0007] Step 1: Enter the fixture parameter information on the press console;
[0008] Step 2: Use two cameras to capture images of the punch spindle on the X-axis and Y-axis respectively. Based on the image processing method, generate the shaft diameter image and background image. Pre-process the background image and use the absolute difference operation to calculate the pixel-by-pixel difference between the shaft diameter image and the pre-processed background image. Then, use the software to perform threshold processing on the image to reduce environmental impact.
[0009] Step 3: Use software to extract the image and only extract the rectangles required for calculation;
[0010] Step 4: Calculate the offset and centering of the inner rectangle relative to the center of the outer rectangle and output them.
[0011] Preferably, the step 1 is specifically:
[0012] Step 1-1: Install two cameras on the device, with the shooting directions of the cameras perpendicular to each other, ensuring that the two cameras are located on the coordinate axes of the horizontal coordinate system;
[0013] Step 1-2: The horizontal cross-section of the medicine cylinder of the press is a circle, and the center of the circle is the origin of the horizontal coordinate system. Construct the horizontal coordinate system and the centering calculation model a based on the two camera coordinate points and the center of the medicine cylinder cross-section;
[0014] Steps 1-3: Use two cameras to capture images on the X and Y axes respectively; construct an outer rectangle based on the image size ratio, and read the coordinate information of the medicine tank to generate the offset calculation models b and c, and add the center line of the outer rectangle, i.e., the center line of the medicine tank; define a matrix based on the resolution m×n of the photos taken by the camera. The matrix size is m×n, and each element in the matrix corresponds to a pixel point.
[0015] Preferably, the step 2 is specifically as follows:
[0016] Step 2-1: Turn on two cameras and simultaneously capture images of the axis diameter of the pill punch spindle on the X-axis and Y-axis.
[0017] Step 2-2: Read the axis diameter image taken this time and the previous background image, convert the background image and the second-shot image into grayscale images, and then apply median filtering to them respectively;
[0018] Step 2-3: Use absolute difference operation to calculate the pixel-by-pixel difference between the new image and the background image. Each pixel value in the difference result matrix represents the brightness difference between the new image and the background image. If the background does not change, the pixel difference is close to 0.
[0019] Step 2-4: Set the threshold, set the pixels smaller than the threshold to 0, and the pixels larger than the threshold to 1, and only retain the pixels set to 1.
[0020] Preferably, the step 3 is specifically as follows:
[0021] Step 3-1: After completing preprocessing, image difference and thresholding, extract the changed part of the foreground area and obtain the matrix;
[0022] Step 3-2: Perform initialization matrix scan: start from the bottom row of the matrix and check upwards row by row;
[0023] Detect the lower boundary: traverse each row and count the number of elements with a value of 1 in the row. If the number of 1s in a row is greater than or equal to 100, the row is considered to be the lower boundary row of the inner rectangle. Record the row number of the lower boundary row and stop searching further upwards.
[0024] Determine the left and right boundaries: Count upward 20 rows from the bottom boundary row to form a 20-row detection area. Within this area, traverse row by row and find the first and last 1s in each row, recording the positions of these left and right boundaries. The X-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 292 and 692. The Y-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 322 and 722. Take the average of the leftmost and rightmost boundary values in these 20 rows as the coordinates of the left and right boundaries.
[0025] Calculate the center line: Use the average value of the left and right boundaries to calculate the coordinates of the inner rectangle on the X and Y axes. The pixel position of the center line of the main axis of the medicine pressing punch on the X axis is (292+692) / 2=492, and the pixel position of the center line of the main axis of the medicine pressing punch on the Y axis is (322+722) / 2=522; and add them to the corresponding offset calculation models b and c.
[0026] Preferably, the step 4 is specifically as follows:
[0027] Step 4-1: Calculate the offset pixels of the corresponding inner rectangle center relative to the outer rectangle center in the offset calculation models b and c respectively;
[0028] Step 4-2: Import the X and Y axis offsets into the alignment calculation model a, calculate the alignment coordinates and alignment values, and output them.
[0029] A computer program enables a computer to execute the above-mentioned centering degree calculation method.
[0030] An electronic device includes: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the above-mentioned centering degree calculation method.
[0031] A computer-readable storage medium stores a computer program, which implements the above-mentioned centering degree calculation method when executed by a processor.
[0032] A chip includes: a processor for calling and running a computer program from a memory, so that a device equipped with the chip executes the above-mentioned centering degree calculation method.
[0033] A computer program product includes a computer storage medium storing a computer program, wherein the computer program includes instructions executable by at least one processor, and when the instructions are executed by the at least one processor, the above-mentioned centering degree calculation method is implemented.
[0034] The beneficial effects of the present invention are as follows:
[0035] The method of the present invention can effectively improve the centering accuracy and provide reliable technical support for the stable operation and production efficiency of the equipment. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 It is an intuitive diagram of the X-axis offset calculation model b;
[0037] Figure 2 It is an intuitive diagram of the Y-axis offset calculation model c;
[0038] Figure 3 It is an intuitive diagram of the moderate computing model a. DETAILED DESCRIPTION
[0039] The present invention will be further described below with reference to the accompanying drawings and examples.
[0040] The purpose of the present invention is to propose a method for calculating the alignment between a medicine cylinder and a medicine pressing punch of a pressing machine based on image analysis. The method is simple and the calculation is convenient.
[0041] To achieve the above-mentioned purpose, the present invention adopts the following technical solution: a method for calculating the alignment between the medicine cylinder and the medicine pressing punch of a press machine based on image analysis, comprising the following steps: a first step, inputting the parameter information of the fixing device into the press machine console; a second step, using two cameras to shoot the axis diameter image of the medicine pressing punch main axis on the X-axis and Y-axis respectively, and based on the image processing method, pre-processing the axis diameter image and the background image, using the absolute difference operation to perform pixel-by-pixel difference calculation on the new image and the pre-processed background image, and then thresholding the image through software to reduce environmental impact; a third step, using software to extract the image, and only extracting the rectangle required for calculation; a fourth step, respectively calculating the offset and alignment of the inner rectangle relative to the center of the outer rectangle and outputting them. Specific embodiment:
[0043] 1. Enter the fixture parameter information on the press console:
[0044] (1) Install two cameras on the device with their shooting directions perpendicular to each other, ensuring that the two cameras are located on the coordinate axes of the horizontal coordinate system.
[0045] (2) The horizontal cross section of the medicine tank is a circle. The center of the circle is the origin of the horizontal coordinate system, which is the red origin (0, 0) in the view. The horizontal coordinate system and the centering calculation model a are constructed based on the two camera coordinate points and the center of the medicine tank cross section.
[0046] (3) Use two cameras to collect images on the X-axis and Y-axis respectively. The background image captured and saved at this time is used for the subsequent differential operation. The external rectangle is constructed according to the image size ratio, and the coordinate information of the medicine tank is read. The center line of the external rectangle (i.e., the center line of the medicine tank) is added to the offset calculation model b and c. The matrix is defined according to the resolution m×n of the photo taken by the camera. The size of the matrix is m×n, and each element in the matrix corresponds to a pixel point. Since the camera pixel used this time is 1024×1024, the m and n values are both 1024.
[0047] 2. Use two cameras on the same horizontal plane to capture the axis diameter image of the punch on the X-axis and Y-axis respectively, and pre-process the image:
[0048] (1) Turn on two cameras and simultaneously capture the axis diameter image of the punch on the X-axis and Y-axis.
[0049] (2) Read the image and the previous background image, and convert both the background image and the new image into grayscale images. This can reduce the amount of calculation, improve the processing speed, and avoid the interference of color on the difference result; then use median filtering on them respectively to reduce the influence of noise.
[0050] (3) Use absolute difference operation to calculate the pixel difference between the new image and the background image. Each pixel value in the difference result matrix represents the brightness difference between the new image and the background image. If the background has not changed, the pixel difference should be close to 0. The area where the foreground changes will have a significant difference value.
[0051] (4) Since the working environment of the press machine is relatively complex and there are illumination changes, mechanical vibrations, and other noise sources, the threshold is set to 10 pixels. This setting is intended to filter out small differences caused by environmental factors to cope with the influence of illumination changes and slight noise. At the same time, the pixels smaller than the threshold (approximate background) are set to 0, and the pixels larger than the threshold (the required shaft diameter part) are set to 1, and only the pixels set to 1 are retained.
[0052] 3. Use software to extract the image and only extract the rectangles required for calculation:
[0053] (1) After completing preprocessing, image difference, and thresholding, the background region of the difference matrix is close to zero, and only the significant changes in the foreground region are retained. The significant changes are extracted to obtain the required matrix.
[0054] (2) Initialize the matrix scan: Start from the bottom row of the matrix and check upwards row by row; Detect the lower boundary: Traverse each row and count the number of elements with a value of 1 in the row. If the number of 1s in a row is greater than or equal to 100, the row is considered to be the lower boundary row of the inner rectangle. Record the row number of the lower boundary row and stop searching upwards; Determine the left and right boundaries: Count 20 rows upward from the lower boundary row to form a 20-row detection area. Within this area, traverse row by row and find the first and last positions of 1 in each row, and record the positions of these left and right boundaries. The X-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 292 and 692. The Y-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 322 and 722. The average of the leftmost and rightmost boundary values in these 20 rows is used as the coordinates of the left and right boundaries. Calculate the centerline: Use the average of the left and right boundaries to calculate the coordinates of the inner rectangle on the X and Y axes. The pixel position of the centerline of the main axis of the punch on the X axis is (292 + 692) / 2 = 492, and the pixel position of the centerline of the main axis of the punch on the Y axis is (322 + 722) / 2 = 522. These values are then added to the corresponding offset calculation models b and c.
[0055] 4. Calculate the offset and centering of the inner rectangle relative to the center of the outer rectangle and output them:
[0056] (1) In the offset calculation models b and c, the offset pixels of the corresponding inner rectangle center relative to the outer rectangle center are calculated respectively. Figure 1 In the figure, the red dotted line is the center line of the medicine cylinder, and the blue dotted line is the center line of the rectangle inside the X-axis. The X-axis offset is -20 pixels. Since the main shaft diameter of the medicine punch is 400 mm and the photo pixel size is 1024 × 1024, the calculated value c = 1 / m = 0.39 mm, so the X-axis offset is 20c = 20 × 0.39 = 7.8 mm. Figure 2 In the figure, the red dotted line is the center line of the medicine cylinder, the blue dotted line is the center line of the inner rectangle of the Y-axis, the offset of the Y-axis is 10, and the offset of the Y-axis is 10c=10×0.39=3.9mm.
[0057] (2) Import the X and Y axis offsets into the centering calculation model a, calculate the centering coordinates to be (-20, 10), so the centering value is 8.72mm and output. Figure 3 , where the red origin is the center point of the medicine cylinder; the two yellow dots on the two axes are the Y-axis offset recording camera and the X-axis offset recording camera respectively. The two yellow dots and the red origin form a horizontal coordinate system; the blue dot represents the center point of the main axis of the medicine pressing punch.
Claims
1. A method for calculating alignment based on image analysis, characterized in that: The steps include: Step 1: Enter the fixture parameter information on the press console; Step 2: Use two cameras to capture images of the punch spindle on the X-axis and Y-axis respectively. Based on the image processing method, generate the shaft diameter image and background image. Pre-process the background image and use the absolute difference operation to calculate the pixel-by-pixel difference between the shaft diameter image and the pre-processed background image. Then, use the software to perform threshold processing on the image to reduce environmental impact. Step 2-1: Turn on two cameras and simultaneously capture the axis diameter image of the pill punch main axis on the X-axis and Y-axis; Step 2-2: Read the axis diameter image taken this time and the previous background image, convert the background image and the second-shot image into grayscale images, and then apply median filtering to them respectively; Step 2-3: Use absolute difference operation to calculate the pixel-by-pixel difference between the new image and the background image. Each pixel value in the difference result matrix represents the brightness difference between the new image and the background image. If the background does not change, the pixel difference is close to 0. Step 2-4: Set the threshold, set the pixels smaller than the threshold to 0, and the pixels larger than the threshold to 1, and only keep the pixels set to 1; Step 3: Use software to extract the image and only extract the rectangles required for calculation; Step 4: Calculate the offset and centering of the inner rectangle relative to the center of the outer rectangle and output them.
2. The method for calculating alignment based on image analysis according to claim 1, characterized in that: The step 1 is specifically as follows: Step 1-1: Install two cameras on the device, with the shooting directions of the cameras perpendicular to each other, ensuring that the two cameras are located on the coordinate axes of the horizontal coordinate system; Step 1-2: The horizontal cross-section of the medicine cylinder of the press is a circle, and the center of the circle is the origin of the horizontal coordinate system. Construct the horizontal coordinate system and the centering calculation model a based on the two camera coordinate points and the center of the medicine cylinder cross-section; Steps 1-3: Use two cameras to capture images on the X and Y axes respectively; construct an outer rectangle based on the image size ratio, and read the coordinate information of the medicine tank to generate the offset calculation models b and c, and add the center line of the outer rectangle, i.e., the center line of the medicine tank; define a matrix based on the resolution m×n of the photos taken by the camera. The matrix size is m×n, and each element in the matrix corresponds to a pixel point.
3. The method for calculating alignment based on image analysis according to claim 2, characterized in that: The step 3 is specifically as follows: Step 3-1: After completing preprocessing, image difference and thresholding, extract the changed part of the foreground area and obtain the matrix; Step 3-2: Perform initialization matrix scan: start from the bottom row of the matrix and check upwards row by row; Detect the lower boundary: traverse each row and count the number of elements with a value of 1 in the row. If the number of 1s in a row is greater than or equal to 100, the row is considered to be the lower boundary row of the inner rectangle. Record the row number of the lower boundary row and stop searching further upwards. Determine the left and right boundaries: Count upward 20 rows from the bottom boundary to form a 20-row detection area. Within this area, traverse row by row and find the first and last 1 positions in each row, and record the positions of these left and right boundaries. The X-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 292 and 692. The Y-axis offset records the rectangle generated after the camera image is processed. The average positions of the first and last 1s in each row are 322 and 722. The average of the leftmost and rightmost boundary values in these 20 rows is used as the coordinates of the left and right boundaries. Calculate the center line: Use the average value of the left and right boundaries to calculate the coordinates of the inner rectangle on the X and Y axes. The pixel position of the center line of the main axis of the medicine pressing punch on the X axis is (292+692) / 2=492, and the pixel position of the center line of the main axis of the medicine pressing punch on the Y axis is (322+722) / 2=522; and add them to the corresponding offset calculation models b and c.
4. The method for calculating alignment based on image analysis according to claim 3, characterized in that: The step 4 is specifically as follows: Step 4-1: Calculate the offset pixels of the corresponding inner rectangle center relative to the outer rectangle center in the offset calculation models b and c respectively; Step 4-2: Import the X and Y axis offsets into the alignment calculation model a, calculate the alignment coordinates and alignment values, and output them.
5. An electronic device, characterized in that: include: processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory, so that the electronic device performs the method according to any one of claims 1 to 4.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.
7. A chip, characterized in that: include: A processor, configured to call and run a computer program from a memory, so that a device equipped with the chip executes the method according to any one of claims 1 to 4.
8. A computer program product, characterized in that The computer program product comprises a computer storage medium storing a computer program, wherein the computer program comprises instructions executable by at least one processor, and when the instructions are executed by the at least one processor, the method according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Image median filtering detection method and device, equipment and storage medium
CN117237262A
Camera coordinate conversion parameter calibration method and system and camera
CN118279410A