Multi-target detection and ranging method based on Swin Transformer and ZED camera

Through the multi-target detection and ranging method based on Swin Transformer and ZED camera, the problem of low real-time detection and ranging efficiency of binocular robot terminal equipment is solved, and fast and intelligent target detection and distance calculation are achieved, which is suitable for industrial scenarios. .

CN113313201BActive Publication Date: 2024-10-15NANJING HUIGE INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202110685876.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-06-21
Publication Date
2024-10-15
Estimated Expiration
2041-06-21

AI Technical Summary

Technical Problem

Existing technology is difficult to achieve real-time multi-target detection and ranging for binocular robot terminal equipment, resulting in low efficiency of target detection and ranging, making it difficult to apply to industrial scenarios such as car obstacle avoidance and drone tracking.

Method used

A multi-target detection and ranging method based on Swin Transformer and ZED camera is adopted. The Swin Transformer target detector is trained through preset training hyperparameters. Real-time detection and ranging is achieved in combination with the ZED camera, and the target distance is calculated using the depth map.

Benefits of technology

It achieves rapid and intelligent detection and extraction of targets, and calculates the target distance, which improves the real-time detection and ranging efficiency of terminal equipment and is suitable for industrial scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113313201B_ABST
    Figure CN113313201B_ABST
Patent Text Reader

Abstract

The present invention discloses a multi-target detection and ranging method based on Swin Transformer and ZED camera, and the method comprises the following steps: S1, using preset training hyperparameters to train the Swin Transformer target detector to obtain the Swin Transformer target detection model; S2, using the Swin Transformer target detection model and the ZED camera to realize real-time detection and ranging of multiple targets. Beneficial effect: The present invention integrates Swin Transformer target detection and ZED binocular ranging, effectively solving the difficulty of real-time multi-target detection and multi-target ranging of terminal equipment. Compared with traditional detection and ranging methods, this method can quickly and intelligently detect and extract targets, and calculate target distances, and is suitable for industrial scenarios such as car obstacle avoidance and drone tracking.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of video image processing and target detection, and in particular to a multi-target detection and ranging method based on SwinTransformer and a ZED camera. Background Art

[0002] The performance of modern robots has been continuously developed and improved. Now robots have been widely used in various fields such as industrial production, military, life services, exploration of unknown environments and disaster relief support. Robots can fully understand their environment. They not only have sensory functions but also have adaptive capabilities. They can determine appropriate actions based on their own judgments and given instructions. Their essence is similar to a constantly improving knowledge information system. Intelligent robots have the ability to coordinate with the external environment, and their visual system is the key part required for this ability.

[0003] Binoculars are essential devices for humanoid robots, and they play a vital role in helping robots obtain information about the outside world. Based on the dynamic target detection and tracking system of binocular robots, external targets can be located in real time through binoculars, and then the dynamic targets can be tracked using the robot motion control algorithm. The key to the above process lies in the precise positioning of dynamic targets, and the dynamic target detection and ranging technology based on vision is the key to target positioning, so it is particularly important to study dynamic target detection and ranging technology. Summary of the invention

[0004] In view of the problems in the related art, the present invention proposes a multi-target detection and ranging method based on Swin Transformer and ZED camera to overcome the above-mentioned technical problems existing in the existing related art.

[0005] To this end, the specific technical solution adopted by the present invention is as follows:

[0006] A multi-target detection and ranging method based on Swin Transformer and ZED camera, the method comprises the following steps:

[0007] S1. Train the Swin Transformer target detector using preset training hyperparameters to obtain a Swin Transformer target detection model.

[0008] S2. Use the Swin Transformer target detection model and ZED camera to achieve real-time detection and ranging of multiple targets.

[0009] Furthermore, the S1 uses preset training parameters to train the Swin Transformer target detector to obtain the Swin Transformer target detection model, including the following steps:

[0010] S11. Make a data set: Download the COCO data set, shuffle the data set, and extract the training set, validation set, and test set in a ratio of 7:2:1;

[0011] S12, data expansion: use basic image expansion method to expand the training data;

[0012] S13. Set training hyperparameters: Set the training hyperparameters of the Swin Transformer object detector;

[0013] S14. Model training: Train the Swin Transformer target detector according to the training hyperparameters and the prepared data set to obtain the Swin Transformer target detection model.

[0014] Furthermore, the expansion of the training data in S12 includes: cropping, random rotation, horizontal flipping, color conversion, and several expansion methods for the target cropping strategy;

[0015] The training hyperparameters of the Swin Transformer target detector set in S13 include: the number of images per training batch, the input image width, the image height, the number of image channels, the impulse, the initial learning rate, the weight decay coefficient, the learning rate adjustment parameter, the maximum number of iterations, the optimizer, and the threshold.

[0016] Furthermore, the S2 uses the Swin Transformer target detection model and the ZED camera to achieve real-time detection and ranging of multiple targets, including the following steps:

[0017] S21, initialization: initializing the camera parameters and Swin Transformer target detection model;

[0018] S22, read the flag bit to determine whether to exit the program: read the keyboard status and determine whether to exit the program;

[0019] S23, read image: use the ZED binocular camera to read the left camera color image, send it to the SwinTransformer target detection model, and determine whether the image is successfully read. If so, execute S24, otherwise return to S22;

[0020] S24, object detection: Use the Swin Transformer object detection model to read a new image and predict the bounding box, confidence, and category confidence information of the object in the image;

[0021] S25, target ranging: According to the prediction results of the Swin Transformer target detection model and the ZED camera depth map, the distance of each target is calculated to achieve multi-target ranging;

[0022] S26, display: draw the bounding box of the detected multiple targets, the target category and the confidence level on the original image, and mark the calculated target distance.

[0023] Furthermore, the initialization of the camera parameters and the Swin Transformer target detection model in S21 includes the following steps:

[0024] S211, initializing camera parameters;

[0025] S212. Create a new child thread for the Swin Transformer object detection model;

[0026] S213, initializing the Swin Transformer target detection model.

[0027] Furthermore, the initialization process of the camera parameters in S211 specifically includes the following steps:

[0028] Set the camera acquisition mode to WVGA;

[0029] Set the camera frame rate to 100;

[0030] Set the size of the collected image to 672x386.

[0031] Furthermore, the initialization process of the Swin Transformer target detection model in S213 specifically includes: reading the model configuration file config and the weight file checkpoint.

[0032] Further, the step of reading the keyboard status and determining whether to exit the program in S22 includes the following steps:

[0033] Read the keyboard status to determine whether there is keyboard input q or Esc. If so, set the exit flag to true, close the SwinTransformer target detection model, close the child thread, and exit the main program; otherwise, execute S23.

[0034] Furthermore, in S24, the Swin Transformer target detection model is used to read a new image, and the prediction of the bounding box, confidence, and category confidence information of the target in the image includes the following steps:

[0035] S241, load the Swin Transformer target detection model;

[0036] S242, determine whether the exit flag is true, if it is true, close the Swin Transformer target detection model and exit the thread, if it is false, execute S243;

[0037] S243, determine whether there is a new input image, if not, return to S242 after a delay of 1ms, if there is a new input image, enter S244;

[0038] S244, image format conversion, converting the Mat type image of Opencv3 into the image type of the Swin Transformer target detection model;

[0039] S245, inputting the converted image type image into the Swin Transformer target detection model, and predicting the bounding box, confidence, and category confidence information of the target in the image;

[0040] S246, change the data flag to detection end, pass it to the main thread, and return to S242.

[0041] Furthermore, the step S25 of calculating the distance of each target to achieve multi-target ranging according to the prediction result of the Swin Transformer target detection model and the ZED camera depth map includes the following steps:

[0042] S251, predicting the target frame according to the Swin Transformer target detection model, obtaining the target category, the coordinates of the upper left corner of the target frame, and the length and width (x, y, w, h) of the target;

[0043] S252, using the ZED camera to obtain a depth image Dst of each pixel distance;

[0044] S253, obtaining the depth values ​​of the upper left corner, upper right corner, lower left corner, lower right corner and the neighborhood 3x3 of the center point of the target frame;

[0045] S254, performing median filtering on the depth pixels at the upper left corner, upper right corner, lower left corner, lower right corner and center point of the target frame;

[0046] Among them, the filtering formula is ddst(x, y) = med{Dst(x+k, y+l), (k, l∈[-l, 1])}, where ddst represents the median filter calculation result, Dst represents the depth map, med means taking the middle value in the set, x and y represent the horizontal and vertical coordinates, k and l are the traversal values ​​on the horizontal and vertical coordinates, between the interval [-1, 1];

[0047] S255, taking the depth value of the target frame center point after filtering as the target distance, to achieve multi-target ranging;

[0048] The formula for the depth value is ddst(x+w / 2, y+h / 2), where ddst represents the median filter calculation result, x and y represent the horizontal and vertical coordinates, and w and h are the width and height of the prediction box.

[0049] The beneficial effects of the present invention are as follows: the present invention provides a multi-target detection and ranging method based on Swin Transformer and ZED cameras, which integrates Swin Transformer target detection and ZED binocular ranging, and effectively solves the difficulty of terminal equipment to realize multi-target detection and multi-target ranging in real time; compared with traditional detection and ranging methods, the method can quickly and intelligently detect and extract targets, and calculate target distances, and is suitable for industrial scenarios such as car obstacle avoidance and drone tracking. BRIEF DESCRIPTION OF THE DRAWINGS

[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0051] Figure 1 is a flow chart of a multi-target detection and ranging method based on a Swin Transformer and a ZED camera according to an embodiment of the present invention;

[0052] Figure 2 is a schematic diagram of an algorithm for a multi-target detection and ranging method based on a Swin Transformer and a ZED camera according to an embodiment of the present invention;

[0053] Figure 3 is a structural schematic diagram of a clipping strategy for a target in a multi-target detection and ranging method based on a Swin Transformer and a ZED camera according to an embodiment of the present invention;

[0054] Figure 4This is a main thread flow chart of a multi-target detection and ranging method based on Swin Transformer and ZED camera according to an embodiment of the present invention;

[0055] Figure 5 is a schematic diagram of ZED camera initialization in a multi-target detection and ranging method based on Swin Transformer and ZED camera according to an embodiment of the present invention;

[0056] Figure 6 is a schematic diagram of initializing a Swin Transformer target detection model in a multi-target detection and ranging method based on a Swin Transformer and a ZED camera according to an embodiment of the present invention;

[0057] Figure 7 It is a flow chart of the Swin Transformer detector subthread in the multi-target detection and ranging method based on Swin Transformer and ZED camera according to an embodiment of the present invention. DETAILED DESCRIPTION

[0058] To further illustrate each embodiment, the present invention provides drawings, which are part of the disclosure of the present invention and are mainly used to illustrate the embodiments and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these contents, ordinary technicians in the field should be able to understand other possible implementations and advantages of the present invention. The components in the figures are not drawn to scale, and similar component symbols are generally used to represent similar components.

[0059] According to an embodiment of the present invention, a multi-target detection and ranging method based on Swin Transformer and ZED camera is provided.

[0060] The present invention is further described with reference to the accompanying drawings and specific embodiments. Figure 1-7 As shown, according to the multi-target detection and ranging method based on Swin Transformer and ZED camera in an embodiment of the present invention, the method comprises the following steps:

[0061] S1. Train the Swin Transformer target detector using preset training hyperparameters to obtain a Swin Transformer target detection model.

[0062] Among them, the Swin Transformer is a neural network target detection model with Transformer as the basic unit. Transformer is a new network structure used to complete learning tasks such as machine translation. It fully uses the attention mechanism to achieve sequence-to-sequence modeling, and has the advantages of low computational complexity, high parallelism, and easy learning of long-range dependencies. Swin Transformer constructs a hierarchical Transformer to achieve target detection tasks by introducing the hierarchical construction method commonly used in convolutional neural networks.

[0063] The design of the Swin Transformer model refers to the hierarchical feature representation of convolutional neural networks. The entire model is divided into different layers, each layer downsamples the feature map output by the previous layer, where the hierarchical features are calculated by shifting windows. The shifting window improves efficiency by limiting the self-attention calculation to non-overlapping local windows while also allowing cross-window connections. This hierarchical architecture has flexibility in modeling at various scales and has linear computational complexity relative to the image size. Multi-scale prediction is used in the prediction layer, and large, medium, and small target objects in the image can be detected for different receptive fields.

[0064] Swin Transformer needs to obtain the parameters of the neural network through data training. Here, the input image is set to 672x386. The COCO dataset is divided and the training data is expanded. The Swin Transformer object detector is used to train the Swin Transformer object detection model to complete the training of the object detection model.

[0065] Specifically, the S1 uses preset training parameters to train the Swin Transformer target detector to obtain the Swin Transformer target detection model, including the following steps:

[0066] S11. Make a data set: Download the COCO data set, shuffle the data set, and extract the training set, validation set, and test set in a ratio of 7:2:1;

[0067] S12, data expansion: use basic image expansion method to expand the training data;

[0068] Several basic image expansion methods are used for training data: cropping, rotation, horizontal flipping, and brightness transformation. In addition, the mark of the target frame is retained during expansion. If the target frame is offset or transformed, the size and coordinates of the target frame are changed through formula calculation to ensure that the mark of the target frame is retained after the image transformation, so as to achieve automatic expansion and reduce manpower. The specific method is:

[0069] 1) Unified sample size: All sample images are uniformly scaled to a size of 672x386 to adapt to the size of the real-time detection image.

[0070] 2) Sample cropping: As mentioned above, the sample images of this method will be resized to a rectangular size of 672x386. This method uses a larger rectangular box (randomly specified to be 0.8 to 0.9 times the size of the original image) to crop an image block at a random position of the original image, which can ensure that the target is likely to be in the cropped image and improve the generalization of the model.

[0071] 3) Random rotation: Randomly select an angle between 0 and 15 degrees for the original image, rotate the image by this angle and add it to the training set. For the neural network, the rotated image is also new data. Since it needs to be automatically marked on the original image after data expansion, if the rotation angle is too large, it is easy to cause a large-scale offset of the target. According to the transformation of the target frame, in order to ensure that the target can be framed, the width and height of the frame will be larger than the original frame. When the rotation angle α is larger, the change of the frame is greater, resulting in a greater error in the frame. Within 15 degrees, the offset and size of the frame are small, and the error of the external frame can be controlled within a controllable range.

[0072] 4) Horizontal flipping: Horizontal flipping can double the size of the sample image and can also be used in conjunction with other expansion methods. This method uses randomly rotated images and mirror flipping at the same time.

[0073] 5) Color jitter: Convert the image into HSV color space, and try to randomly change the original saturation and brightness of the image (i.e., change the values ​​of the S and V channels) or fine-tune the hue (change the value of the channel in a small range) in the HSV color space.

[0074] 6) Targeted tailoring strategy: The principle is as follows Figure 3 As shown in the figure, in view of the particularity of the target detection task and taking into account the position of the original annotation box, a new expansion strategy was formed during the research process: maintain a certain coverage area ratio and randomly jitter based on the original annotation box position. The position information of the original target box A is recorded as [xmin, ymin, xmax, ymax], and the position information of the annotation box B after the coordinates are enlarged and randomly jittered is [xmin-Δxmin, ymin-Δymin, xmax+Δxmax, ymax+Δymax]. When the ratio of the area of ​​box A to the large box B is greater than 0.5, the box B is intercepted according to its position in the original image and stored in the training set.

[0075] S13. Set training hyperparameters: Set the training hyperparameters of the Swin Transformer object detector;

[0076] Setting good hyperparameters can make the neural network fit faster and better. The training hyperparameters are shown in Table 1. One epoch represents training all the data once. At 27 epochs and 33 epochs, the learning rate is multiplied by the learning rate adjustment parameter 0.1 to reduce the learning rate.

[0077] Table 1 Hyperparameter settings during training

[0078]

[0079]

[0080] S14. Model training: Train the Swin Transformer target detector according to the training hyperparameters and the prepared data set to obtain the Swin Transformer target detection model.

[0081] S2. Use the Swin Transformer target detection model and ZED camera to achieve real-time detection and ranging of multiple targets.

[0082] Among them, the multi-target ranging method based on Swin Transformer and ZED camera has the following process: the ZED camera collects images in real time and calculates the depth map, and uses the trained model to predict the multi-target positions and target categories in the collected color image, combined with the depth map.

[0083] The ZED camera can collect images in real time. Target detection and binocular ranging are two different tasks. Distance measurement requires the position of the target frame to be determined. In principle, target detection precedes binocular ranging, but the time required for target detection is much longer than that required for binocular ranging. To ensure efficiency, a thread is opened for target detection, and the main thread is responsible for image acquisition, transmission, and ranging.

[0084] The main function flow chart is as follows Figure 4As shown, first initialize the ZED camera parameters and Swin Transformer target detection model. The input of the parameters can be passed in as a parameter through the argv of the main function, so that the required parameters can be passed in when the program is executed in Linux. The thread of the main function executes the binocular ranging program and uses a while loop to execute the main part of the code. If q or Esc is entered on the keyboard, the program will exit directly if it determines that there is an exit sign. The ZED camera collects new data and takes out the depth image. The distance between the camera and each target is calculated based on the target box obtained by the Swin Transformer target detection, and then the bounding box, target name, recognition confidence and target distance are drawn on the original image and displayed. In order to facilitate the careful analysis of a certain frame of the picture sometimes, it is set to pause the while loop when the key p is pressed, and continue to run until the key p is pressed again.

[0085] Specifically, the S2 uses the Swin Transformer target detection model and the ZED camera to achieve real-time detection and ranging of multiple targets, including the following steps:

[0086] S21, initialization: initializing the camera parameters and Swin Transformer target detection model;

[0087] Program initialization is divided into two steps: camera initialization and Swin Transformer object detection model initialization. Camera initialization is as follows Figure 5 As shown, first set the camera acquisition mode and frame rate. To ensure the smoothness and speed of data processing, the acquisition mode is set to WVGA, the frame rate is set to 100, and the size of the acquired image is 672x386.

[0088] The Swin Transformer target detection model initialization process is as follows Figure 6 As shown, first you need to read the model configuration file config and the weight file checkpoint. To ensure real-time sampling monitoring of the program, create a new thread for the SwinTransformer detector, and then start the Swin Transformer detector. Whenever the camera obtains an image to the detector, Swin Transformer completes the detection and returns the detection result.

[0089] S22, read the flag bit to determine whether to exit the program: read the keyboard status and determine whether to exit the program;

[0090] Reading the keyboard status and determining whether to exit the program in S22 includes the following steps: reading the keyboard status, determining whether there is a keyboard input q or Esc, if the exit flag is set to true, closing the Swin Transformer target detection model, closing the child thread, and exiting the main program; if not, executing S23.

[0091] S23, read image: use the ZED binocular camera to read the left camera color image, send it to the SwinTransformer target detection model, and determine whether the image is successfully read. If so, execute S24, otherwise return to S22;

[0092] As a binocular camera, ZED will obtain color images based on the left and right cameras and automatically calculate the depth information of each pixel. Here, we only need to obtain the color image of the left camera and feed it into the Swin Transformer target detection model.

[0093] S24, object detection: Use the Swin Transformer object detection model to read a new image and predict the bounding box, confidence, and category confidence information of the object in the image;

[0094] The Swin Transformer target detection model obtains the image to infer which targets exist in the image. The main thread sets a data flag. When the flag is true, it means that the Swin Transformer target detection model is idle and a new image can be input; if the flag is false, it means that the Swin Transformer target detection model is busy and no new image needs to be input. The detection sub-thread flowchart is as follows: Figure 7 As shown, the specific steps include:

[0095] S241, load the Swin Transformer target detection model, which requires the Swin Transformer framework to interpret the configuration file config;

[0096] S242, determine whether the exit flag is true, if it is true, close the Swin Transformer target detection model and exit the thread, if it is false, execute S243;

[0097] S243, determine whether there is a new input image, if not, return to S242 after a delay of 1ms, if there is a new input image, enter S244;

[0098] S244, image format conversion, converting the Mat type image of Opencv3 into the image type of the Swin Transformer target detection model;

[0099] S245, input the converted image type image into the Swin Transformer target detection model, calculate the multi-target information of this frame image, the target information is a 21x12x3x(4+1+c) tensor, that is, divide the input image into 21x12 blocks, and predict 3 external bounding boxes for each block of the image. Each external bounding box contains coordinate information (x, y, w, h), whether it contains a target, and the confidence of each category. The multi-target detection result of the image can be obtained by integrating the above information through maximum suppression;

[0100] S246, change the data flag to detection end, pass it to the main thread, and return to S242.

[0101] S25, target ranging: According to the prediction results of the Swin Transformer target detection model and the ZED camera depth map, the distance of each target is calculated to achieve multi-target ranging;

[0102] In S25, the distance of each target is calculated according to the prediction result of the Swin Transformer target detection model and the ZED camera depth map to realize multi-target ranging, which includes the following steps:

[0103] S251, predicting the target frame according to the Swin Transformer target detection model, obtaining the target category, the coordinates of the upper left corner of the target frame, and the length and width (x, y, w, h) of the target;

[0104] S252, using the ZED camera to obtain a depth image Dst of each pixel distance;

[0105] S253, obtaining the depth values ​​of the upper left corner, upper right corner, lower left corner, lower right corner and the neighborhood 3x3 of the center point of the target frame;

[0106] S254, performing median filtering on the depth pixels at the upper left corner, upper right corner, lower left corner, lower right corner and center point of the target frame;

[0107] Among them, the filtering formula is ddst(x, y) = med{Dst(x+k, y+l), (k, l∈[-1, 1])}, where ddst represents the median filter calculation result, Dst represents the depth map, med means taking the middle value in the set, x and y represent the horizontal and vertical coordinates, k and l are the traversal values ​​on the horizontal and vertical coordinates, between the interval [-1, 1];

[0108] S255, taking the depth value of the target frame center point after filtering as the target distance, to achieve multi-target ranging;

[0109] The formula for the depth value is ddst(x+w / 2, y+h / 2), where ddst represents the median filter calculation result, x and y represent the horizontal and vertical coordinates, and w and h are the width and height of the prediction box.

[0110] S26, display: draw the bounding box of the detected multiple targets, the target category and the confidence level on the original image, and mark the calculated target distance.

[0111] In summary, with the help of the above technical scheme of the present invention, the present invention provides a multi-target detection and ranging method based on Swin Transformer and ZED camera, which integrates Swin Transformer target detection and ZED binocular ranging, and effectively solves the difficulty of terminal equipment to realize multi-target detection and multi-target ranging in real time; compared with traditional detection and ranging methods, this method can quickly and intelligently detect and extract targets, and calculate target distances, which is suitable for industrial scenarios such as car obstacle avoidance and drone tracking.

[0112] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0113] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0114] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0115] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0116] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the technical principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. Multi-target detection and ranging method based on Swin Transformer and ZED camera, It is characterized in that The method comprises the following steps: S1. Train the Swin Transformer target detector using preset training hyperparameters to obtain a Swin Transformer target detection model. S2, using the Swin Transformer target detection model and ZED camera to achieve real-time detection and ranging of multiple targets; The S2 uses the Swin Transformer target detection model and the ZED camera to achieve real-time detection and ranging of multiple targets, including the following steps: S21, initialization: initializing the camera parameters and Swin Transformer target detection model; S22, read the flag bit to determine whether to exit the program: read the keyboard status and determine whether to exit the program; S23, read image: use the ZED binocular camera to read the left camera color image, send it to the Swin Transformer target detection model, and determine whether the image is successfully read. If so, execute S24, otherwise return to S22; S24, object detection: Use the Swin Transformer object detection model to read a new image and predict the bounding box, confidence, and category confidence information of the object in the image; S25, target ranging: According to the prediction results of the Swin Transformer target detection model and the ZED camera depth map, the distance of each target is calculated to achieve multi-target ranging; S26, display: draw the outer bounding box of the multi-target detected by the target, the target category and the confidence level on the original image, and mark the calculated target distance; In S25, the distance of each target is calculated according to the prediction result of the Swin Transformer target detection model and the ZED camera depth map to realize multi-target ranging, which includes the following steps: S251, predicting the target frame according to the Swin Transformer target detection model, obtaining the target category, the coordinates of the upper left corner of the target frame, and the length and width (x, y, w, h) of the target; S252, using the ZED camera to obtain a depth image Dst of each pixel distance; S253, obtaining the depth values ​​of the upper left corner, upper right corner, lower left corner, lower right corner and the neighborhood 3x3 of the center point of the target frame; S254, performing median filtering on the depth pixels at the upper left corner, upper right corner, lower left corner, lower right corner and center point of the target frame; The filtering formula is ddst(x, y) = med{Dst(x+k, y+l), (k, l∈[-1, 1])}, where ddst represents the median filter calculation result, Dst represents the depth map, med means taking the middle value in the set, x and y represent the horizontal and vertical coordinates, k and l are the traversal values ​​on the horizontal and vertical coordinates, between the interval [-1, 1]; S255, taking the depth value of the target frame center point after filtering as the target distance, to achieve multi-target ranging; The formula for the depth value is ddst(x+w / 2, y+h / 2), where ddst represents the median filter calculation result, x and y represent the horizontal and vertical coordinates, and w and h are the width and height of the prediction box.

2. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 1, It is characterized in that In S1, the Swin Transformer target detector is trained using preset training parameters to obtain a Swin Transformer target detection model, which includes the following steps: S11. Make a data set: Download the COCO data set, shuffle the data set, and extract the training set, validation set, and test set according to the preset ratio; S12, data expansion: use basic image expansion method to expand the training data; S13. Set training hyperparameters: Set the training hyperparameters of the Swin Transformer object detector; S14. Model training: Train the Swin Transformer target detector according to the training hyperparameters and the prepared data set to obtain the Swin Transformer target detection model.

3. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 2, It is characterized in that The expansion of the training data in S12 includes: cropping, random rotation, horizontal flipping, color conversion and several expansion methods for the target cropping strategy; The training hyperparameters of the Swin Transformer target detector set in S13 include: the number of images per training batch, the input image width, the image height, the number of image channels, the impulse, the initial learning rate, the weight decay coefficient, the learning rate adjustment parameter, the maximum number of iterations, the optimizer, and the threshold.

4. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 1, It is characterized in that The initialization process of the camera parameters and the Swin Transformer target detection model in S21 includes the following steps: S211, initializing camera parameters; S212. Create a new child thread for the Swin Transformer object detection model; S213, initializing the Swin Transformer target detection model.

5. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 4, It is characterized in that The initialization process of the camera parameters in S211 specifically includes the following steps: Set the camera acquisition mode to WVGA; Set the camera frame rate to 100; Set the size of the collected image to 672x386.

6. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 4, It is characterized in that The initialization process of the Swin Transformer target detection model in S213 specifically includes: reading the model configuration file config and the weight file checkpoint.

7. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 1, It is characterized in that The step S22 of reading the keyboard status and determining whether to exit the program includes the following steps: Read the keyboard status to determine whether there is keyboard input q or Esc. If so, set the exit flag to true, close the SwinTransformer target detection model, close the child thread, and exit the main program; otherwise, execute S23.

8. The multi-target detection and ranging method based on Swin Transformer and ZED camera according to claim 1, It is characterized in that In S24, the Swin Transformer target detection model is used to read a new image, and the prediction of the bounding box, confidence, and category confidence information of the target in the image includes the following steps: S241, load the Swin Transformer target detection model; S242, determine whether the exit flag is true, if it is true, close the Swin Transformer target detection model and exit the thread, if it is false, execute S243; S243, determine whether there is a new input image, if not, return to S242 after a delay of 1ms, if there is a new input image, enter S244; S244, image format conversion, converting the Mat type image of Opencv3 into the image type of the Swin Transformer target detection model; S245, inputting the converted image type image into the Swin Transformer target detection model, and predicting the bounding box, confidence, and category confidence information of the target in the image; S246, change the data flag to detection end, pass it to the main thread, and return to S242.