Target detection method and device, equipment and storage medium
By obtaining the scaling ratio of the current image and the preset template image and the reference target, the center coordinates of the unidentified target are determined, and the target detection is performed using the second preset model. This solves the problem of insufficient detection accuracy in highly flexible detection scenarios and achieves higher detection accuracy and comprehensiveness.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-20
- Publication Date
- 2026-03-13
AI Technical Summary
In detection scenarios with high flexibility requirements, the accuracy of existing target detection algorithms is difficult to guarantee due to fluctuations in shooting distance and angle deviations caused by human operation.
By obtaining the scaling ratio of the current image and the preset template image and the reference target, the center coordinates of the unidentified target are determined, and the target detection is performed using the second preset model, and the detection results are output.
It improves the accuracy and comprehensiveness of target detection, enabling effective detection even when unidentified targets exist.
Smart Images

Figure CN121661362A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of target detection technology, specifically to a target detection method, apparatus, device, and storage medium. Background Technology
[0002] Currently, deep learning-based visual inspection technology has been widely applied in industrial fields such as automobile manufacturing and electronic assembly. Mainstream solutions mostly adopt object detection algorithms such as YOLO and Faster R-CNN, which are deployed on edge device systems to achieve intelligent detection of component defects and assembly integrity.
[0003] After acquiring the image to be detected, specific detection areas in the image are typically inspected to improve detection accuracy. In highly flexible detection scenarios where fixed cameras and robotic arms are difficult to use, mobile devices must be used for detection. However, due to the uncontrollability of human operation, the shooting process can cause fluctuations in shooting distance and deviations in phone tilt angle, which leads to significant differences in the imaging position of the same target, resulting in reduced accuracy of target detection. Summary of the Invention
[0004] In view of the above problems, this application provides a target detection method, apparatus, device and storage medium, which can accurately determine the area where the unidentified target is located based on the current zoom level and the reference target, thereby realizing target detection and improving the accuracy of target detection.
[0005] The first aspect of this application provides a target detection method, comprising: acquiring a current image of a region to be detected, and performing target detection on the current image using a first preset model to obtain at least one current target; if the number of current targets is less than the number of preset targets, determining a current scaling ratio based on the current targets and their corresponding preset targets; wherein the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in a preset template image corresponding to the current image; determining the center coordinates of at least one unidentified target based on the current scaling ratio and a reference target, thereby determining the distribution area of at least one unidentified target, and performing target detection on the distribution area using a second preset model to output a target detection result; wherein the reference target is selected from at least one current target.
[0006] In some specific embodiments, the step of determining the current scaling ratio based on the current target and its corresponding preset target includes: determining a first ratio of the width of the coordinate frame of the current target to that of the corresponding preset target, and determining a second ratio of the length of the coordinate frame of the current target to that of the corresponding preset target; taking half of the sum of the first ratio and the second ratio as the initial scaling ratio; and weighting and summing the initial scaling ratios corresponding to each current target to obtain the current scaling ratio; wherein the weight of the initial scaling ratio corresponding to the current target is the target detection confidence of the current target.
[0007] In some specific embodiments, the step of determining the center coordinates of at least one unidentified target based on the current scaling ratio and the reference target includes: obtaining the center coordinate difference between the at least one unidentified target and the reference target corresponding to a preset target, and obtaining the planar rotation angle between the current image and the preset template image; determining the center coordinates of the unidentified target based on the current scaling ratio, the center coordinates of the reference target, the center coordinate difference, and the planar rotation angle.
[0008] In some specific embodiments, the step of obtaining the planar rotation angle between the current image and the preset template image includes: determining a first difference between the y-axis coordinate of the center coordinate of the reference target and the y-axis coordinate of the center coordinate of the preset target corresponding to the reference target, and determining a second difference between the x-axis coordinate of the center coordinate of the reference target and the x-axis coordinate of the center coordinate of the preset target corresponding to the reference target; comparing the first difference with the second difference to obtain a ratio, and using the arctangent function value of the ratio as the planar rotation angle between the current image and the preset template image.
[0009] In some specific embodiments, the center coordinates of the reference target include the x-axis coordinate and y-axis coordinate of the reference target's center coordinates, and the center coordinate difference includes the x-axis coordinate difference and the y-axis coordinate difference. The step of determining the center coordinates of the unidentified target based on the current scaling ratio, the center coordinates of the reference target, the center coordinate difference, and the plane rotation angle includes: determining a first product obtained by multiplying the x-axis coordinate difference by the current scaling ratio and then by the cosine of the plane rotation angle; determining a second product obtained by multiplying the x-axis coordinate difference by the current scaling ratio and then by the sine of the plane rotation angle; determining a third product obtained by multiplying the y-axis coordinate difference by the current scaling ratio and then by the sine of the plane rotation angle; determining a fourth product obtained by multiplying the y-axis coordinate difference by the current scaling ratio and then by the cosine of the plane rotation angle; adding the first product to the x-axis coordinate of the reference target's center coordinates and subtracting the third product to obtain the x-axis coordinate of the center coordinates of the unidentified target's target coordinate frame; adding the second product to the y-axis coordinate of the reference target's center coordinates and then adding the fourth product to obtain the y-axis coordinate of the center coordinates of the unidentified target's target coordinate frame.
[0010] In some specific embodiments, the step of determining the distribution area of at least one unidentified target specifically includes: determining the width and length of the coordinate frame of the reference target, and determining the ratio of the width of the coordinate frames of the first preset target and the second preset target corresponding to the reference target in the preset template image, and the ratio of the length of the coordinate frames; determining the width and length of the target coordinate frame based on the width and length of the coordinate frame of the reference target, the ratio of the width of the coordinate frame and the ratio of the length of the coordinate frame, so as to determine the position of the target coordinate frame according to the center coordinates of the target coordinate frame, the width of the target coordinate frame and the length of the target coordinate frame.
[0011] In some specific embodiments, the step of determining the width and length of the target coordinate frame based on the width and length of the reference target's coordinate frame, the ratio of the coordinate frame width to the ratio of the coordinate frame length to the coordinate frame length to obtain an initial width, and multiplying the initial width by a first safety margin coefficient to obtain the width of the target coordinate frame; wherein the first safety margin coefficient is greater than 1; multiplying the length of the reference target's coordinate frame by the ratio of the coordinate frame length to obtain an initial length, and multiplying the initial length by a second safety margin coefficient to obtain the length of the target coordinate frame; wherein the second safety margin coefficient is greater than 1.
[0012] A second aspect of this application provides a target detection apparatus, comprising: an image acquisition module for acquiring a current image of a region to be detected; a first detection module for performing target detection on the current image using a first preset model to obtain at least one current target; a processing module for determining a current scaling ratio based on the current targets and their corresponding preset targets if the number of current targets is less than the number of preset targets; wherein the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in a preset template image corresponding to the current image; determining the center coordinates of at least one unidentified target based on the current scaling ratio and a reference target to determine the distribution area of at least one unidentified target; wherein the reference target is selected from at least one current target; and a second detection module for performing target detection on the distribution area and outputting target detection results.
[0013] A third aspect of this application provides an electronic device, comprising: a processor; and a memory for storing a computer program, wherein the computer program, when executed by the processor, implements the target detection method described above.
[0014] A fourth aspect of this application provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the target detection method as described above.
[0015] The present application possesses at least the following beneficial technical effects: Based on the target detection method, apparatus, device, and storage medium provided in this application, the method includes: acquiring a current image of the region to be detected, and performing target detection on the current image using a first preset model to obtain at least one current target; if the number of current targets is less than the number of preset targets, determining a current scaling ratio based on the current targets and their corresponding preset targets; wherein the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in a preset template image corresponding to the current image; determining the center coordinates of at least one unidentified target based on the current scaling ratio and a reference target, thereby determining the distribution area of at least one unidentified target, and performing target detection on the distribution area using a second preset model to output the target detection result; wherein the reference target is selected from at least one current target. This method can accurately determine the region where the unidentified target is located based on the current scaling ratio and the reference target, thereby achieving target detection and improving the accuracy of target detection.
[0016] The above description is merely an overview of the technical solutions of the embodiments of this application. In order to better understand the technical means of the embodiments of this application and to implement them in accordance with the contents of the specification, and to make the above and other objects, features and advantages of the embodiments of this application more obvious and understandable, specific implementation methods of this application are described below. Attached Figure Description
[0017] The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 This is a flowchart illustrating an embodiment of the target detection method provided in this application; Figure 2 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 3 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 4 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 5 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 6 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 7 This is a flowchart illustrating another embodiment of the target detection method provided in this application; Figure 8 This is a structural block diagram of an embodiment of the target detection device provided in this application; Figure 9 This is a schematic diagram of the structural framework of an embodiment of the electronic device provided in this application; Figure 10 This is a schematic diagram of the structural framework of an embodiment of the computer-readable storage medium provided in this application. Detailed Implementation
[0018] Exemplary embodiments of the present application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be implemented in various forms and should not be limited to the embodiments set forth herein. All other embodiments obtained by those skilled in the art based on the embodiments of the present application without inventive effort are within the scope of protection of the present application.
[0019] If the embodiments of this application involve descriptions such as "first" or "second," these descriptions are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Therefore, a feature defined with "first" or "second" may explicitly or implicitly include at least one of those features. Furthermore, if the word "and / or" appears throughout the text, it means including three parallel solutions. For example, "A and / or B" includes solution A, solution B, or a solution that simultaneously satisfies A and B. Additionally, the technical solutions of various embodiments can be combined with each other, but this must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or impossible to implement, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed in this application.
[0020] The first aspect of this application provides a target detection method. Figure 1 This is a flowchart illustrating an embodiment of the target detection method provided in this application. (In conjunction with...) Figure 1 This method includes the following steps: S101: Obtain the current image of the region to be detected, and perform target detection on the current image using the first preset model to obtain at least one current target.
[0021] Specifically, the area to be detected can be a specific component area on an industrial production line, such as the interior configuration area after vehicle assembly in a vehicle production line. Image acquisition devices, such as high-definition cameras, can be used to acquire images of the area to be detected, thereby obtaining the current image of the area. The first preset model is a pre-trained target detection model, which can be trained based on a large amount of labeled data and is capable of identifying specific targets in the image. After the current image is input into the first preset model, the model will process the current image and output the detected current target information, which may include the target's location, category, and quality information.
[0022] S102: If the number of current targets is less than the number of preset targets, the current scaling ratio is determined based on the current targets and their corresponding preset targets; wherein, the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in the preset template image corresponding to the current image.
[0023] It should be understood that a preset template image can be an image containing the area to be detected, acquired under a relatively stable and standard environment. Multiple preset targets can be pre-annotated in the preset template image; these targets are the objects that need to be detected in the subsequent detection process. For example, in the detection scenario of a vehicle's interior configuration area, the preset template image can be an image of the vehicle's interior taken in a standard assembly state, containing all the preset interior component targets that need to be detected, such as seats, center console, and dashboard.
[0024] In some application scenarios, when acquiring a preset template image, the shooting plane can be controlled to be parallel to the plane of the area to be detected (an angle deviation of <2° is considered parallel), and the distance between the shooting plane and the plane of the area to be detected should be less than a preset distance, such as less than 20cm. Corresponding to the method of acquiring the preset template image, when acquiring the current image, efforts can be made to ensure that the shooting plane and the plane of the area to be detected are nearly parallel and the distance is as small as possible. Due to the uncertainty of human operation in actual scenarios, the acquisition conditions of the preset template image may not be fully met, leading to problems such as fluctuations in shooting distance and angle deviations between the current image and the preset template image. However, the target detection method provided in this application can effectively perform target detection even with these problems, improving the accuracy of target detection.
[0025] If the number of current targets is less than the number of preset targets, it indicates that there are targets in the current image that have not been identified by the first preset model, i.e., there are unidentified targets. At this time, based on the identified current targets and their corresponding preset targets in the preset template image, the scaling ratio of the current image relative to the preset template image is determined. Therefore, the current scaling ratio represents the size ratio between the current targets and the preset targets, and is an important basis for subsequently determining the location of unidentified targets.
[0026] S103: Based on the current scaling ratio and the reference target, determine the center coordinates of at least one unidentified target, thereby determining the distribution area of at least one unidentified target, and output the target detection result by performing target detection on the distribution area through the second preset model; wherein, the reference target is selected from at least one current target.
[0027] The baseline target is a reference object among the current targets, and its selection should be based on certain preset selection rules. For example, the selection criteria of the preset selection rules may include one or more of the following: highest confidence level, highest probability of being identified, most stable size, largest size, or most central location among the current targets. In the event that no target is identified, the target coordinate frame will theoretically include the corresponding unidentified target.
[0028] Specifically, using a reference target and the current scaling ratio, the positional offset of the unidentified target relative to the reference target can be calculated, thereby determining the center coordinates of the unidentified target. Based on these center coordinates, the distribution area of the unidentified target can be determined in subsequent processes. The center coordinates of the unidentified target can be the center coordinates of the target bounding box, and the distribution area of the unidentified target is the specific location of the target bounding box. Then, a second preset model is used to perform target detection on the distribution area, outputting the target detection result. The target bounding box is then used, i.e., the second preset model is used to perform target detection on the region within the target bounding box. The second preset model can be a detection model optimized for a specific target or scene to improve detection accuracy and efficiency. Therefore, even if there are targets in the current image that were not identified by the first preset model, they can be accurately detected through subsequent processing steps (unless the unidentified target is missing), thereby improving the comprehensiveness and accuracy of target detection.
[0029] Figure 2 This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0030] Combination Figure 2 In some specific embodiments, the step of determining the current scaling ratio based on the current target and its corresponding preset target includes: S201: Determine a first ratio of the width of the coordinate frame of the current target to that of the corresponding preset target, and determine a second ratio of the length of the coordinate frame of the current target to that of the corresponding preset target. Use half of the sum of the first ratio and the second ratio as the initial scaling ratio.
[0031] It should be understood that when determining the initial scaling ratio, it is first necessary to obtain the width and height of the bounding box of the current target and its corresponding preset target in the preset template image. The bounding box of the preset target can be rectangular, and its boundaries can touch the boundaries of the preset targets within the box; that is, the bounding box of the preset target can be considered as the smallest bounding box enclosing the preset target. Of course, the bounding box of the current target can also be set in a similar manner. The width and height of the bounding box of the preset target can be obtained from the preset template image using image processing algorithms such as edge detection and contour extraction. Correspondingly, the width and height of the bounding box of the current target can be obtained from the current image using relevant image processing algorithms.
[0032] After obtaining the width and height of the coordinate frames of the current target and the corresponding preset target, the width of the current target's coordinate frame is divided by the width of the corresponding preset target's coordinate frame to obtain a first ratio. Similarly, the length of the current target's coordinate frame is divided by the length of the corresponding preset target's coordinate frame to obtain a second ratio. To comprehensively consider scaling in both width and height directions, the first and second ratios are added together and the result is halved as an initial scaling ratio. This initial scaling ratio reflects, to some extent, the change in the overall size of the current image relative to the preset template image.
[0033] S202: The current scaling ratio is obtained by weighted summation of the initial scaling ratios corresponding to each current target; where the weight of the initial scaling ratio corresponding to the current target is the target detection confidence of the current target.
[0034] Furthermore, since different current targets may have different detection confidence levels, with higher confidence levels indicating stronger reliability of the target detection result, the detection confidence level of the current target can be consistent with that of the corresponding preset target. The detection confidence level of the preset target can be preset based on actual detection conditions. Therefore, to more accurately reflect the overall scaling of the current image relative to the preset template image, the initial scaling ratios corresponding to each current target are weighted and summed. That is, using the target detection confidence level of the current target as the weight, the initial scaling ratios corresponding to all current targets are weighted and summed, and the final weighted sum is the current scaling ratio. In this way, current targets with higher confidence levels play a greater role in determining the current scaling ratio, making the current scaling ratio more accurately reflect the size change relationship between the current image and the preset template image.
[0035] In some application scenarios, set This is the initial scaling factor for the current target. These are the width and height of the current target's bounding box, respectively. and These are the width and length (which can be considered as height in some applications) of the coordinate frame corresponding to the current target. The initial scaling ratio is then calculated using the following formula: Let the target detection confidence level be... The current number of targets is m, and the current zoom level is [value missing]. Therefore, the current scaling ratio is calculated using the following formula: Figure 3 This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0036] Combination Figure 3 In some specific embodiments, the step of determining the center coordinates of the target bounding box of at least one unidentified target based on the current zoom level and the reference target includes: S301: Obtain the center coordinate difference between at least one unidentified target and the preset target corresponding to the reference target, and obtain the planar rotation angle between the current image and the preset template image.
[0037] It should be understood that in this application, both the center coordinates of the preset target and the center coordinates of the current target are coordinates in the same xy-axis coordinate system to facilitate subsequent calculations and comparisons. The center coordinates of the unidentified target can be determined first, thus determining the center coordinates of the target's bounding box. At this point, the center coordinates of the reference target can be obtained first, which can be the center coordinates of the reference target's bounding box. This coordinate serves as a reference point for subsequent calculations. Simultaneously, it is necessary to obtain the difference between the center coordinates of the unidentified target and the reference target in the preset template image (this can be the difference between the center coordinates of the preset target's bounding box). This difference reflects the relative positional relationship between the unidentified target and the reference target in the preset template image. Furthermore, since image rotation may occur during actual shooting, it is also necessary to obtain the planar rotation angle between the current image and the preset template image to perform corresponding rotation correction on the coordinates.
[0038] The coordinates of the center of the bounding box of the reference target can be accurately obtained in the current image using image processing algorithms, such as center point detection. The difference between the center coordinates of the bounding boxes of the unidentified target and the reference target can be obtained in the preset template image using corresponding image processing algorithms. The planar rotation angle can be obtained by comparing feature points or feature lines in the current image and the preset template image, using algorithms such as image registration or rotation estimation.
[0039] S302: Determine the center coordinates of the unidentified target based on the current zoom level, the center coordinates of the reference target, the center coordinate difference, and the plane rotation angle.
[0040] After obtaining the above parameters, a comprehensive calculation can be performed based on these parameters to determine the center coordinates of the unidentified target, that is, to determine the center coordinates of the target frame of the unidentified target. Specifically, the center coordinates of the target frame of the unidentified target are determined based on the current zoom level, the center coordinates of the reference target's frame, the difference between the center coordinates, and the plane rotation angle.
[0041] Figure 4 This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0042] Combination Figure 4 In some specific embodiments, the step of obtaining the planar rotation angle between the current image and the preset template image includes: S401: Determine the first difference between the y-axis coordinate of the center coordinate of the reference target and the y-axis coordinate of the center coordinate of the preset target corresponding to the reference target, and determine the second difference between the x-axis coordinate of the center coordinate of the reference target and the x-axis coordinate of the center coordinate of the preset target corresponding to the reference target.
[0043] When obtaining the planar rotation angle between the current image and the preset template image, it is first necessary to determine the difference in the center coordinates of the reference target in the current image and the preset template image.
[0044] Specifically, the first difference between the y-axis coordinates of the reference target's center and the preset template image is calculated. This difference reflects the vertical offset of the reference target's position between the two images. Then, the second difference between the x-axis coordinates of the reference target's center and the preset template image is calculated. This difference reflects the horizontal offset of the reference target's position between the two images.
[0045] S402: Compare the first difference with the second difference to obtain a ratio, and use the arctangent function value of the ratio as the planar rotation angle between the current image and the preset template image.
[0046] It should be understood that, since the first and second differences reflect the offset of the reference target position in the two images, this step further compares these two differences to obtain a ratio. This ratio reflects the relative positional offset of the reference target between the current image and the preset template image. Subsequently, the arctangent function value is taken from this ratio, which is the planar rotation angle between the current image and the preset template image.
[0047] In some application scenarios, the y-axis coordinate of the center coordinate of the reference target's coordinate frame is set to... The y-axis coordinate of the center coordinate of the coordinate frame of the preset target corresponding to the benchmark target is... The x-axis coordinate of the center of the reference target's coordinate frame is The x-axis coordinate of the center of the coordinate frame of the preset target corresponding to the baseline target is: The plane rotation angle is Therefore, the formula for calculating the plane rotation angle is as follows: Figure 5 This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0048] Combination Figure 5 In some specific embodiments, the center coordinates of the reference target include the x-axis coordinates and y-axis coordinates of the reference target's center coordinates. Specifically, the center coordinates of the reference target's coordinate frame include the x-axis coordinates and y-axis coordinates of the reference target's coordinate frame, and the center coordinate difference includes the x-axis coordinate difference and the y-axis coordinate difference. The step of determining the center coordinates of the unidentified target based on the current zoom level, the center coordinates of the reference target, the center coordinate difference, and the plane rotation angle, i.e., step S302 above, includes: S501: Determine the first product obtained by multiplying the x-axis coordinate difference by the current scaling factor and then by the cosine of the plane rotation angle; determine the second product obtained by multiplying the x-axis coordinate difference by the current scaling factor and then by the sine of the plane rotation angle; determine the third product obtained by multiplying the y-axis coordinate difference by the current scaling factor and then by the sine of the plane rotation angle; and determine the fourth product obtained by multiplying the y-axis coordinate difference by the current scaling factor and then by the cosine of the plane rotation angle.
[0049] Based on the above embodiments, the steps for determining the center coordinates of the target coordinate frame of the unidentified target are further explained.
[0050] First, based on the known difference in x-axis coordinates, multiply it by the current scaling factor, and then multiply it by the cosine of the plane rotation angle to obtain the first product. Similarly, multiply the difference in x-axis coordinates by the current scaling factor, and then multiply it by the sine of the plane rotation angle to obtain the second product, which reflects the vertical component in the horizontal direction caused by rotation.
[0051] Then, the difference in y-axis coordinates is multiplied by the current scaling factor, and then by the sine of the plane rotation angle to obtain the third product, which reflects the horizontal component caused by rotation in the vertical direction. Similarly, the difference in y-axis coordinates is multiplied by the current scaling factor, and then by the cosine of the plane rotation angle to obtain the fourth product, which takes into account the scaling and rotation of the target in the vertical direction.
[0052] S502: Add the first product to the x-axis coordinate of the center coordinate of the reference target and then subtract the third product to obtain the x-axis coordinate of the center coordinate of the unidentified target. Add the second product to the y-axis coordinate of the center coordinate of the reference target and then add the fourth product to obtain the y-axis coordinate of the center coordinate of the unidentified target.
[0053] Furthermore, after obtaining the above four products, the center coordinates of the reference target's frame can be corrected based on these products to obtain the center coordinates of the target frame of the unidentified target.
[0054] Specifically, the x-axis coordinate of the center of the reference target is added to the first product. This can be done by adding the first product to the x-axis coordinate of the center of the reference target's frame and then subtracting the third product. The result is the x-axis coordinate of the center of the unidentified target's frame. Similarly, the y-axis coordinate of the center of the reference target's frame is added to the second product and then to the fourth product. The result is the y-axis coordinate of the center of the unidentified target's frame.
[0055] It should be understood that the center coordinates of the target bounding box of the unidentified target determined by the above method take into account the scaling ratio, rotation angle, and the relative positional relationship between the unidentified target and the reference target in the preset template image, thereby accurately determining the position of the unidentified target in the current image.
[0056] In some application scenarios, let the difference in x-axis coordinates be _____. The difference in y-axis coordinates is The x-coordinate of the center of the target coordinate frame is The y-coordinate of the center of the target coordinate frame is Therefore, the x and y coordinates of the center of the target coordinate frame can be calculated using the following formula: Figure 6 This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0057] Combination Figure 6 In some specific embodiments, the step of determining the distribution area of at least one unidentified target specifically includes: S601: Determine the width and length of the coordinate frame of the reference target, and determine the ratio of the width of the coordinate frame of the first preset target and the ratio of the length of the coordinate frame of the reference target and the unidentified target in the preset template image, respectively.
[0058] To more accurately locate unidentified targets, in addition to considering the center coordinates of their bounding boxes, their dimensions also need to be accurately estimated. This can be achieved using image processing algorithms, such as edge detection or contour extraction, to determine the width and length of the bounding box of the reference target in the current image. This dimensional information reflects the actual size of the reference target in the current image. Simultaneously, in a preset template image, image processing algorithms are also used to obtain the first and second preset targets corresponding to the unidentified target and the reference target, respectively, and to determine the width and length of their bounding boxes. Subsequently, the ratio of the width to the length of the bounding boxes of the unidentified target and the reference target in the preset template image is calculated, thus determining the ratio of the width to the length of the bounding boxes of the first and second preset targets.
[0059] S602: Based on the width and length of the reference target's coordinate frame, the width ratio of the coordinate frame, and the length ratio of the coordinate frame, determine the width and length of the target coordinate frame, so as to determine the position of the target coordinate frame according to the center coordinates of the target coordinate frame, the width of the target coordinate frame, and the length of the target coordinate frame.
[0060] After determining the corresponding parameters through the above steps, this step further determines the width and length of the target bounding box of the unidentified target based on these parameters. Specifically, the width of the bounding box of the reference target is multiplied by the ratio of the width of the bounding box of the unidentified target to the width of the bounding box of the reference target in the preset template image, and the result is the width of the target bounding box of the unidentified target. Similarly, the length of the bounding box of the reference target is multiplied by the corresponding bounding box length ratio, and the result is the length of the target bounding box of the unidentified target.
[0061] It should be understood that once the center coordinates, width, and length of the target bounding box are determined (the width direction is parallel to one of the x-axis and y-axis, and the length direction is parallel to the other of the x-axis and y-axis), the position of the target bounding box in the current image can be accurately determined, thereby completing the localization of the unidentified target.
[0062] Figure 7This is a flowchart illustrating another embodiment of the target detection method provided in this application.
[0063] Combination Figure 7 In some specific embodiments, the step of determining the width and length of the target coordinate frame based on the width and length of the reference target's coordinate frame, the ratio of the coordinate frame width to the coordinate frame length, includes: S701: Multiply the width of the reference target's coordinate frame by the ratio of the coordinate frame width to obtain the initial width, and multiply the initial width by the first safety margin coefficient to obtain the width of the target's coordinate frame; wherein, the first safety margin coefficient is greater than 1.
[0064] It should be understood that when determining the width of the target bounding box, a first safety margin coefficient is introduced to take into account various errors that may exist in practical applications and to ensure that the target can be completely contained within the bounding box. This first safety margin coefficient is greater than 1, so that the final width of the target bounding box is greater than the actual width of the target bounding box for unidentified targets.
[0065] Specifically, the width of the reference target's bounding box is multiplied by the ratio of the bounding box widths of the unidentified target and the reference target in the preset template image to obtain an initial width. This initial width is a preliminary estimate based on the relative proportions in the preset template image. Then, the initial width is multiplied by a first safety margin coefficient greater than 1. This appropriately expands the width of the target bounding box to ensure that the unidentified target can be completely enclosed within it, thus obtaining the final width of the target bounding box.
[0066] S702: Multiply the length of the reference target's coordinate frame by the ratio of the coordinate frame length to obtain the initial length, and multiply the initial length by the second safety margin coefficient to obtain the length of the target's coordinate frame; wherein, the second safety margin coefficient is greater than 1.
[0067] Similarly, when determining the length of the target bounding box, the errors in practical applications and the need to ensure target integrity must be considered. Therefore, a second safety margin coefficient is introduced, which is also greater than 1. Specifically, the length of the bounding box of the reference target is first multiplied by the ratio of the bounding box lengths of the unidentified target and the reference target in the preset template image to obtain an initial length. This initial length reflects a preliminary length estimate based on the preset template image. Then, this initial length is multiplied by a second safety margin coefficient greater than 1 to appropriately increase the length of the target bounding box, ensuring that the unidentified target can be completely contained within the bounding box, thus obtaining the final target bounding box length.
[0068] In some application scenarios, the width of the coordinate frame of the reference target is set to... The length of the coordinate frame of the reference target is The aspect ratio of the coordinate frame is The ratio of the coordinate frame length is The width and length of the target coordinate frame are respectively , , This is the first safety margin factor. Greater than 0, This is the second safety margin factor. The value is greater than 0. Therefore, the formulas for calculating the width and length of the target bounding box are as follows: In some application scenarios, the first preset model can be either a YOLOv11 model or a MobileNetV3_Small model. The YOLOv11 model offers higher detection accuracy and speed, enabling it to accurately identify targets in complex scenes, while the MobileNetV3_Small model features smaller model size and lower computational cost. After the second preset model obtains its detection results, the results from the first preset model are fused together to output the final detection result.
[0069] A second aspect of this application provides a target detection device 80. Figure 8 This is a structural block diagram of an embodiment of the target detection device 80 provided in this application.
[0070] Combination Figure 8 The target detection device 80 includes: an image acquisition module 81, used to acquire a current image of the region to be detected; a first detection module 82, used to perform target detection on the current image using a first preset model to obtain at least one current target; wherein both the current image and the preset template image include the region to be detected, and the preset template image includes multiple preset targets; a processing module 83, used to determine a current scaling ratio based on the current targets and their corresponding preset targets if the number of current targets is less than the number of preset targets; wherein the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in the preset template image corresponding to the current image; and to determine the center coordinates of at least one unidentified target based on the current scaling ratio and a reference target, so as to determine the distribution area of at least one unidentified target; wherein the reference target is selected from at least one current target; and a second detection module 84, used to perform target detection on the distribution area and output the target detection result.
[0071] A third aspect of this application provides an electronic device 600, comprising: a processor; and a memory for storing a computer program, wherein the computer program, when executed by the processor, implements the target detection method of any of the above embodiments.
[0072] Figure 9This is a schematic diagram of the structural framework of an embodiment of the electronic device 600 provided in this application.
[0073] Combination Figure 9 In some specific embodiments, the electronic device 600 includes a central processing unit (CPU) 601 and a read-only memory (ROM) 602. The CPU 601 is a processor, and the ROM 602 is a memory. The CPU 601 can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in the ROM 602 or programs loaded from storage portion 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for system operation. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0074] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0075] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs various functions defined in the system of this application.
[0076] A fourth aspect of this application provides a computer-readable storage medium 40, Figure 10 This is a schematic diagram of the structural framework of an embodiment of the computer-readable storage medium 40 provided in this application.
[0077] Combination Figure 10 The computer-readable storage medium 40 stores a computer program 41, which, when executed by a processor, implements the target detection method as described in any of the above embodiments.
[0078] It should be noted that the computer-readable medium 40 shown in the embodiments of this application can be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. The transmitted data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. The computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0079] In summary, the target detection method, apparatus, device, and storage medium provided in this application include: acquiring a current image of a region to be detected, and performing target detection on the current image using a first preset model to obtain a current target; wherein both the current image and a preset template image include the region to be detected, and the preset template image includes multiple preset targets; if the number of current targets is less than the number of preset targets, a current scaling ratio is determined based on the current targets and their corresponding preset targets; wherein the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets; determining the center coordinates of the target coordinate box of an unidentified target based on the current scaling ratio and a reference target, thereby determining the position of the target coordinate box, and performing target detection on the region within the target coordinate box using a second preset model; wherein the reference target is one of the current targets. This method can accurately determine the region where the unidentified target is located based on the current scaling ratio and the reference target, thereby achieving target detection and improving the accuracy of target detection.
[0080] The above description is merely a preferred exemplary embodiment of this application and is not intended to limit the implementation of this application. Those skilled in the art can easily make corresponding modifications or alterations based on the main concept and spirit of this application. Therefore, the scope of protection of this application should be determined by the scope of protection claimed in the claims.
Claims
1. A target detection method, characterized in that, include: The current image of the region to be detected is obtained, and at least one current target is obtained by performing target detection on the current image using a first preset model; If the number of current targets is less than the number of preset targets, then the current scaling ratio is determined based on the current targets and their corresponding preset targets; wherein, the current scaling ratio is used to characterize the size ratio between the current targets and the preset targets, and the preset targets exist in the preset template image corresponding to the current image; Based on the current scaling ratio and the reference target, the center coordinates of at least one unidentified target are determined to determine the distribution area of the at least one unidentified target. The target detection result is then output by performing target detection on the distribution area through a second preset model. The reference target is selected from the at least one current target.
2. The target detection method according to claim 1, characterized in that, The step of determining the current scaling ratio based on the current target and its corresponding preset target includes: A first ratio is determined between the width of the coordinate frame of the current target and the width of the corresponding preset target, and a second ratio is determined between the length of the coordinate frame of the current target and the width of the corresponding preset target. Half of the sum of the first ratio and the second ratio is used as the initial scaling ratio. The current scaling ratio is obtained by weighted summing of the initial scaling ratios corresponding to each current target; wherein the weight of the initial scaling ratio corresponding to the current target is the target detection confidence of the current target.
3. The target detection method according to claim 1, characterized in that, The step of determining the center coordinates of at least one unidentified target based on the current zoom level and the reference target includes: Obtain the center coordinate difference between the preset targets corresponding to the at least one unidentified target and the reference target, and obtain the planar rotation angle between the current image and the preset template image; The center coordinates of the unidentified target are determined based on the current zoom level, the center coordinates of the reference target, the center coordinate difference, and the plane rotation angle.
4. The target detection method according to claim 3, characterized in that, The step of obtaining the planar rotation angle between the current image and the preset template image includes: The first difference between the y-axis coordinate of the center of the reference target and the y-axis coordinate of the center of the preset target corresponding to the reference target is determined, and the second difference between the x-axis coordinate of the center of the reference target and the x-axis coordinate of the center of the preset target corresponding to the reference target is determined. The first difference is compared with the second difference to obtain a ratio, and the arctangent function value of the ratio is used as the planar rotation angle between the current image and the preset template image.
5. The target detection method according to claim 3, characterized in that, The center coordinates of the reference target include the x-axis coordinates and y-axis coordinates of the center coordinates of the reference target, and the center coordinate difference includes the x-axis coordinate difference and the y-axis coordinate difference; The step of determining the center coordinates of the unidentified target based on the current zoom level, the center coordinates of the reference target, the center coordinate difference, and the plane rotation angle includes: The product is determined by multiplying the x-axis coordinate difference by the current scaling factor and then by the cosine of the plane rotation angle; the product is determined by multiplying the x-axis coordinate difference by the current scaling factor and then by the sine of the plane rotation angle; the product is determined by multiplying the y-axis coordinate difference by the current scaling factor and then by the sine of the plane rotation angle; and the product is determined by multiplying the y-axis coordinate difference by the current scaling factor and then by the cosine of the plane rotation angle. The x-axis coordinate of the center coordinate of the reference target is added to the first product and then the third product is subtracted to obtain the x-axis coordinate of the center coordinate of the target frame of the unidentified target. The y-axis coordinate of the center coordinate of the reference target is added to the second product and then the fourth product to obtain the y-axis coordinate of the center coordinate of the target frame of the unidentified target.
6. The target detection method according to claim 1, characterized in that, The step of determining the distribution area of at least one unidentified target specifically includes: The width and length of the coordinate frame of the reference target are determined, and the ratio of the width of the coordinate frame of the first preset target and the ratio of the length of the coordinate frame of the unidentified target and the reference target in the preset template image are determined respectively. Based on the width and length of the reference target's coordinate frame, the width ratio of the coordinate frame, and the length ratio of the coordinate frame, the width and length of the target coordinate frame are determined, so as to determine the position of the target coordinate frame according to the center coordinates of the target coordinate frame, the width of the target coordinate frame, and the length of the target coordinate frame.
7. The target detection method according to claim 6, characterized in that, The step of determining the width and length of the target coordinate frame based on the width and length of the reference target's coordinate frame, the width ratio of the coordinate frame, and the length ratio of the coordinate frame includes: The initial width is obtained by multiplying the width of the reference target's coordinate frame by the ratio of the coordinate frame width, and the initial width is multiplied by the first safety margin coefficient to obtain the width of the target's coordinate frame; wherein, the first safety margin coefficient is greater than 1; The initial length is obtained by multiplying the length of the reference target's coordinate frame by the ratio of the coordinate frame length, and the initial length is multiplied by the second safety margin coefficient to obtain the length of the target's coordinate frame; wherein, the second safety margin coefficient is greater than 1.
8. A target detection device, characterized in that, include: The image acquisition module is used to acquire the current image of the region to be detected. The first detection module is used to perform target detection on the current image using a first preset model to obtain at least one current target; A processing module is configured to, if the number of current targets is less than the number of preset targets, determine a current scaling ratio based on the current targets and their corresponding preset targets; wherein the current scaling ratio characterizes the size ratio between the current targets and the preset targets, and the preset targets exist in a preset template image corresponding to the current image; and determine the center coordinates of at least one unidentified target based on the current scaling ratio and a reference target, so as to determine the distribution area of the at least one unidentified target; wherein the reference target is selected from the at least one current target. The second detection module is used to perform target detection on the distribution area and output the target detection results.
9. An electronic device, characterized in that, include: processor; A memory for storing a computer program that, when executed by the processor, implements the target detection method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the target detection method as described in any one of claims 1-7.