Device direction detection method, device, storage medium and electronic equipment
By comparing and rotary correction of the central symmetric detection area between the template image and the image to be tested, the problem of noise interference in device detection is solved, and efficient and accurate device direction recognition is achieved.
Patent Information
- Application Number
- CN202111565341.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-20
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2041-12-20
AI Technical Summary
In the prior art, in device detection, especially when the left and right differences are not obvious, noise can easily lead to problems inability to identify the device direction, resulting in inaccurate detection.
By acquiring the template image and the image to be tested, the center symmetrical detection area is used for offset correction and rotation comparison, the device direction is determined, and threshold segmentation and gradient direction comparison are used to reduce the impact of noise.
It improves the accuracy of device direction detection, reduces calculation amount and resource usage, avoids noise interference, and meets high-throughput detection needs.
Smart Images

Figure CN114494119B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of device detection, and in particular to a device direction detection method, device, storage medium and electronic equipment. Background Art
[0002] Typically, after devices are manufactured, they need to be inspected for defects before shipment to eliminate those with quality defects. This defect detection typically requires specialized testing equipment. With the continuous advancement of technology, the structural complexity of various devices and the production capacity of devices are constantly increasing, which in turn places higher demands on device testing equipment.
[0003] Visual inspection equipment is a common type of inspection equipment. Typically, multiple cameras are installed in a visual inspection system to capture images of a device from different angles. The system's algorithms process and analyze the images captured by each camera. Currently, many devices on the market have asymmetrical structures, and different structures may exhibit different defects. Consequently, different algorithms are required to detect different locations within the device to determine if any anomalies exist.
[0004] In many current 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. This requires the algorithm to complete the detection of the orientation of the device in the image in a very short time, so as to determine whether the device is good or defective before unloading, and thus store the device in the correct material box when unloading. Although the existing image processing algorithms are capable of detecting whether the device is reversed, most of these existing algorithms need to identify a specific object at a specific position in the device, and determine whether the orientation of the device is correct based on the position of the identified object. However, object recognition algorithms often have problems such as large computational complexity, high resource usage, and long time consumption. In addition, object recognition algorithms are easily affected by a lot of noise. Especially when the left and right differences of the device are not very obvious, it is very likely that the noise in the image will make it impossible to find the specific object and thus fail to identify the orientation of the device. Summary of the Invention
[0005] The purpose of the present invention is to overcome the problem in the prior art that when the left and right differences are not obvious, the specific object cannot be found due to noise and the direction of the device cannot be identified. A method, device, storage medium and electronic device for detecting the direction of the device are provided.
[0006] In order to achieve the above object, the present invention provides a method for detecting the direction of a device, comprising:
[0007] Acquire a template image containing a sample device and an image to be tested containing a device to be tested, wherein the template image contains a plurality of first detection areas, the first detection areas cover a characteristic portion of the sample device that characterizes the orientation of the sample device, and the plurality of first detection areas are centrally symmetrical;
[0008] Performing offset correction on the image to be tested based on the template image so that the device to be tested in the image to be tested and the sample device in the template image are positioned in the same position in their respective images;
[0009] generating a second detection area in the image to be detected according to the position of the first detection area in the template image;
[0010] Comparing the image area covered by the first detection area with the image area covered by the second detection area to obtain a first comparison result;
[0011] Rotating the image area covered by the first detection area so that the rotated first detection area is located at the position when the sample device appears reversed;
[0012] Comparing the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result;
[0013] The direction of the device to be detected is determined according to the first comparison result and the second comparison result.
[0014] In one embodiment of the present application, a threshold segmentation is performed on the template image using a preset threshold to obtain pixels corresponding to the feature part; when the template image is in an initial position, the position and maximum gradient direction of the pixels of the feature part are determined and saved; the template image is rotated so that the pixel points of the feature part are located at the position when the sample device appears reversed, and the position and maximum gradient direction of the pixels of the rotated feature part are determined and saved.
[0015] In one embodiment of the present application, when obtaining the first comparison result and the second comparison result, the comparison is based on the saved pixel positions and maximum gradient directions of the feature parts before and after rotation.
[0016] In one embodiment of the present application, before comparing the image area covered by the first detection area with the image area covered by the second detection area, it also includes: performing threshold segmentation on the image area covered by the second detection area through a preset threshold, obtaining characteristic pixels of the characteristic part in the image to be tested, and determining the maximum gradient direction of the characteristic pixels, wherein the preset threshold is set based on the color difference between the characteristic part and the background area in at least one color channel.
[0017] In one embodiment of the present application, comparing the image area covered by the first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested; and comparing the image area covered by the rotated first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the rotated template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested.
[0018] In one embodiment of the present application, the area of the second detection area is larger than that of the first detection area, and each second detection area includes the first detection area located at a corresponding position.
[0019] In one embodiment of the present application, when the first comparison result and the second comparison result are obtained by comparison, the position and / or angle of the first detection area are adjusted multiple times within the coverage range of the corresponding second detection area, and a comparison is performed after each adjustment of the position and / or angle, and the comparison result with the highest similarity is used as the first comparison result or the second comparison result.
[0020] A second aspect of the present application provides a device for detecting a device direction, comprising:
[0021] An image acquisition module, configured to acquire a template image containing a sample device and an image to be tested containing a device to be tested, wherein the template image includes a plurality of first detection regions, the first detection regions covering a characteristic portion of the sample device that characterizes the orientation of the sample device, and the plurality of first detection regions are centrally symmetrical;
[0022] A correction module, configured to perform offset correction on the image to be tested based on the template image, so that the positions of the device in the image to be tested and the device in the template image are the same in their respective images;
[0023] A detection area determination module, configured to generate a second detection area in the image to be detected based on the position of the first detection area in the template image;
[0024] a first comparison module, configured to compare an image area covered by the first detection area with an image area covered by the second detection area to obtain a first comparison result;
[0025] An image processing module, configured to rotate the image area covered by the first detection area so that the rotated first detection area is located at a position when the sample device is reversed;
[0026] a second comparison module, configured to compare the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result;
[0027] The direction detection module is used to determine the direction of the device to be detected according to the first comparison result and the second comparison result.
[0028] A third aspect of the present application provides a machine-readable storage medium having instructions stored thereon. When the instructions are executed by a processor, the processor is configured to execute a device orientation detection method according to any one of the above items.
[0029] The fourth aspect of the present application provides an electronic device, including a processor and a memory, the processor and the memory are connected via a bus, a computer program is stored in the memory, and when the computer program is called by the processor, a device direction detection method according to any one of the above items is executed.
[0030] In the above technical solution, by determining the first detection area in the template image and the second detection area in the image to be detected, the gradient change direction of the pixel points in the specific area of the image to be detected and the template image is compared, which not only can obtain accurate comparison results, but also can save complex calculations, and at the same time avoid the adverse effects of noise in the image and brightness changes on the detection results.
[0031] Other features and advantages of the embodiments of the present application will be described in detail in the subsequent detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] 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 detailed description, 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:
[0033] Figure 1 The following schematically shows a flow chart of a method for detecting the orientation of a device according to an embodiment of the present application;
[0034] Figure 2 Schematically shows a structural block diagram of a device for detecting device direction according to an embodiment of the present application;
[0035] Figure 3 The following schematically shows a structural block diagram of an electronic device according to an embodiment of the present application;
[0036] Figure 4 The internal structure diagram of a computer device according to an embodiment of the present application is schematically shown. DETAILED DESCRIPTION
[0037] The following describes the specific embodiments of the present application in detail with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only used to illustrate and explain the present application and are not intended to limit the present application.
[0038] It should be noted that if the embodiments of the present application involve directional indications (such as up, down, left, right, front, back, etc.), the directional indications are only used to explain the relative position relationship, movement status, etc. between the various components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indications will also change accordingly.
[0039] In addition, if there are descriptions involving "first", "second", etc. in the embodiments of the present application, the descriptions of "first", "second", etc. are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the fact that they can be implemented by ordinary technicians in this field. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such a combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0040] like Figure 1 As shown, a schematic diagram of the process of the device direction detection method according to an embodiment of the present application is shown. Figure 1 As shown, in one embodiment of the present application, a method for detecting the direction of a device is provided, comprising the following steps:
[0041] Step 101: Acquire a template image containing a sample device and an image to be tested containing a device to be tested, wherein the template image contains a plurality of first detection regions, the first detection regions covering a characteristic portion of the sample device that characterizes the orientation of the sample device, and the plurality of first detection regions are centrally symmetrical.
[0042] Step 102 , performing offset correction on the image to be tested based on the template image, so that the device to be tested in the image to be tested and the sample device in the template image are positioned in the same position in their respective images;
[0043] Step 103: generating a second detection area in the image to be detected according to the position of the first detection area in the template image;
[0044] Step 104: Compare the image area covered by the first detection area with the image area covered by the second detection area to obtain a first comparison result;
[0045] Step 105 , rotating the image area covered by the first detection area so that the rotated first detection area is located at the position when the sample device is reversed;
[0046] Step 106, comparing the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result;
[0047] Step 107 : Determine the direction of the device to be detected according to the first comparison result and the second comparison result.
[0048] A processor may obtain a template image containing a sample device and an image to be inspected containing a device to be inspected. The template image includes multiple first inspection areas, each covering a characteristic portion of the sample device that characterizes its orientation, wherein the characteristic portion may be an edge of the sample device. Furthermore, the multiple first inspection areas may be centrally symmetrical. For example, one area may represent the upper left corner of the sample device and another area may represent the lower right corner of the sample device. After determining the multiple first inspection areas in the template image, the processor may perform offset correction on the image to be inspected based on the template image, thereby aligning the positions of the device to be inspected in the image to be inspected and the sample device in the template image. After aligning the positions of the device to be inspected in the image to be inspected and the sample device in the template image, the processor may generate corresponding second inspection areas in the image to be inspected based on the determined positions of the first inspection areas in the template image. For example, assuming the template image has two first inspection areas, located in the upper left and lower right corners of the template image, the upper left and lower right corners of the image to be inspected may be determined as second inspection areas.
[0049] In one embodiment, the area of the second detection zone is larger than that of the first detection zone, and each second detection zone includes the first detection zone located at a corresponding position.
[0050] The area of the second detection area of the image to be tested is larger than the area of the first detection area of the template image, and the second detection area of each image to be tested includes the first detection area located at the corresponding position. After the processor determines the first detection area in the template image and the second detection area in the image to be tested, it can compare the image area covered by the first detection area with the image area covered by the second detection area, thereby obtaining a first comparison result. For example, the processor determines the first detection area in the upper left corner of the template image as area A, and determines the first detection area in the lower right corner of the template image as area B. The second detection area in the upper left corner of the image to be tested is determined as area C, and the second detection area in the lower right corner of the image to be tested is determined as area D. The processor can compare the image area covered by area A in the template image with area C in the image to be tested, and compare the image area covered by area B in the template image with area D in the image to be tested, thereby obtaining a first comparison result.
[0051] The processor may rotate the image area covered by the first detection area of the template image so that the rotated first detection area of the template image is located at the position where the sample device appears reversed. For example, the first detection area in the upper left corner of the template image is determined as area A, and the first detection area in the lower right corner of the template image is determined as area B. After rotating the image area, the first detection area in the upper left corner of the template image can be determined as area B, and the first detection area in the lower right corner of the template image can be determined as area A.
[0052] After the processor rotates the image area covered by the first detection area of the template image, it can compare the image area covered by the rotated first detection area with the area covered by the second detection area, thereby obtaining a second comparison result. For example, when the processor rotates the image area covered by the first detection area of the template image, the first detection area in the upper left corner of the template image is area B, and the first detection area in the lower right corner of the template image is area A. The processor can compare the image area covered by the first detection area B in the upper left corner of the rotated template image with area C in the image to be detected, and compare the image area covered by the first detection area A in the lower right corner of the rotated template image with area D in the image to be detected, thereby obtaining a second comparison result. After obtaining the first comparison result and the second comparison result, the processor can determine the direction of the device to be detected based on the comparison results.
[0053] In one embodiment, when the first comparison result and the second comparison result are obtained by comparison, the position and / or angle of the first detection area are adjusted multiple times within the coverage range of the corresponding second detection area, and a comparison is performed after each adjustment of the position and / or angle, and the comparison result with the highest similarity is used as the first comparison result or the second comparison result.
[0054] When the processor obtains the first comparison result and the second comparison result through comparison, because the area of the second detection area of the image to be tested is larger than the area of the first detection area of the template image and covers the area of the first detection area, the processor may adjust the position and / or angle of the first detection area of the template image multiple times within the range covered by the second detection area of the corresponding image to be tested. After each adjustment of the first detection area of the template image, a comparison may be performed again, and the comparison result with the highest similarity shall be determined as the final first comparison result or second comparison result.
[0055] For example, when obtaining the first comparison result, the processor can compare the first detection area A in the upper left corner of the template image at the initial position with the second detection area C in the upper left corner of the image to be tested, and area C can completely cover area A. Area A can be rotated and translated within the coverage range of area C, and each time an adjustment is made, the processor compares the pixel points of the characteristic part of area A with the characteristic pixel points of the characteristic part of area C to obtain a score. Similarly, area B in the lower right corner of the template image at the initial position and area D in the lower right corner of the image to be tested are also adjusted and compared. Moreover, the adjustments of the multiple first detection areas in the corresponding template image are synchronized with each other, that is, each time the angle of the first detection area A is adjusted, the angle of the first detection area B must also be adjusted accordingly, and the direction and amplitude of the angle adjustment are consistent. Similarly, each time the first detection area A is translated, the angle of the first detection area B must also be translated accordingly, and the direction and amplitude of the translation are consistent. After each adjustment, a score needs to be obtained based on the comparison results of the first detection area A and the second detection area C, and the comparison results of the first detection area B and the second detection area D. After multiple adjustments, multiple scores can be obtained, and the highest score is used as the first comparison result.
[0056] For another example, when obtaining the second comparison result, the processor can compare the first detection area B in the upper left corner of the rotated template image with the second detection area C in the upper left corner of the image to be tested, and area C can completely cover area B. Area B can be rotated and translated within the coverage range of area C, and each time an adjustment is made, the processor compares the pixel points of the characteristic part of area B with the characteristic pixel points of the characteristic part of area C to obtain a score. Similarly, area A in the lower right corner of the rotated template image and area D in the lower right corner of the image to be tested are also adjusted and compared synchronously. Multiple scores can be obtained after multiple adjustments, and the highest score is used as the second comparison result.
[0057] During actual device inspection, features within the device are often not readily apparent. If the score is determined based on a single comparison without multiple adjustments to the position and angle to determine the highest score, even when the device orientation is correct, the score may be very low due to noise and inaccurate coverage of the inspection area, leading to false detections. By performing multiple comparisons using angle and translation adjustments and using the highest score as the first comparison result, the goal is to avoid image noise and positional deviations in the second inspection area generated in step 102, thereby more accurately finding the best match between the template image and the image under test, and further improving the accuracy of the inspection results.
[0058] In one embodiment, the template image is threshold segmented by a preset threshold to obtain pixels corresponding to the feature part; when the template image is in an initial position, the position and maximum gradient direction of the pixels of the feature part are determined and saved; the template image is rotated so that the pixel points of the feature part are located at the position when the sample device appears reversed, and the position and maximum gradient direction of the pixels of the rotated feature part are determined and saved.
[0059] The processor can set a preset threshold and perform threshold segmentation on the template image based on the preset threshold to obtain pixels corresponding to the characteristic portion covered by the first detection area in the template image. When the template image is in its initial position, that is, as in the example above, the first detection area in the upper left corner of the template image is area A, and the first detection area in the lower right corner of the template image is area B, the position and maximum gradient direction of the pixels of the characteristic portion covered by the first detection area are determined and saved. After determining and saving the relevant parameters of the characteristic portion covered by the first detection area in the template image in the initial position, the processor can rotate the template image. That is, as in the example above, the first detection area in the upper left corner of the template image is area B, and the first detection area in the lower right corner of the template image is area A. This causes the characteristic portion covered by the first detection area to be reversed, that is, the pixels of the characteristic portion are located at the position where the sample device is reversed. The processor can determine and save the position and maximum gradient direction of the pixels of the characteristic portion covered by the rotated first detection area. Consequently, the processor can directly call upon the saved pixel positions and maximum gradient direction of the template image during subsequent comparisons, eliminating the need to re-determine the pixel positions and maximum gradient direction of the template image for each comparison, thus saving comparison time.
[0060] In one embodiment, when obtaining the first comparison result and the second comparison result, the comparison is based on the saved pixel positions and maximum gradient directions of the feature parts before and after rotation.
[0061] When the processor obtains a first comparison result between the first detection area of the template image and the second detection area of the image to be tested, it can directly call the previously saved positions and maximum gradient directions of the pixels of the characteristic portion covered by the first detection area in the template image for comparison. When the processor obtains a second comparison result between the first detection area of the template image and the second detection area of the image to be tested, it can directly call the previously saved positions and maximum gradient directions of the pixels of the characteristic portion covered by the first detection area in the rotated template image for comparison. This eliminates the need for the processor to re-determine the pixel positions and maximum gradient directions of the template image, saving the time required for comparison.
[0062] In one embodiment, before comparing the image area covered by the first detection area with the image area covered by the second detection area, it also includes: performing threshold segmentation on the image area covered by the second detection area through a preset threshold to obtain characteristic pixels of the characteristic part in the image to be tested, and determining the maximum gradient direction of the characteristic pixels, wherein the preset threshold is set based on the color difference between the characteristic part and the background area in at least one color channel.
[0063] Before comparing the image area covered by the first detection area with the image area covered by the second detection area, the processor may set a preset threshold and use the preset threshold to perform threshold segmentation on the image area covered by the second detection area of the image to be detected, thereby obtaining characteristic pixels of the characteristic portion covered by the second detection area of the image to be detected. The processor also determines the maximum gradient direction corresponding to the characteristic pixels. The preset threshold is set based on the color difference between the characteristic portion and the background area in at least one color channel. In other words, the processor can distinguish the characteristic portion from the background area by setting the color channel.
[0064] In one embodiment, comparing the image area covered by the first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested; and comparing the image area covered by the rotated first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the rotated template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested.
[0065] When the processor compares the image area covered by the first detection area with the image area covered by the second detection area, it can compare the maximum gradient direction of the pixels of the characteristic part covered by the first detection area in the template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the second detection area of the image to be tested. For example, the maximum gradient direction of the pixels of the characteristic part of area A in the upper left of the first detection area in the initial position of the template image is compared with area C in the upper left of the second detection area in the image to be tested. The maximum gradient direction of the pixels of the characteristic part of area B in the lower right of the first detection area in the template image at the initial position (position before rotation) is compared with area D in the lower right of the second detection area in the image to be tested. If the image to be tested is reversed at this time, the characteristic part covered by the second detection area of the image to be tested and the corresponding characteristic pixels will not exist at the position where the pixel point of the characteristic part covered by the first detection area of the template image is located. At this time, the comparison result of a single pixel point can be 0 or empty, and the score of the comparison result will be very low.
[0066] When comparing the image area covered by the first detection area after the template image is rotated with the image area covered by the second detection area, the processor may compare the maximum gradient direction of the pixels in the characteristic portion covered by the first detection area in the rotated template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the second detection area of the image to be tested. For example, the maximum gradient direction of the pixels in area B in the upper left corner of the first detection area after the template image is rotated is compared with area C in the upper left corner of the second detection area in the image to be tested. The maximum gradient direction of the pixels in area A in the lower right corner of the first detection area after the template image is rotated is compared with area D in the lower right corner of the second detection area in the image to be tested.
[0067] Optionally, when comparing the maximum gradient direction of a single pixel in a feature portion of the first detection region in the template image with the maximum gradient direction of a pixel at a corresponding position in the second detection region in the image to be tested, the maximum gradient direction of the single pixel in the template image can be compared with the maximum gradient directions of the pixels covered by the single pixel and the adjacent pixels in the image to be tested, and the result with the highest similarity is used as the comparison result for the single pixel in the template image. For example, assuming that there are three feature pixels X, Y, and Z in the first detection region A, the maximum gradient direction of pixel X can be compared with that of a pixel X' at the same position as pixel X in the second detection region C in the image to be tested, resulting in a comparison result X1. Furthermore, the same comparison is performed on the eight adjacent pixels of X and X', resulting in comparison results X2-X9. The result with the highest score among X1-X9 is then recorded as the comparison result between pixel X and X', denoted as Xn. The same comparison is performed on the other two pixels Y and Z, resulting in Yn and Zn. The comparison score P for the first detection region A and the second detection region C is then determined based on Xn, Yn, and Zn. Similarly, the first detection area B and the second detection area D are compared using the above method to obtain a score Q, and then the first comparison result is obtained based on P and Q. Similarly, the second comparison result can also be obtained using the above method.
[0068] In the case of very small devices, even if both devices are good, the same structure in one device may still have a slight deviation in its position in the two different devices due to manufacturing errors and other factors. The advantage of this approach is that it avoids the problem of mismatching caused by a single one-to-one comparison of two pixels due to device errors. It can find matching pixels within a certain degree of freedom, thereby improving detection accuracy.
[0069] In the above technical solution, by determining the first detection area in the template image and the second detection area in the image to be detected, the gradient change direction of the pixel points in the specific area of the image to be detected and the template image is compared, which not only can obtain accurate comparison results, but also can save complex calculations, and at the same time avoid the adverse effects of noise in the image and brightness changes on the detection results.
[0070] In one embodiment, Figure 2 As shown, a block diagram of a device direction detection device 200 is schematically shown, comprising: an image acquisition module 201, for acquiring a template image containing a sample device and an image to be detected containing a device to be detected, wherein the template image contains a plurality of first detection areas, the first detection areas cover a characteristic portion of the sample device that characterizes the direction of the sample device, and the plurality of first detection areas are in a centrally symmetrical relationship; a correction module 202, for performing offset correction on the image to be detected based on the template image, so that the positions of the device in the image to be detected and the device in the template image are the same in their respective images; a detection area determination module 203, for determining the position of the first detection area in the template image according to the position of the first detection area in the template image; A first comparison module 204 is configured to compare the image area covered by the first detection area with the image area covered by the second detection area to obtain a first comparison result; an image processing module 205 is configured to rotate the image area covered by the first detection area so that the rotated first detection area is located at a position where the sample device appears reversed; a second comparison module 206 is configured to compare the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result; and a direction detection module 207 is configured to determine the direction of the device to be detected based on the first comparison result and the second comparison result.
[0071] The image acquisition module 201 can acquire a template image containing a sample device and an image to be detected containing a device to be detected, wherein the template image contains multiple first detection areas, and the first detection areas cover a characteristic portion of the sample device that characterizes the direction of the sample device, wherein the characteristic portion can be an edge portion of the sample device. In addition, the multiple first detection areas can be centrally symmetrical. For example, the area that characterizes the upper left corner of the sample device and the area that characterizes the lower right corner of the sample device can be used. After the image acquisition module 201 determines the multiple first detection areas in the template image, the correction module 202 can perform offset correction on the image to be detected based on the template image, so that the device to be detected in the image to be detected and the sample device in the template image are in the same position in their respective images.
[0072] After the correction module 202 aligns the positions of the device under test in the image under test and the sample device in the template image in their respective images, the detection area determination module 203 can generate a corresponding second detection area in the image under test based on the determined position of the first detection area in the template image. For example, if the first detection area of the template image is located in the upper left and lower right of the template image, the upper left and lower right of the image under test will be determined as the second detection area.
[0073] After the detection area determination module 203 determines the first detection area in the template image and the second detection area in the image to be detected, the first comparison module 204 can compare the image area covered by the first detection area with the image area covered by the second detection area to obtain a first comparison result.
[0074] The image processing module 205 may rotate the image area covered by the first detection area of the template image so that the first detection area of the rotated template image is located at the position when the sample device appears reversed.
[0075] After the image processing module 205 rotates the image area covered by the first detection area of the template image, the second comparison module 206 can compare the image area covered by the rotated first detection area with the area covered by the second detection area to obtain a second comparison result.
[0076] The direction detection module 207 may determine the direction of the device to be detected according to the first comparison result obtained by the first comparison module 204 and the second comparison result obtained by the second comparison module 206 .
[0077] In one embodiment, a machine-readable storage medium is provided. The machine-readable storage medium stores instructions. When the instructions are executed by a processor, the processor is configured to execute the above-mentioned device orientation detection method.
[0078] In one embodiment, Figure 3 , schematically shows an electronic device 300, including a processor 301 and a memory 302. The processor 301 and the memory 302 are connected via a bus, and the memory 302 stores a computer program, which executes any of the above device orientation detection methods when the computer program is called by the processor 301.
[0079] The processor includes a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the device orientation detection method can be implemented by adjusting the kernel parameters.
[0080] 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.
[0081] An embodiment of the present application provides a storage medium having a program stored thereon, which implements the above-mentioned device direction detection method when executed by a processor.
[0082] An embodiment of the present application provides a processor, which is used to run a program, wherein the above-mentioned device direction detection method is executed when the program is running.
[0083] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4 As 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 images to be tested. 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 device direction detection method is implemented.
[0084] Those skilled in the art will understand that Figure 4 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 shown in the figure, or combine certain components, or have a different component arrangement.
[0085] An embodiment of the present application provides a device, comprising a processor, a memory, and a program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the following steps: obtaining a template image including a sample device and an image to be tested including a device to be tested, wherein the template image includes a plurality of first detection areas, the first detection areas covering characteristic portions of the sample device that characterize the orientation of the sample device, and the plurality of first detection areas being centrally symmetrical; performing offset correction on the image to be tested based on the template image so that the device to be tested in the image to be tested and the sample device in the template image are located in the same position in their respective images; generating a second detection area in the image to be tested based on the position of the first detection area in the template image; comparing an image area covered by the first detection area with an image area covered by the second detection area to obtain a first comparison result; rotating the image area covered by the first detection area so that the rotated first detection area is located at a position where the sample device appears reversed; comparing the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result; and determining the orientation of the device to be tested based on the first comparison result and the second comparison result.
[0086] In one embodiment, the template image is threshold segmented by a preset threshold to obtain pixels corresponding to the feature part; when the template image is in an initial position, the position and maximum gradient direction of the pixels of the feature part are determined and saved; the template image is rotated so that the pixel points of the feature part are located at the position when the sample device appears reversed, and the position and maximum gradient direction of the pixels of the rotated feature part are determined and saved.
[0087] In one embodiment, when obtaining the first comparison result and the second comparison result, the comparison is based on the saved pixel positions and maximum gradient directions of the feature parts before and after rotation.
[0088] In one embodiment, before comparing the image area covered by the first detection area with the image area covered by the second detection area, it also includes: performing threshold segmentation on the image area covered by the second detection area through a preset threshold to obtain characteristic pixels of the characteristic part in the image to be tested, and determining the maximum gradient direction of the characteristic pixels, wherein the preset threshold is set based on the color difference between the characteristic part and the background area in at least one color channel.
[0089] In one embodiment, comparing the image area covered by the first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested; and comparing the image area covered by the rotated first detection area with the image area covered by the second detection area includes: comparing the maximum gradient direction of the pixels of the characteristic part in the rotated template image with the maximum gradient direction of the characteristic pixels located at the corresponding position in the image to be tested.
[0090] In one embodiment, the area of the second detection zone is larger than that of the first detection zone, and each second detection zone includes the first detection zone located at a corresponding position.
[0091] In one embodiment, when the first comparison result and the second comparison result are obtained by comparison, the position and / or angle of the first detection area are adjusted multiple times within the coverage range of the corresponding second detection area, and a comparison is performed after each adjustment of the position and / or angle, and the comparison result with the highest similarity is used as the first comparison result or the second comparison result.
[0092] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can 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 can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0093] 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 produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the steps in the process. 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.
[0094] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0095] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0096] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0097] 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.
[0098] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The 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 disc read-only memory (CD-ROM), digital versatile disc (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 transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0099] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0100] The above are merely 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 modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for detecting the direction of a device, characterized in that: include: Acquire a template image containing a sample device and an image to be tested containing a device to be tested, wherein the template image contains a plurality of first detection areas, the first detection areas cover a characteristic portion of the sample device that characterizes the orientation of the sample device, and the plurality of first detection areas are centrally symmetrical; Performing offset correction on the image to be tested based on the template image so that the device to be tested in the image to be tested and the sample device in the template image are located at the same position in their respective images; generating a second detection area in the image to be detected according to the position of the first detection area in the template image; Comparing an image area covered by the first detection area with an image area covered by the second detection area to obtain a first comparison result; Rotating the image area covered by the first detection area so that the rotated first detection area is located at the position when the sample device appears reversed; Comparing the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result; The direction of the device to be detected is determined according to the first comparison result and the second comparison result.
2. The device direction detection method according to claim 1, characterized in that: Also includes: Performing threshold segmentation on the template image using a preset threshold to obtain pixels corresponding to the feature portion; When the template image is at an initial position, determining and saving the position and maximum gradient direction of the pixels of the feature part; The template image is rotated so that the pixel points of the characteristic portion are located at the position when the sample device appears reversed, and the position and maximum gradient direction of the pixel points of the characteristic portion after rotation are determined and saved.
3. The device direction detection method according to claim 2, characterized in that: Also includes: When obtaining the first comparison result and the second comparison result, the comparison is performed based on the saved pixel positions and maximum gradient directions of the feature parts before and after the rotation.
4. The device direction detection method according to claim 2, characterized in that: Before comparing the image area covered by the first detection area with the image area covered by the second detection area, the method further includes: Using a preset threshold, the image area covered by the second detection area is threshold segmented to obtain characteristic pixels of the characteristic part in the image to be tested, and the maximum gradient direction of the characteristic pixels is determined, wherein the preset threshold is set based on the color difference between the characteristic part and the background area in at least one color channel.
5. The device direction detection method according to claim 4, characterized in that: Comparing the image area covered by the first detection area with the image area covered by the second detection area includes: Comparing the maximum gradient direction of pixels of the characteristic portion in the template image with the maximum gradient direction of characteristic pixels at corresponding positions in the image to be tested; Furthermore, comparing the image area covered by the rotated first detection area with the image area covered by the second detection area includes: The maximum gradient direction of the pixels of the characteristic portion in the rotated template image is compared with the maximum gradient direction of the characteristic pixels at the corresponding position in the image to be tested.
6. The method for detecting the direction of a device according to claim 1, wherein: The area of the second detection area is larger than that of the first detection area, and each second detection area includes the first detection area at a corresponding position.
7. The device direction detection method according to claim 6, characterized in that: Also includes: When the first comparison result and the second comparison result are obtained by comparison, the position and / or angle of the first detection area are adjusted multiple times within the coverage range of the corresponding second detection area, and a comparison is performed after each adjustment of the position and / or angle. The comparison result with the highest similarity is used as the first comparison result or the second comparison result.
8. A device for detecting the direction of a device, characterized in that: include: an image acquisition module, configured to acquire a template image containing a sample device and an image to be tested containing a device to be tested, wherein the template image includes a plurality of first detection areas, the first detection areas covering a characteristic portion of the sample device that characterizes the orientation of the sample device, and the plurality of first detection areas are centrally symmetrical; a correction module, configured to perform offset correction on the image to be tested based on a template image, so that the positions of the device in the image to be tested and the device in the template image are the same in their respective images; a detection area determination module, configured to generate a second detection area in the image to be detected according to a position of the first detection area in the template image; a first comparison module, configured to compare an image area covered by the first detection area with an image area covered by the second detection area to obtain a first comparison result; an image processing module, configured to rotate the image area covered by the first detection area so that the rotated first detection area is located at a position when the sample device appears reversed; a second comparison module, configured to compare the image area covered by the rotated first detection area with the image area covered by the second detection area to obtain a second comparison result; A direction detection module is used to determine the direction of the device to be detected according to the first comparison result and the second comparison result.
9. 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 device orientation detection method according to any one of claims 1 to 7.
10. 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 device orientation according to any one of claims 1 to 7 is executed.
Citation Information
Patent Citations
Price tag detection method and device, electronic equipment and storage medium
CN109961447A
Method and system for detecting image defects, electronic equipment and medium
CN112598627A