Method, device, storage medium and electronic device for detecting device height
By generating detection areas in the device image and scanning along the height scanning direction, the problem of large and time-consuming calculations in the prior art is solved, and fast and efficient device height detection is achieved, suitable for high-throughput scenarios and reduce noise impact.
Patent Information
- Application Number
- CN202111567210.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2041-12-20
AI Technical Summary
The prior art has a large amount of calculation, a lot of resource occupancy and a long time in device height detection, making it difficult to meet the needs of real-time detection and calculation of output results in a short time.
By generating a detection area in the device image, scanning the device image in the height scanning direction, determining the distance between its boundary and the preset reference plane based on the pixels of the device to be detected, and determining the device height by multiple scans.
It realizes rapid and efficient calculation of device height, is suitable for high-throughput detection scenarios, can avoid the impact of noise in device images on detection results, and has good scalability.
Smart Images

Figure CN114494124B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of device detection, and in particular to a method, device, storage medium and electronic device for detecting the height of a device. Background Art
[0002] Generally, after a device is manufactured, various defects may occur, such as scratches on the surface of the device pins and cracks on the surface of the device shell. Therefore, it is necessary to detect defects in the produced devices before leaving the factory to eliminate devices with quality defects. Device defect detection generally requires the use of special testing equipment. With the continuous development of science and technology, the structural complexity of various devices and the production capacity of devices are also constantly improving. Correspondingly, higher requirements are placed on device testing equipment. In many production test scenarios, there are high requirements for the rate (throughput) of device detection, and it is necessary to sort and unload good and defective products immediately after the detection is completed. In this case, the algorithm is required to complete the detection of the height of the device in an image in a very short time, so as to determine whether the device is a good product or a defective product before unloading, so that the device can be stored in the correct material box when unloading.
[0003] Although existing image processing algorithms are capable of performing device height detection, these existing algorithms often require edge extraction and boundary fitting, which results in large computational complexity, high resource usage, and long processing time. They are not suitable for scenarios that require real-time detection and must complete calculations and output results in a short period of time. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a method, an apparatus, a storage medium and an electronic device for detecting the height of a device.
[0005] In order to achieve the above-mentioned object, the present application provides a method for detecting the height of a device in a first aspect, comprising:
[0006] Generate a detection area in a device image of the device to be detected, where the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected;
[0007] Determine pixels corresponding to the device to be inspected in the device image covered by the inspection area;
[0008] Scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected;
[0009] The device height of the device to be inspected is determined according to the spacing distance determined by multiple scans.
[0010] Optionally, scanning the device image within the detection area along the height scanning direction includes: determining whether a preset scanning direction is consistent with the height scanning direction indicated by the detection area; when it is determined that the preset scanning direction is inconsistent with the height scanning direction, rotating the device image and the detection area so that the height scanning direction of the device in the rotated device image is consistent with the preset scanning direction.
[0011] Optionally, determining pixels corresponding to the device to be detected in the device image covered by the detection area includes: performing threshold segmentation on the image area covered by the detection area by a preset color threshold to determine the pixels of the device to be detected in the image area covered by the detection area, and marking the determined pixels of the device to be detected with a preset value, wherein the preset color threshold is used to distinguish the pixels of the device to be detected from the pixels of the background image.
[0012] Optionally, the preset color threshold is set according to the difference in color components between the device to be detected and the background image in at least one color channel.
[0013] Optionally, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the device gap height, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the device image covered by the detection area along the height scanning direction, and determining the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected; determining the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected; and determining the device height of the device to be detected according to the spacing distance obtained by multiple scans includes: determining the device height of the device to be detected according to the gap height obtained by multiple scans.
[0014] Optionally, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the overall height of the device, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the detection area along the height scanning direction, and determining the last scanned pixel point marked as the preset value as the upper boundary of the device to be detected; determining the spacing distance between the upper boundary and the preset reference plane as the overall device height of the device to be detected; determining the device height of the device to be detected according to the spacing distance determined by multiple scans includes: determining the device height of the device to be detected according to the overall device height determined by multiple scans.
[0015] Optionally, the method also includes: dividing the detection area into multiple area segments along a direction perpendicular to the height scanning direction; and scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected, including: scanning the device image in the detection area multiple times along the height scanning direction, and obtaining multiple spacing distances each time; in each area segment, obtaining the segment height corresponding to the area segment according to the multiple spacing distances corresponding to the area segment; and determining the device height of the device to be detected according to the spacing distances determined by multiple scans includes: determining the device height of the device to be detected according to the segment heights corresponding to the multiple area segments.
[0016] Optionally, within each area segment, a segment height corresponding to each area segment is obtained by averaging multiple spacing distances corresponding to the segment; and a device height of the device to be detected is determined by averaging segment heights corresponding to multiple area segments.
[0017] Optionally, the method further includes: when the deviation between the device height and the target height is greater than a preset deviation threshold, determining that the device to be detected is an abnormal device; when the deviation is less than or equal to the preset deviation threshold, determining that the device to be detected is a normal device.
[0018] Optionally, generating a detection area in a device image of the device to be detected includes: acquiring a template image corresponding to the device image of the device to be detected, wherein the template image includes a reference device and an initial detection area covering at least one boundary of the reference device; comparing the device image with the template image to determine a position offset between the device to be detected in the device image and the reference device in the template image; and generating a detection area in the device image according to the position offset.
[0019] A second aspect of the present application provides a device for detecting the height of a device, comprising:
[0020] A detection area determination module is used to generate a detection area in a device image of the device to be detected, where the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected; and determine pixels corresponding to the device to be detected in the device image covered by the detection area;
[0021] A scanning module, used to scan the device image in the detection area along the height scanning direction, and obtain the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected;
[0022] The height determination module is used to determine the device height of the device to be detected according to the spacing distance determined by multiple scans.
[0023] A third aspect of the present application provides a machine-readable storage medium having instructions stored thereon, which, when executed by a processor, configure the processor to execute the above-mentioned method for detecting the height of a device.
[0024] A fourth aspect of the present application provides an electronic device, including a processor and a memory, wherein the processor and the memory are connected via a bus, and a computer program is stored in the memory. When the computer program is called by the processor, the above-mentioned method for detecting the height of a device is executed.
[0025] The above technical solution can conveniently and quickly calculate the device height of the device to be detected, which is applicable to high-throughput detection scenarios and different detection objects, and has good scalability. Moreover, by determining the device height by the distance between the boundary of the detection device and the preset reference plane, the influence of noise in the device image on the detection result can be avoided.
[0026] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent specific implementation section. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings are used to provide a further understanding of the embodiments of the present application and constitute a part of the specification. Together with the following specific implementations, they are used to explain the embodiments of the present application, but do not constitute a limitation on the embodiments of the present application. In the accompanying drawings:
[0028] Figure 1 A schematic diagram of a process for detecting the height of a device according to an embodiment of the present application is shown;
[0029] Figure 2 The structure block diagram of the device for detecting the height of a device according to an embodiment of the present application is schematically shown;
[0030] Figure 3 The internal structure of a computer device according to an embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0031] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. It should be understood that the specific implementation methods described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0032] Figure 1 The flowchart of the method for detecting the height of a device according to an embodiment of the present application is schematically shown. Figure 1 As shown, in one embodiment of the present application, a method for detecting the height of a device is provided, comprising the following steps:
[0033] Step 101 : generating a detection area in a device image of a device to be detected, wherein the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected.
[0034] Step 102: Determine pixels corresponding to the device to be inspected in the device image covered by the inspection area.
[0035] Step 103, scan the device image in the detection area along the height scanning direction, and obtain the spacing distance between the boundary of the device to be detected and the preset reference plane based on the pixels corresponding to the device to be detected, wherein the preset reference plane can be the surface on which the detection device is placed, and the position of this surface usually does not change, so it can be used as a reference for height measurement.
[0036] Step 104 , determining the device height of the device to be inspected according to the spacing distance determined by multiple scans.
[0037] As a relatively common defect in device production, the height abnormality of the device or device pins, etc., will have a certain impact on the production quality of the device. In order to detect the quality of the device, first, the processor can obtain a device image of the device to be detected. Among them, the device image can be captured by an image acquisition device. The image acquisition device can be a device with image acquisition function such as a camera, a video camera, a camera, a recorder, etc. When the image acquisition device captures the device image of the device to be detected, the processor can obtain the device image of the device to be detected, and can generate a detection area in the device image of the device to be detected. Among them, the detection area can cover at least one boundary of the device to be detected in the device image, and indicate the height scanning direction for the device to be detected.
[0038] After generating the detection area, the processor can determine the pixels corresponding to the device to be detected in the device image covered by the detection area. After determining the pixels corresponding to the device to be detected, the processor can scan the device image in the detection area along the height scanning direction, and obtain the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected. Among them, the boundary of the device to be detected can refer to the lower boundary of the device to be detected, and can refer to the upper boundary of the device to be detected. The preset reference plane can refer to the plane where the device to be detected is placed in the detection device. For example, the preset reference plane can refer to the glass turntable of the detection device.
[0039] When the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained, the processor can scan the device to be detected multiple times, and then the processor can determine the device height of the device to be detected according to the spacing distance determined by the multiple scans. The height of the device can refer to the gap height of the device or the overall height of the device.
[0040] The above technical solution can conveniently and quickly calculate the device height of the device to be detected, which is applicable to high-throughput detection scenarios and different detection objects, and has good scalability. Moreover, by determining the device height by the distance between the boundary of the detection device and the preset reference plane, the influence of noise in the device image on the detection result can be avoided.
[0041] In one embodiment, the detection area is a rotatable rectangular area.
[0042] In one embodiment, scanning the device image within the detection area along the height scanning direction includes: determining whether a preset scanning direction is consistent with the height scanning direction indicated by the detection area; when it is determined that the preset scanning direction is inconsistent with the height scanning direction, rotating the device image and the detection area so that the height scanning direction of the device in the rotated device image is consistent with the preset scanning direction.
[0043] The processor can determine whether the preset scanning direction is consistent with the height scanning direction indicated by the detection area. Among them, the preset scanning direction may refer to the scanning direction of the scanning device. The preset scanning direction may refer to the direction of scanning from the preset reference plane to the upper boundary of the device to be detected, and may refer to the direction of scanning from the upper boundary of the device to be detected to the preset reference plane. If it is determined that the preset scanning direction is inconsistent with the height scanning direction of the device to be detected, the processor can rotate the device image and the detection area so that the height scanning direction of the device in the rotated device image is consistent with the preset scanning direction. Among them, the detection area may refer to a rotatable rectangular area. If it is determined that the preset scanning direction is consistent with the height scanning direction of the device to be detected, the processor can obtain the spacing distance between the boundary of the device to be detected and the preset reference plane based on the pixels corresponding to the determined device to be detected.
[0044] In one embodiment, determining pixels corresponding to the device to be detected in the device image covered by the detection area includes: performing threshold segmentation on the image area covered by the detection area by a preset color threshold to determine the pixels of the device to be detected in the image area covered by the detection area, and marking the determined pixels of the device to be detected with a preset value, wherein the preset color threshold is used to distinguish the pixels of the device to be detected from the pixels of the background image.
[0045] Since the color of the device to be detected and its background area are different, the device image can be processed by threshold segmentation to facilitate the subsequent determination of the pixels corresponding to the device to be detected. Specifically, the processor can first perform threshold segmentation on the image area covered by the detection area by a preset color threshold. Threshold segmentation can be understood as defining the area of the device to be detected and the background area in which it is located by a preset color threshold. That is, the preset color threshold can be used to distinguish the pixels of the device to be detected from the pixels of the background image.
[0046] After performing the threshold segmentation, the processor can determine the pixels of the device to be detected in the image area covered by the detection area, and can mark the pixels of the determined device to be detected with a preset value. For example, the processor can determine that the pixel mark of the device to be detected has a preset value of 1, and can determine that the pixel mark of the background image has a preset value of 0.
[0047] In one embodiment, the preset color threshold is set according to the difference in color components between the device to be detected and the background image in at least one color channel.
[0048] In order to better distinguish the pixels of the device to be detected from the pixels of the background image, the preset color threshold can be set according to the color component difference between the device to be detected and the background image in at least one color channel. The color component of each pixel in the device image and the background image involves three color channels, which can include three channels of R, G and B, that is, three channels of red, green and blue. The component value of each color channel can be 0 to 255.
[0049] In one embodiment, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the device gap height, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the device image covered by the detection area along the height scanning direction, and determining the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected; determining the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected; and determining the device height of the device to be detected according to the spacing distance obtained by multiple scans includes: determining the device height of the device to be detected according to the gap height obtained by multiple scans.
[0050] The processor can scan the device image covered by the detection area along the height scanning direction, and determine the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected. Among them, the starting point of the height scanning direction can be located at the preset reference plane. The scanning method can be to scan the device image line by line. The preset value can be expressed as a pixel mark preset value of the device to be detected. When the lower boundary of the device to be detected is determined, the processor can determine the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected. Among them, the preset reference plane can refer to the plane where the device to be detected is placed in the detection device. For example, the preset reference plane can refer to the glass turntable of the detection device. The processor can scan the device image covered by the detection area multiple times along the height scanning direction, and according to the gap height of the device to be detected obtained by multiple scans, the processor can determine the device height of the device to be detected.
[0051] In one embodiment, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the overall height of the device, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the detection area along the height scanning direction, and determining the last scanned pixel point marked as a preset value as the upper boundary of the device to be detected; determining the spacing distance between the upper boundary and the preset reference plane as the overall device height of the device to be detected; determining the device height of the device to be detected according to the spacing distance determined by multiple scans includes: determining the device height of the device to be detected according to the overall device height determined by multiple scans.
[0052] The processor can scan the device image covered by the detection area along the height scanning direction, and determine the last scanned pixel point marked as the preset value as the upper boundary of the device to be detected. Among them, the starting point of the height scanning direction can be located at the preset reference plane. The scanning method can be to scan the device image line by line. The preset value can be expressed as a pixel mark preset value of the device to be detected. When the upper boundary of the device to be detected is determined, the processor can determine the spacing distance between the upper boundary and the preset reference plane as the overall height of the device to be detected. Among them, the preset reference plane can refer to the plane where the device to be detected is placed in the detection device. For example, the preset reference plane can refer to the glass turntable of the detection device. The processor can scan the device image covered by the detection area multiple times along the height scanning direction, and according to the overall height of the device to be detected obtained by multiple scans, the processor can determine the device height of the device to be detected.
[0053] In one embodiment, the method also includes: dividing the detection area into multiple area segments along a direction perpendicular to the height scanning direction; and scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected, including: scanning the device image in the detection area multiple times along the height scanning direction, and obtaining multiple spacing distances each time; in each area segment, obtaining the segment height corresponding to the area segment according to the multiple spacing distances corresponding to the area segment; and determining the device height of the device to be detected according to the spacing distances determined by multiple scans includes: determining the device height of the device to be detected according to the segment heights corresponding to the multiple area segments.
[0054] The processor can divide the detection area into multiple area segments along a direction perpendicular to the height scanning direction. Therefore, when scanning the device image in the detection area along the height scanning direction, the processor can scan the device image multiple times in the detection area along the height scanning direction, and obtain multiple spacing distances each time. Among them, the spacing distance can refer to the spacing distance between the detected boundary of the device to be detected and the preset reference plane. In each area segment, the processor can obtain the segment heights corresponding to the multiple area segments according to the multiple spacing distances corresponding to the area segment. According to the segment heights corresponding to the multiple area segments, the processor can determine the device height of the device to be detected.
[0055] Furthermore, in one embodiment, within each area segment, the segment height corresponding to each area segment is obtained by averaging multiple spacing distances corresponding to the segment; and the device height of the device to be detected is determined by averaging the segment heights corresponding to multiple area segments.
[0056] In each area segment, the processor may calculate the average value of multiple spacing distances corresponding to the area segment to obtain the segment heights corresponding to the multiple area segments. The spacing distance may refer to the spacing distance between the detected boundary of the device to be detected and the preset reference plane. Multiple area segments correspond to multiple segment heights. After obtaining the segment heights corresponding to the multiple area segments, the processor may calculate the average value of the segment heights to determine the device height of the device to be detected.
[0057] By first taking the average value in sections and then determining the height of the device to be detected, the amount of calculation can be reduced, the detection efficiency can be improved, and the influence of noise in the device image on the detection result can be avoided.
[0058] In one embodiment, the method further includes: when the deviation between the device height and the target height is greater than a preset deviation threshold, determining that the device to be detected is an abnormal device; when the deviation is less than or equal to the preset deviation threshold, determining that the device to be detected is a normal device.
[0059] When the deviation between the device height and the target height is greater than a preset deviation threshold, the processor can determine that the device to be detected is an abnormal device. When the deviation is less than or equal to the preset deviation threshold, the processor can determine that the device to be detected is a normal device.
[0060] In one embodiment, generating a detection area in a device image of a device to be detected includes: acquiring a template image corresponding to the device image of the device to be detected, wherein the template image includes a reference device and an initial detection area covering at least one boundary of the reference device; comparing the device image with the template image to determine a position offset between the device to be detected in the device image and the reference device in the template image; and generating a detection area in the device image according to the position offset.
[0061] To generate a detection area in a device image of a device to be detected, the processor may first obtain a template image corresponding to the device image of the device to be detected. The template image may include a reference device and an initial detection area covering at least one boundary of the reference device. The reference device may refer to a device without defects or with negligible defects. In the template image, the detection area of the template image may be marked according to the position of the reference device. The detection area of the template image may refer to an initial detection area covering at least one boundary of the reference device.
[0062] In the actual detection process, the position of the device to be detected may be offset, that is, the detection area of the template image cannot cover the detection area of the device to be detected. For example, when the positions of the image acquisition device that takes the template image and the image acquisition device that takes the device image remain unchanged, but the device to be detected is not put in place or the position of the device to be detected moves during the transmission and detection process after the device is produced, the device in the device image may be offset. In this case, if the detection area of the template image is marked according to the reference device position in the template image, and the detection area is generated in the image to be detected according to the detection area of the template image. At this time, the detection area of the template image may not cover at least one boundary of the device to be detected in the device image, and the result of the device detection will have a large error.
[0063] In order to correct the position offset of the detection area in the image to be detected, the processor can compare the device image with the template image to determine the position offset between the device to be detected in the device image and the reference device in the template image. After determining the position offset, the processor can generate a detection area in the device image according to the position offset. At this time, the relative position relationship between the detection area and the device in the template image is the same as the relative position relationship between the detection area and the device in the device image. Among them, there can be multiple ways to generate the detection area in the device image according to the position offset. For example, the detection area can be generated in the device image first, and then the position of the detection area is adjusted according to the determined position offset to complete the offset correction of the detection area. It can also be that the position offset of the detection area is adjusted while the detection area is generated in the device image according to the position offset to complete the offset correction of the detection area.
[0064] Through the above technical solution, the device height of the device to be detected can be calculated quickly and easily, which can be applied to high-throughput detection scenarios and different detection objects, and has good scalability. Moreover, by determining the device height by the distance between the boundary of the detection device and the preset reference plane, the influence of noise in the device image on the detection result can be avoided. In addition, by taking the average value of the segmented device first and then determining the height of the device to be detected, the amount of calculation can be reduced and the detection efficiency can be improved.
[0065] Figure 1 FIG. 1 is a flow chart of a method for detecting device height in one embodiment. It should be understood that although Figure 1 The steps in the flowchart are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 At least part of the steps may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the sub-steps or stages of other steps.
[0066] In one embodiment, Figure 2 As shown, a device for detecting the height of a device is provided, comprising a detection area determination module, a scanning module and a height determination module, wherein:
[0067] The detection area determination module 201 is used to generate a detection area in the device image of the device to be detected, where the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected; and determine the pixels corresponding to the device to be detected in the device image covered by the detection area.
[0068] The scanning module 202 is used to scan the device image in the detection area along the height scanning direction, and obtain the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected.
[0069] The height determination module 203 is used to determine the device height of the device to be detected according to the spacing distance determined by multiple scans.
[0070] The height of the device is detected, and the detection area determination module 201 can generate a detection area in the device image of the device to be detected, and the detection area covers at least one boundary of the device to be detected in the device image, and indicates the height scanning direction for the device to be detected. Specifically, the detection area determination module 201 can obtain a template image corresponding to the device image of the device to be detected, wherein the template image includes a reference device and an initial detection area covering at least one boundary of the reference device. The reference device may refer to a device without defects or with negligible defects. In the template image, the detection area of the template image can be marked according to the position of the reference device. The detection area of the template image may refer to an initial detection area covering at least one boundary of the reference device.
[0071] After acquiring the template image, the detection area determination module 201 can compare the device image with the template image to determine the position offset between the device to be detected in the device image and the reference device in the template image. The detection area determination module 201 can generate a detection area in the device image according to the position offset. At this time, the relative position relationship between the detection area and the device in the template image is the same as the relative position relationship between the detection area and the device in the device image.
[0072] After generating the detection area, the detection area determination module 201 can determine the pixels corresponding to the device to be detected in the device image covered by the detection area. Specifically, the detection area determination module 201 can perform threshold segmentation on the image area covered by the detection area by a preset diffraction threshold to determine the pixels of the device to be detected in the image area covered by the detection area. Among them, threshold segmentation can be understood as defining the area of the device to be detected and the background area in which it is located by means of a preset color threshold. The detection area determination module 201 can mark the pixels of the determined device to be detected with a preset value. For example, the detection area determination module 201 can determine that the pixel mark preset value of the device to be detected is 1, and can determine that the pixel mark preset value of the background image is 0.
[0073] After determining the pixels corresponding to the device to be detected, the scanning module 202 can be used to scan the device image in the detection area along the height scanning direction, and obtain the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected.
[0074] The scanning module 202 can scan the device image covered by the detection area along the height scanning direction, and determine the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected. Among them, the starting point of the height scanning direction can be located at the preset reference plane. The scanning method can be to scan the device image line by line. The preset value can be expressed as a pixel mark preset value of the device to be detected. When the lower boundary of the device to be detected is determined, the scanning module 202 can determine the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected. Among them, the preset reference plane can refer to the plane where the device to be detected is placed in the detection device. For example, the preset reference plane can refer to the glass turntable of the detection device. The scanning module 202 can scan the device image covered by the detection area multiple times along the height scanning direction, and according to the gap height of the device to be detected obtained by multiple scans, the height determination module 203 can determine the device height of the device to be detected.
[0075] The scanning module 202 can scan the device image covered by the detection area along the height scanning direction, and determine the pixel point marked as the preset value scanned at the end as the upper boundary of the device to be detected. Among them, the starting point of the height scanning direction can be located at the preset reference plane. The scanning method can be to scan the device image line by line. The preset value can be expressed as a pixel mark preset value of the device to be detected. When the upper boundary of the device to be detected is determined, the scanning module 202 can determine the spacing distance between the upper boundary and the preset reference plane as the overall height of the device to be detected. Among them, the preset reference plane can refer to the plane where the device to be detected is placed in the detection device. For example, the preset reference plane can refer to the glass turntable of the detection device. The scanning module 202 can scan the device image covered by the detection area multiple times along the height scanning direction, and according to the overall height of the device to be detected obtained by multiple scans, the height determination module 203 can determine the device height of the device to be detected.
[0076] The scanning module 202 can divide the detection area into multiple area segments along a direction perpendicular to the height scanning direction. Therefore, when scanning the device image in the detection area along the height scanning direction, the scanning module 202 can scan the device image multiple times in the detection area along the height scanning direction, and obtain multiple spacing distances each time. Among them, the spacing distance can refer to the spacing distance between the detected boundary of the device to be detected and the preset reference plane. In each area segment, the scanning module 202 can obtain the segment heights corresponding to the multiple area segments according to the multiple spacing distances corresponding to the area segment. According to the segment heights corresponding to the multiple area segments, the height determination module 203 can determine the device height of the device to be detected.
[0077] The device for detecting the height of a device includes a processor and a memory. The detection area determination module, scanning module and height determination module are all stored in the memory as program units, and the processor executes the program modules stored in the memory to implement corresponding functions.
[0078] The processor includes a kernel, and the kernel calls the corresponding program unit from the memory. One or more kernels can be set, and the method for detecting the height of the device can be implemented by adjusting the kernel parameters.
[0079] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0080] An embodiment of the present application provides a storage medium on which a program is stored. When the program is executed by a processor, the above-mentioned method for detecting the height of a device is implemented.
[0081] An embodiment of the present application provides a processor, which is used to run a program, wherein the method for detecting the height of a device is executed when the program is run.
[0082] An embodiment of the present application provides an electronic device, including a processor and a memory, wherein the processor and the memory are connected via a bus, and a computer program is stored in the memory. When the computer program is called by the processor, the above-mentioned method for detecting the height of a device is executed.
[0083] In one embodiment, a computer device is provided. The computer device may refer to the electronic device described above. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 3As shown. The computer device includes a processor A01, a network interface A02, a memory (not shown in the figure) and a database (not shown in the figure) connected via a system bus. Among them, the processor A01 of the computer device is used to provide computing and control capabilities. The memory of the computer device includes an internal memory A03 and a non-volatile storage medium A04. The non-volatile storage medium A04 stores an operating system B01, a computer program B02 and a database (not shown in the figure). The internal memory A03 provides an environment for the operation of the operating system B01 and the computer program B02 in the non-volatile storage medium A04. The database of the computer device is used to store data such as the device height of the device to be detected. The network interface A02 of the computer device is used to communicate with an external terminal through a network connection. When the computer program B02 is executed by the processor A01, a method for detecting the height of a device is implemented.
[0084] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0085] An embodiment of the present application provides a device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are implemented: generating a detection area in a device image of the device to be detected, the detection area covering at least one boundary of the device to be detected in the device image, and indicating a height scanning direction for the device to be detected; determining pixels corresponding to the device to be detected in the device image covered by the detection area; scanning the device image within the detection area along the height scanning direction, and obtaining a spacing distance between a boundary of the device to be detected and a preset reference plane based on the pixels corresponding to the device to be detected; and determining a device height of the device to be detected based on the spacing distance determined through multiple scans.
[0086] In one embodiment, scanning the device image within the detection area along the height scanning direction includes: determining whether a preset scanning direction is consistent with the height scanning direction indicated by the detection area; when it is determined that the preset scanning direction is inconsistent with the height scanning direction, rotating the device image and the detection area so that the height scanning direction of the device in the rotated device image is consistent with the preset scanning direction.
[0087] In one embodiment, determining pixels corresponding to the device to be detected in the device image covered by the detection area includes: performing threshold segmentation on the image area covered by the detection area by a preset color threshold to determine the pixels of the device to be detected in the image area covered by the detection area, and marking the determined pixels of the device to be detected with a preset value, wherein the preset color threshold is used to distinguish the pixels of the device to be detected from the pixels of the background image.
[0088] In one embodiment, the preset color threshold is set according to the difference in color components between the device to be detected and the background image in at least one color channel.
[0089] In one embodiment, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the device gap height, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the device image covered by the detection area along the height scanning direction, and determining the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected; determining the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected; and determining the device height of the device to be detected according to the spacing distance obtained by multiple scans includes: determining the device height of the device to be detected according to the gap height obtained by multiple scans.
[0090] In one embodiment, when the starting point of the height scanning direction is located at a preset reference plane and the device height is the overall height of the device, the device image is scanned in the detection area along the height scanning direction, and the spacing distance between the boundary of the device to be detected and the preset reference plane is obtained according to the pixels corresponding to the device to be detected, including: scanning the detection area along the height scanning direction, and determining the last scanned pixel point marked as a preset value as the upper boundary of the device to be detected; determining the spacing distance between the upper boundary and the preset reference plane as the overall device height of the device to be detected; determining the device height of the device to be detected according to the spacing distance determined by multiple scans includes: determining the device height of the device to be detected according to the overall device height determined by multiple scans.
[0091] In one embodiment, the method also includes: dividing the detection area into multiple area segments along a direction perpendicular to the height scanning direction; and scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected, including: scanning the device image in the detection area multiple times along the height scanning direction, and obtaining multiple spacing distances each time; in each area segment, obtaining the segment height corresponding to the area segment according to the multiple spacing distances corresponding to the area segment; and determining the device height of the device to be detected according to the spacing distances determined by multiple scans includes: determining the device height of the device to be detected according to the segment heights corresponding to the multiple area segments.
[0092] In one embodiment, within each area segment, the segment height corresponding to each area segment is obtained by averaging multiple spacing distances corresponding to the segment; and the device height of the device to be detected is determined by averaging the segment heights corresponding to multiple area segments.
[0093] In one embodiment, the method further includes: when the deviation between the device height and the target height is greater than a preset deviation threshold, determining that the device to be detected is an abnormal device; when the deviation is less than or equal to the preset deviation threshold, determining that the device to be detected is a normal device.
[0094] In one embodiment, generating a detection area in a device image of a device to be detected includes: acquiring a template image corresponding to the device image of the device to be detected, wherein the template image includes a reference device and an initial detection area covering at least one boundary of the reference device; comparing the device image with the template image to determine a position offset between the device to be detected in the device image and the reference device in the template image; and generating a detection area in the device image according to the position offset.
[0095] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program initialized with the above-mentioned method steps for detecting the height of a device.
[0096] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0097] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0098] These computer program instructions may also be stored in a computer readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0099] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0100] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0101] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0102] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0103] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0104] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.
Claims
1. A method for detecting the height of a device, characterized in that: The method comprises: Generate a detection area in a device image of the device to be detected, wherein the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected; Determining pixels corresponding to the device to be detected in the device image covered by the detection area; Scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and a preset reference plane according to the pixels corresponding to the device to be detected; Determine the device height of the device to be detected according to the spacing distance determined by multiple scans; Wherein, determining the pixels corresponding to the device to be detected in the device image covered by the detection area includes: performing threshold segmentation on the image area covered by the detection area by a preset color threshold to determine the pixels of the device to be detected in the image area covered by the detection area, and marking the determined pixels of the device to be detected with a preset value, wherein the preset color threshold is used to distinguish the pixels of the device to be detected from the pixels of the background image; The spacing distance between the boundary of the device to be detected and the preset reference plane is determined by any of the following methods: In the case where the starting point of the height scanning direction is located at the preset reference plane, and the device height is the device gap height, the device image covered by the detection area is scanned along the height scanning direction, and the pixel point marked as the preset value scanned for the first time is determined as the lower boundary of the device to be detected; the spacing distance between the lower boundary and the preset reference plane is determined as the gap height of the device to be detected; and determining the device height of the device to be detected according to the spacing distance obtained by multiple scans includes: determining the device height of the device to be detected according to the gap height obtained by multiple scans; When the starting point of the height scanning direction is located at the preset reference plane and the device height is the overall height of the device, the detection area is scanned along the height scanning direction, and the pixel point marked as the preset value scanned last is determined as the upper boundary of the device to be detected; the spacing distance between the upper boundary and the preset reference plane is determined as the overall device height of the device to be detected; determining the device height of the device to be detected based on the spacing distance determined by multiple scans includes: determining the device height of the device to be detected based on the overall device height determined by multiple scans.
2. The method for detecting the height of a device according to claim 1, characterized in that: The scanning of the device image within the detection area along the height scanning direction comprises: Determining whether the preset scanning direction is consistent with the height scanning direction indicated by the detection area; When it is determined that the preset scanning direction is inconsistent with the height scanning direction, the device image and the detection area are rotated so that the height scanning direction of the device in the rotated device image is consistent with the preset scanning direction.
3. The method for detecting the height of a device according to claim 1, characterized in that: The preset color threshold is set according to the color component difference between the device to be detected and the background image in at least one color channel.
4. The method for detecting the height of a device according to claim 1, characterized in that: The method further comprises: Dividing the detection area into a plurality of area segments along a direction perpendicular to the height scanning direction; Furthermore, scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected includes: Scanning the device image in the detection area multiple times along the height scanning direction, and obtaining multiple spacing distances each time; In each area segment, a segment height corresponding to the area segment is obtained according to a plurality of spacing distances corresponding to the area segment; Furthermore, determining the device height of the device to be detected according to the spacing distance determined by multiple scans includes: The device height of the device to be detected is determined according to the segment heights corresponding to the multiple area segments.
5. The method for detecting the height of a device according to claim 4, characterized in that: In each area segment, a segment height corresponding to each area segment is obtained by averaging a plurality of spacing distances corresponding to the segment; Furthermore, the device height of the device to be detected is determined by averaging the segment heights corresponding to the multiple area segments.
6. The method for detecting the height of a device according to any one of claims 1 to 5, characterized in that: The method further comprises: When the deviation between the device height and the target height is greater than a preset deviation threshold, the device to be detected is determined to be an abnormal device; when the deviation is less than or equal to the preset deviation threshold, the device to be detected is determined to be a normal device.
7. The method for detecting the height of a device according to any one of claims 1 to 5, characterized in that: Generating a detection area in a device image of a device to be detected includes: Acquire a template image corresponding to the device image of the device to be detected, wherein the template image includes a reference device and an initial detection area covering at least one boundary of the reference device; Comparing the device image with the template image to determine a position offset between the device to be detected in the device image and the reference device in the template image; An inspection area is generated in the device image according to the position shift amount.
8. The method for detecting the height of a device according to any one of claims 1 to 5, characterized in that: The detection area is a rotatable rectangular area.
9. A device for detecting the height of a device, characterized in that: The device comprises: A detection area determination module, used to generate a detection area in a device image of a device to be detected, wherein the detection area covers at least one boundary of the device to be detected in the device image and indicates a height scanning direction for the device to be detected; determine pixels corresponding to the device to be detected in the device image covered by the detection area, wherein determining pixels corresponding to the device to be detected in the device image covered by the detection area includes: performing threshold segmentation on the image area covered by the detection area by a preset color threshold to determine pixels of the device to be detected in the image area covered by the detection area, and marking the determined pixels of the device to be detected with a preset value, wherein the preset color threshold is used to distinguish pixels of the device to be detected from pixels of a background image; A scanning module, used for scanning the device image in the detection area along the height scanning direction, and obtaining the spacing distance between the boundary of the device to be detected and the preset reference plane according to the pixels corresponding to the device to be detected, wherein the spacing distance between the boundary of the device to be detected and the preset reference plane is determined by any one of the following methods: when the starting point of the height scanning direction is located at the preset reference plane and the device height is the device gap height, scanning the device image covered by the detection area along the height scanning direction, determining the pixel point marked as the preset value scanned for the first time as the lower boundary of the device to be detected; determining the spacing distance between the lower boundary and the preset reference plane as the gap height of the device to be detected; and , the device height of the device to be detected according to the spacing distance obtained by multiple scans includes: determining the device height of the device to be detected according to the gap height obtained by multiple scans; when the starting point of the height scanning direction is located at the preset reference plane and the device height is the overall height of the device, scanning the detection area along the height scanning direction, and determining the pixel point marked as the preset value scanned last as the upper boundary of the device to be detected; determining the spacing distance between the upper boundary and the preset reference plane as the overall device height of the device to be detected; the device height of the device to be detected according to the spacing distance determined by multiple scans includes: determining the device height of the device to be detected according to the overall device height determined by multiple scans; The height determination module is used to determine the device height of the device to be detected according to the spacing distance determined by multiple scans.
10. A machine-readable storage medium having instructions stored thereon, characterized in that: When the instruction is executed by a processor, the processor is configured to perform the method for detecting the height of a device according to any one of claims 1 to 8.
11. An electronic device, comprising a processor and a memory, wherein the processor and the memory are connected via a bus, wherein: A computer program is stored in the memory, and when the computer program is called by the processor, the method for detecting the height of a component according to any one of claims 1 to 8 is executed.
Citation Information
Patent Citations
Object boundary line determination method and device, electronic equipment and storage medium
CN112686919A
Height measurement method, terminal equipment and computer storage medium
CN113077476A