Target object distance measurement method, device, equipment and readable storage medium

By using a monocular ranging method at the construction site to obtain the shooting distance and included angle of the target object, and using geometric relationships to calculate the object spacing, the problems of accuracy and cost in object spacing detection at the construction site are solved, and the calculation accuracy and efficiency are improved.

CN113607064BActive Publication Date: 2026-11-24GLODON CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202110902462.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-08-06
Publication Date
2026-11-24
Estimated Expiration
2041-08-06

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately detect the distance between objects at construction sites, especially under lighting and complex background conditions, and are also costly.

Method used

By acquiring the target image captured by the camera lens, the shooting distance and angle between the target object and the lens are determined. The distance between objects is calculated using geometric relationships, avoiding the differences in angles of multiple cameras and the construction of a three-dimensional coordinate system. A monocular ranging method is adopted.

Benefits of technology

It has improved the accuracy and efficiency of object spacing measurement while reducing costs, reduced errors, and enabled timely detection of safety hazards.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113607064B_ABST
    Figure CN113607064B_ABST
Patent Text Reader

Abstract

This invention relates to the field of object ranging technology, and discloses a method, apparatus, device, and readable storage medium for calculating the distance between target objects. The method includes: acquiring a target image captured by a camera lens, wherein the target image includes at least two target objects; determining the shooting distance from each target object to the camera lens and the shooting angle corresponding to each target object from the target image; and determining the distance between the target objects based on the geometric relationship between the shooting angle and the shooting distance. By implementing this invention, the distance between target objects can be accurately measured without the use of other equipment, and a single camera lens can be used to capture the target objects, avoiding perspective problems caused by differences in shooting angles of different cameras, further reducing errors in the distance calculation and improving the accuracy of the distance calculation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of object ranging technology, specifically to a method, apparatus, device, and readable storage medium for calculating the distance between target objects. Background Technology

[0002] Construction sites typically contain various construction objects, and when the distance between some of these objects is less than the safe distance, it can pose a safety hazard to the construction site and workers. Examples include oxygen cylinders and acetylene cylinders. Multiple cameras are usually installed at construction sites to monitor and photograph these objects. Currently, distance detection between construction objects in images primarily involves using OpenCV to detect the objects in the image and then using common dimensional knowledge of the objects to measure the distance; or using a terminal device (containing at least two cameras) to capture a 2D image of the objects and determine the 3D coordinates of the objects and the distance to the terminal device based on camera parameters; or using a depth sensor to construct a 3D coordinate system and then combining it with lens parameters such as focal length to determine the distance. However, these methods are either easily affected by lighting and complex background environments, require only one camera to capture a specific scene at the construction site, or are costly, making accurate distance detection between objects in images difficult. Summary of the Invention

[0003] In view of this, embodiments of the present invention provide a method, apparatus, device, and readable storage medium for calculating the distance between target objects, so as to solve the problem that the distance between objects in an image is difficult to detect accurately.

[0004] According to a first aspect, embodiments of the present invention provide a method for calculating the distance between target objects, comprising: acquiring a target image captured by a camera lens, the target image including at least two target objects; determining from the target image the shooting distance from each target object to the camera lens and the shooting angle corresponding to each target object; and determining the distance between the target objects based on the geometric relationship between the shooting angle and the shooting distance.

[0005] The target object spacing calculation method provided in this invention acquires target images captured by a camera lens, determines the shooting distance from each target object to the camera lens and the shooting angle corresponding to each target object from the target image, and determines the spacing between each target object based on the geometric relationship between the shooting angle and the shooting distance. This method calculates the spacing between target objects by determining the geometric relationship between the shooting distance from each target object to the camera lens and the shooting angle corresponding to each target object from the target image, without the need for other equipment. This reduces the cost of calculating object spacing while ensuring accurate measurement. Furthermore, this method can use a single camera lens with a uniform shooting angle to capture target objects, thereby avoiding perspective problems caused by differences in shooting angles of different cameras, further reducing errors in target object spacing calculation and improving the accuracy of spacing calculation.

[0006] In conjunction with the first aspect, in a first embodiment of the first aspect, determining the shooting angle corresponding to each target object from the target image includes: obtaining the actual distance from the target object to the target plane, the target plane being the plane determined by the shooting lens and the central axis of the target image; and determining the shooting angle corresponding to the target object based on the ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the shooting lens.

[0007] In conjunction with the first embodiment of the first aspect, in the second embodiment of the first aspect, obtaining the actual distance from the target object to the target plane includes: obtaining the pixel width of the target object, the actual width of the target object, the actual width of the target image, and the center horizontal coordinate of the target object in the target image; and calculating the actual distance from the target object to the target plane based on the actual width of the target object, the actual width of the target image, the center horizontal coordinate of the target object in the target image, and the pixel width of the target object.

[0008] In conjunction with the second embodiment of the first aspect, in the third embodiment of the first aspect, the step of calculating the actual distance from the target object to the target plane based on the actual width of the target object, the actual width of the target image, the center horizontal coordinate of the target object in the target image, and the pixel width of the target object includes: obtaining the center horizontal coordinate of the target image; calculating the difference between the center horizontal coordinate of the target object in the target image and the center horizontal coordinate of the target image to obtain a first difference; calculating the ratio between the pixel width of the target object and the actual width of the target object to obtain a first ratio; and calculating the actual distance from the target object to the target plane based on the first difference and the ratio between the first difference and the actual distance from the target object to the target plane being equal to the first ratio.

[0009] The target object distance calculation method provided in this invention obtains the actual distance from the target object to the target plane, and then determines the shooting angle corresponding to the target object based on the ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the shooting lens. This method can determine the shooting angle corresponding to the target object without constructing a three-dimensional coordinate system, simplifying the calculation method of the shooting angle and improving calculation efficiency while ensuring calculation accuracy.

[0010] In conjunction with the second embodiment of the first aspect, in the fourth embodiment of the first aspect, obtaining the pixel width of the target object includes: obtaining the target bounding box corresponding to the target object, as well as the target pixel width and target pixel height of the target bounding box; calculating the tilt angle of the target object based on the target pixel width and the target pixel height; and calculating the pixel width of the target object based on the geometric relationship between the tilt angle, the target pixel width, and the target pixel height.

[0011] In conjunction with the fourth embodiment of the first aspect, in the fifth embodiment of the first aspect, the step of calculating the tilt angle of the target object based on the target pixel width and the target pixel height includes: obtaining the actual height of the target object; calculating the ratio of the actual height of the target object to the actual width of the target object to obtain a second ratio; calculating the ratio of the target pixel width to the target pixel height to obtain a third ratio; and calculating the tilt angle corresponding to the target object based on the product and difference of the second ratio and the third ratio.

[0012] The target object spacing calculation method provided in this embodiment of the invention generates a target bounding box corresponding to the target object on a two-dimensional image based on the target object being placed at an angle. The method obtains the target pixel width and target pixel height of the target bounding box, calculates the tilt angle of the target object based on the ratio of the actual height to the actual width of the target object and the ratio of the target pixel width to the target pixel height, and then calculates the pixel width of the target object according to the geometric relationship between the tilt angle, the target pixel width, and the target pixel height, so that the calculation of the pixel width satisfies different tilt states and reduces the calculation error of the pixel width.

[0013] In conjunction with the fifth embodiment of the first aspect, in the sixth embodiment of the first aspect, the step of calculating the ratio of the target pixel width to the target pixel height to obtain a third ratio includes: determining whether the target object in the target image is occluded; when the target object in the target image is occluded, adjusting the target pixel width; and adjusting the third ratio based on the target pixel height and the adjusted target pixel width.

[0014] The target object spacing calculation method provided in this embodiment of the invention determines whether the target object in the target image is occluded. When occlusion occurs, the target pixel width of the target bounding box is less than the actual value, while the target pixel height is almost the same. Therefore, when the target object in the target image is occluded, the target pixel width is adjusted, and then the third ratio between the target pixel height and the target pixel width is adjusted to reduce the calculation error caused by occlusion.

[0015] In conjunction with the fifth embodiment of the first aspect, in the seventh embodiment of the first aspect, calculating the pixel width of the target object based on the geometric relationship between the tilt angle, the target pixel width, and the target pixel height includes: determining whether the tilt angle is a preset angle; when the tilt angle is not the preset angle, calculating the cosine value of the tilt angle and the sine value of the tilt angle; and calculating the pixel width of the target object based on the product of the target pixel height and the cosine value of the tilt angle and the product of the target pixel width and the sine value of the tilt angle.

[0016] In conjunction with the seventh embodiment of the first aspect, in the eighth embodiment of the first aspect, the step of calculating the pixel width of the target object based on the geometric relationship between the tilt angle, the target pixel width of the target bounding box, and the target pixel height of the target bounding box further includes: when the tilt angle is a preset angle, calculating the pixel width of the target object based on the target pixel height and the second ratio.

[0017] The target object spacing calculation method provided in this embodiment of the invention determines the pixel width of the target object by judging whether the tilt angle is a preset angle and using different calculation methods for the tilt angle that is a preset angle and the tilt angle that is not a preset angle, thereby further ensuring the accuracy of the pixel width of the target object.

[0018] In conjunction with the first aspect, in the ninth embodiment of the first aspect, determining the shooting distance from each of the target objects to the shooting lens from the target image includes: obtaining the imaging correlation coefficient corresponding to the target object; and calculating the shooting distance from each of the target objects to the shooting lens based on the imaging correlation coefficient, the pixel width of the target object, and the actual width of the target image.

[0019] The target object distance calculation method provided in this embodiment of the invention is based on the principle that target objects appear larger when closer and smaller when farther away. It calculates the shooting distance from each target object to the shooting lens by using the imaging correlation coefficient of the target object, the pixel width of the target object, and the actual width of the target image, thus ensuring that the shooting distance is calculated accurately.

[0020] In conjunction with the first aspect, in the tenth embodiment of the first aspect, determining the spacing between the various target objects based on the geometric relationship between the shooting angle and the shooting distance includes: calculating the difference in shooting angle between different target objects; and obtaining the spacing between the various target objects based on the difference and the shooting distance from the different target objects to the shooting lens.

[0021] In conjunction with the tenth embodiment of the first aspect, in the eleventh embodiment of the first aspect, obtaining the spacing between each target object based on the difference and the different shooting distances of the target objects to the shooting lens includes: calculating the square of the shooting distances of the different target objects to the shooting lens and the cosine of the difference in the shooting angle; calculating the product between the shooting distances of the different target objects to the shooting lens and the cosine value; and calculating the spacing between each target object based on the product and the square of the shooting distances of the different target objects to the shooting lens.

[0022] The target object spacing calculation method provided in this invention calculates the distance between different target objects by calculating the difference in the shooting angle between them, and then using the law of cosines. Based on this difference in shooting angle and the shooting distance from each target object to the shooting lens, the spacing between each target object is calculated. This method is simple to calculate and improves the efficiency of spacing calculation while ensuring accuracy, thus facilitating timely determination of whether there are any safety hazards in the placement of target objects.

[0023] In conjunction with the first aspect, in the twelfth embodiment of the first aspect, the method for calculating the distance between target objects further includes: determining whether the distance between target objects of different categories is less than a preset safety distance; when the distance between target objects of different categories is less than the preset safety distance, it is determined that there is a safety hazard.

[0024] The target object spacing calculation method provided in this embodiment of the invention determines whether the spacing between different types of target objects is less than a preset safety spacing. When the spacing between different types of target objects is less than the preset safety spacing, it is determined that there is a safety hazard. This allows for timely understanding of whether there is a safety hazard in the placement of target objects, so that the position of the target objects with safety hazards can be adjusted to ensure safety.

[0025] According to a second aspect, embodiments of the present invention provide a target object distance calculation device, comprising: an acquisition module for acquiring a target image captured by a shooting lens, the target image including at least two target objects; a first determination module for determining, from the target image, the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object; and a second determination module for determining, based on the geometric relationship between the shooting angle and the shooting distance, the distance between the target objects.

[0026] The target object distance calculation device provided in this invention calculates the distance between target objects by determining the shooting distance from each target object to the shooting lens and the geometric relationship between the shooting angles of each target object and the shooting distance determined from the target image. This eliminates the need for additional equipment, reducing the cost of calculating object distances while ensuring accurate measurement. Furthermore, the device can use a single shooting lens with a uniform shooting angle to capture images of the target objects, thereby avoiding perspective problems caused by differences in shooting angles of different lenses, further reducing errors in target object distance calculation and improving the accuracy of distance calculation.

[0027] According to a third aspect, embodiments of the present invention provide an electronic device, including: a memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the computer instructions to perform the target object spacing calculation method described in the first aspect or any embodiment of the first aspect.

[0028] According to a fourth aspect, embodiments of the present invention provide a computer-readable storage medium storing computer instructions for causing a computer to perform the distance calculation method for a target object as described in the first aspect or any embodiment of the first aspect. Attached Figure Description

[0029] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0030] Figure 1 This is a flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention;

[0031] Figure 2 This is another flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention;

[0032] Figure 3 This is another flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention;

[0033] Figure 4 This is a schematic diagram of the target bounding box corresponding to the target object according to an embodiment of the present invention;

[0034] Figure 5 This is a schematic diagram of the tilt angle corresponding to the target object according to an embodiment of the present invention;

[0035] Figure 6 This is a geometrical schematic diagram of the target object, target plane, and shooting lens according to an embodiment of the present invention;

[0036] Figure 7 This is a structural block diagram of a target object distance calculation device according to an embodiment of the present invention;

[0037] Figure 8 This is a schematic diagram of the hardware structure of the electronic device provided in an embodiment of the present invention. Detailed Implementation

[0038] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0039] Currently, distance detection between construction objects in images mainly involves using OpenCV to detect the objects and then measuring the distance using common-sense dimensional knowledge of the objects; alternatively, using a terminal device (containing at least two cameras) to capture a 2D image of the objects and determining the 3D coordinates of the objects and the distance to the terminal device based on camera parameters; or using a depth sensor to construct a 3D coordinate system and then combining it with parameters such as lens focal length to determine the distance to the objects. However, these methods are either easily affected by lighting and complex background environments, require only one camera to capture a specific scene at the construction site, or are costly, making it difficult to accurately detect the distance between objects in the image.

[0040] Based on this, the technical solution of the present invention can use a single camera lens to capture target images including different types of target objects, accurately detect different types of target objects in the target images, and calculate the actual distance between each detected target object.

[0041] According to an embodiment of the present invention, an embodiment of a method for measuring the distance of a target object is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.

[0042] This embodiment provides a method for calculating the distance between target objects, which can be used in electronic devices such as mobile phones, computers, and tablets. Figure 1 This is a flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention, as shown below. Figure 1 As shown, the process includes the following steps:

[0043] S11, acquire the target image captured by the camera lens, the target image includes at least two target objects.

[0044] The target image is an image captured by a camera lens that includes target objects, and the target image may include at least two target objects. After acquiring the target image captured by the camera lens, the electronic device identifies the target objects contained in the target image to determine the number and category of target objects present in the current target image. Specifically, the electronic device can collect multiple sample images containing target objects to form a dataset, train a target object detector based on a deep learning algorithm, and thus, after obtaining the target image captured by the camera lens, input the target image into the detector and output the target object recognition result.

[0045] Taking the detection of oxygen cylinders and acetylene cylinders at a construction site as an example, target images containing both oxygen cylinders and acetylene cylinders are collected as positive samples, and images of other types unrelated to oxygen cylinders and acetylene cylinders are collected evenly as negative samples. The positive and negative samples are integrated into an initial dataset. The initial dataset is then fed into an object detection model for training to obtain an initial detector. Bad cases in the dataset are analyzed, revealing that the detector may misdetect cylindrical bottles such as gas cylinders or fire extinguishers as target objects, or may misidentify objects that are obscured. For the former, images containing similar objects such as gas cylinders or fire extinguishers are added as negative samples, and for the latter, positive samples of that type are added, adjusting the ratio of positive to negative samples, and the detector is retrained. This process is repeated until the detector can accurately detect oxygen cylinders and acetylene cylinders and distinguish them from other similar bottle-shaped objects.

[0046] S12, determine the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object from the target image.

[0047] After identifying each target object contained in the target image, the electronic device uses each target object as a reference and calculates the distance from each target object to the shooting lens based on the principle of monocular ranging, that is, the shooting distance.

[0048] The electronic device can acquire the center coordinates of the target object in the target image and connect this center coordinates to the camera lens (line 1). This creates a two-dimensional plane based on the camera lens and the longitudinal central axis of the target image. The projection of the target object's center coordinates onto this plane is then connected to the camera lens (line 2). This allows the determination of the angle between line 1 and line 2, i.e., the shooting angle corresponding to the target object. Of course, the shooting angle can also be calculated using the shooting distance, the center coordinates of the target object in the target image, and the center coordinates of the target image; this application does not impose specific limitations on this.

[0049] S13 determines the spacing between each target object based on the geometric relationship between the shooting angle and the shooting distance.

[0050] After identifying each target object in the target image, the electronic device can fit it into a polygon on the two-dimensional target image. For example, a cylindrical target object can be fitted into a rectangle on the two-dimensional target image. At the same time, the electronic device can generate a bounding box corresponding to each target object, that is, the bounding box fits closely to the polygon. Based on the shooting angle and shooting distance between any two target objects and the two-dimensional geometric relationship corresponding to the bounding box, the distance between any two target objects can be calculated.

[0051] The target object spacing calculation method provided in this embodiment acquires target images captured by a camera lens, determines the shooting distance from each target object to the camera lens and the corresponding shooting angle of each target object from the target image, and determines the spacing between each target object based on the geometric relationship between the shooting angle and the shooting distance. This method calculates the spacing between target objects by determining the geometric relationship between the shooting distance from each target object to the camera lens and the corresponding shooting angle of each target object from the target image, without the need for other equipment. This reduces the cost of calculating object spacing while ensuring accurate measurement. Furthermore, this method can use a single camera lens with a uniform shooting angle to capture target objects, thereby avoiding perspective problems caused by differences in shooting angles of different cameras, further reducing errors in target object spacing calculation and improving the accuracy of spacing calculation.

[0052] This embodiment provides a method for calculating the distance between target objects, which can be used in electronic devices such as mobile phones, computers, and tablets. Figure 2 This is a flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention, as shown below. Figure 2 As shown, the process includes the following steps:

[0053] S21, acquire the target image captured by the camera lens, the target image including at least two target objects. For detailed explanation, please refer to the relevant description of step S11 in the above embodiment, which will not be repeated here.

[0054] S22, determine the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object from the target image.

[0055] Specifically, step S22 above may include:

[0056] S221, obtain the actual distance from the target object to the target plane, where the target plane is the plane determined by the shooting lens and the central axis of the target image.

[0057] A line and a point outside that line can define a plane. Here, we consider the camera lens as a point and the central axis of the target image as a line, with the camera lens not lying on the central axis. Therefore, the target plane can be determined by the relationship between the camera lens and the central axis of the target image. Since the ratio of the target image's pixel size to its actual size is constant, the actual distance from the target object to the target plane can be determined.

[0058] Specifically, step S221 above may include:

[0059] (1) Obtain the pixel width of the target object, the actual width of the target object, the actual width of the target image, and the center horizontal coordinate of the target object in the target image.

[0060] The pixel width of the target object is represented in pixels by the width of the target object in the target image, while the actual width of the target image is represented in pixels by the width of the image. The x-coordinate of the center of the target object in the target image is the x-axis coordinate of the center point of the target object in the target image.

[0061] Specifically, the steps to obtain the pixel width of the target object may include:

[0062] (11) Obtain the target bounding box corresponding to the target object, as well as the target pixel width and target pixel height of the target bounding box.

[0063] The target bounding box is the bounding box that surrounds the target object. After identifying each target object in the target image, the electronic device can fit and generate a polygon corresponding to each target object. The target bounding box is the bounding box that fits the polygon. The target pixel width of the target bounding box is represented by the width of the target bounding box in pixels, and the target pixel height is represented by the length of the target bounding box in pixels. For example... Figure 4As shown, the polygon (solid line) corresponding to the target object is a rectangle, and the target bounding box (dashed line) fits the slanted rectangle. The target pixel width of the target bounding box is w, and the target pixel width is h.

[0064] (12) Calculate the tilt angle of the target object based on the target pixel width and target pixel height.

[0065] The electronic device can calculate the tilt angle of the target object based on the target pixel width and target pixel height of the target image. Specifically, the calculation steps may include:

[0066] (121) Obtain the actual height of the target object, calculate the ratio of the actual height of the target object to the actual width of the target object, and obtain the second ratio.

[0067] The actual height and width of the target object can be determined through actual measurement. If the actual height is l... real The actual width is d real Therefore, the second ratio can be determined.

[0068] (122) Calculate the ratio of the target pixel width to the target pixel height to obtain the third ratio.

[0069] If the target bounding box has a target pixel width of w and a target pixel width of h, then the third ratio...

[0070] Optionally, when the target object is occluded, step (122) above may include:

[0071] 1) When the target object in the target image is occluded, adjust the target pixel width.

[0072] For occluded target objects, the h and w values ​​of the target bounding box detected by the electronic device have a slight error compared to the actual pixel values. After analyzing and observing all occluded target objects, it was found that the occlusion of target objects mainly falls into the following two categories:

[0073] a. The presence of other objects next to the target object prevents the target bounding box from completely enclosing the target object in the width dimension, resulting in the w value of the target bounding box being smaller than the actual pixel width;

[0074] b. If only a portion of the target object is within the target image, it is equivalent to being truncated in the width dimension, which will also cause the w value of the target bounding box to be smaller than the actual pixel value.

[0075] Based on the two occlusion scenarios described above, to reduce the error caused by occlusion, the target pixel width can be adjusted. Specifically, if Then adjust the target pixel width The reasons are as follows:

[0076] The ratio of the target pixel height to the target pixel width of the target bounding box is The ratio of the target object's pixel height to its pixel width is Since the target object is usually placed at an angle, h will be smaller than l, and w will be larger than d, resulting in When either of the above two occlusion scenarios occurs, the w value of the target bounding box is smaller than the actual pixel value, while the h value has almost no error. This will cause... Therefore, this logic can be used to check whether there is an occlusion problem of the target object. If If true, it means the target object is occluded. In this case, the ratio of the pixel height to the pixel width of the target bounding box is... The default value is the ratio α of the pixel height to the pixel width of the target object when it is standing upright; that is, the w value is set to...

[0077] 2) Adjust the third ratio based on the target pixel height and the adjusted target pixel width.

[0078] The adjusted target bounding box has a target pixel width of 100 pixels. If the target pixel width is h, then adjust the third ratio.

[0079] (123) Based on the product and difference of the second ratio and the third ratio, the tilt angle corresponding to the target object is calculated.

[0080] like Figure 4 As shown, the tilted rectangle is generated by fitting the shape of the target object, and its pixel value represents the pixel value of the target object. Its pixel width is d, its pixel height is l, the target pixel width of the target bounding box is w, the target pixel width of the target bounding box is h, and the tilt angle is θ. The following relationship can be obtained:

[0081]

[0082]

[0083]

[0084]

[0085] make Finally, we can obtain That is, the tangent of the tilt angle corresponding to the target object can be calculated based on the product and difference of the second ratio and the third ratio.

[0086] Based on the tangent of the tilt angle, the corresponding tilt angle θ of the target object can be obtained. In the above formula, α is equivalent to the ratio of the bottle's actual height to its actual width, i.e.

[0087] (13) The pixel width of the target object is calculated based on the geometric relationship between the tilt angle, the target pixel width and the target pixel height.

[0088] From ① and ② above, we can obtain Substituting it into equation ①, we can obtain

[0089]

[0090] Multiplying both sides of ③ by sinθ and simplifying further, we can obtain the expression for the pixel width d of the target object as follows:

[0091]

[0092] Where θ is the tilt angle of the target object, w is the target pixel width, and h is the target pixel width. Therefore, once the tilt angle θ, the target pixel width w, and the target pixel width h are determined, the pixel width d of the target object can be calculated.

[0093] Specifically, step (13) above may include:

[0094] (131) Determine whether the tilt angle is the preset angle.

[0095] When the preset angle is h = w, the tilt angle of the target object is 45°. After the electronic device calculates the tilt angle of the target object, it compares it with the preset angle to determine whether it is equal to the preset angle. If the tilt angle is not the preset angle, step (132) is executed; otherwise, step (134) is executed.

[0096] (132) Calculate the cosine and sine values ​​of the inclination angle.

[0097] When the tilt angle is not the preset angle, calculate the cosine value of the target pixel height (cosθ) and the sine value of the tilt angle (sinθ).

[0098] (133) Calculate the pixel width of the target object based on the product of the target pixel height and the cosine of the tilt angle and the product of the target pixel width and the sine of the tilt angle.

[0099] Calculate the product of the target pixel height and the cosine of the tilt angle, hcosθ, and the product of the target pixel width and the sine of the tilt angle, wsinθ. Based on hcosθ, wsinθ, and the above formula ④, the pixel width of the target object can be calculated.

[0100] (134) The pixel width of the target object is calculated based on the target pixel height and the second ratio.

[0101] When the tilt angle is the preset angle, since θ is 45° ° ,like Figure 5 As shown, in this case, both the numerator and denominator of formula ④ are 0, so formula ④ cannot be used to calculate the pixel width d of the target object. In this special case, it is necessary to calculate the pixel width d of the target object using other methods. The specific derivation steps are as follows:

[0102] First, such as Figure 5 As shown, And because Therefore Therefore, the pixel width of the target object can be obtained as:

[0103]

[0104] Where w is the target pixel width, h is the target pixel width, and α is the ratio of the pixel height to the pixel width of the target object (the second ratio).

[0105] (2) Based on the actual width of the target object, the actual width of the target image, the center horizontal coordinate of the target object in the target image, and the pixel width of the target object, the actual distance from the target object to the target plane is calculated.

[0106] Based on the principle that the ratio of pixel size to actual size is consistent, electronic devices can determine the target object's pixel width d and the target object's actual width d based on the target object's pixel width d and actual width d. real The actual distance x from the target object to the target plane can be calculated from the x-coordinate of the center of the target object in the target image and the actual width of the target image, img_w. real .

[0107] Specifically, step (2) above may include:

[0108] (21) Obtain the center abscissa of the target image, calculate the difference between the center abscissa of the target object in the target image and the center abscissa of the target image, and obtain the first difference.

[0109] If the x-coordinate of the center of the target object in the target image is x, and the actual width of the target image is img_w, then the x-coordinate of the center of the target image is img_w / 2. From this, the first difference x-img_w / 2 can be calculated.

[0110] (22) Calculate the ratio between the pixel width of the target object and the actual width of the target object to obtain the first ratio.

[0111] If the pixel width d of the target object is d, and the actual width d of the target object is dreal Then the first ratio can be calculated.

[0112] (23) The actual distance from the target object to the target plane is calculated based on the first difference and the ratio between the actual distance from the target object to the target plane being equal to the first ratio.

[0113] If the actual distance from the target object to the target plane is x real Then the first difference x-img_w / 2 and the actual distance x from the target object to the target plane are... real The ratio between them is based on Ratio to the first If they are equal, then we can obtain Therefore, the actual distance to the target plane can be calculated as follows:

[0114]

[0115] S222, Based on the ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the shooting lens, determine the shooting angle corresponding to the target object.

[0116] like Figure 6 As shown, if the calculated actual distance from a target object to the target plane is x... real And the shooting distance from the target object to the camera lens is d1. The ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the camera lens is the sine of the shooting angle, that is:

[0117]

[0118] Where γ1 is the shooting angle corresponding to the target object, and d real Let d1 be the actual width of the target object, d1 be the shooting distance from the target object to the camera lens, x be the horizontal coordinate of the center of the target object in the target image, and img_w be the actual width of the target image. Similarly, the shooting angles for other target objects can be obtained.

[0119] S223, determine the shooting distance from each target object to the shooting lens from the target image. For detailed explanation, please refer to the relevant descriptions in the above embodiments; they will not be repeated here.

[0120] S23: Based on the geometric relationship between the shooting angle and the shooting distance, determine the spacing between each target object. For a detailed explanation, please refer to the relevant description of step S13 in the above embodiment; it will not be repeated here.

[0121] The target object distance calculation method provided in this embodiment obtains the actual distance from the target object to the target plane, and then determines the shooting angle corresponding to the target object based on the ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the shooting lens. This eliminates the need to construct a three-dimensional coordinate system to determine the shooting angle, simplifying the calculation method and improving computational efficiency while ensuring accuracy. Given the tilted placement of the target object, a target bounding box corresponding to the target object is generated on the two-dimensional image. The target pixel width and height of the bounding box are obtained, and the tilt angle corresponding to the target object is calculated based on the ratio of the actual height to the actual width of the target object, and the ratio of the target pixel width to the target pixel height. Then, based on the geometric relationship between the tilt angle, target pixel width, and target pixel height, the pixel width of the target object is calculated to ensure that the pixel width calculation satisfies different tilt states and reduces calculation errors. When the target object in the target image is occluded, the target pixel width is adjusted, and consequently, the third ratio between the target pixel height and the target pixel width is adjusted to reduce calculation errors caused by occlusion. By determining whether the tilt angle is a preset angle, different calculation methods are used to determine the pixel width of the target object for both preset and non-preset tilt angles, thereby further ensuring the accuracy of the pixel width of the target object.

[0122] This embodiment provides a method for calculating the distance between target objects, which can be used in electronic devices such as mobile phones, computers, and tablets. Figure 3 This is a flowchart of a method for calculating the distance between target objects according to an embodiment of the present invention, as shown below. Figure 3 As shown, the process includes the following steps:

[0123] S31, acquire the target image captured by the camera lens, the target image including at least two target objects. For detailed explanation, please refer to the relevant description of step S11 in the above embodiment, which will not be repeated here.

[0124] S32, determine the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object from the target image.

[0125] Specifically, step S32 above may include:

[0126] S321, determine the shooting angle corresponding to each target object from the target image. For detailed explanation, please refer to the relevant descriptions in the above embodiments; they will not be repeated here.

[0127] S322, obtain the imaging correlation coefficient corresponding to the target object.

[0128] Assuming the ratio of the pixel width of the target object to the actual width of the target image is δ, when the size of the target object is fixed, its shooting distance from the lens and δ are negatively correlated, and the correlation coefficient scale is a constant. The shooting distance of the target object from the lens in the target image is negatively correlated with the ratio of the target object's pixel width to the actual width of the target image, reflecting the principle that objects appear larger when closer and smaller when farther away. Based on a large number of images surveyed, this correlation coefficient scale is found to be 0.20.

[0129] S323 calculates the shooting distance from each target object to the shooting lens based on the imaging correlation coefficient, the pixel width of the target object, and the actual width of the target image.

[0130] Based on the imaging correlation coefficient, the pixel width of the target object, and the actual width of the target image, the formula for calculating the shooting distance can be obtained as follows:

[0131]

[0132] Where d1 is the shooting distance from a target object to the camera lens, scale is the imaging correlation coefficient, d is the pixel width of the target object, and img_w is the actual width of the target image. Similarly, the shooting distances corresponding to each target object can be obtained.

[0133] It should be noted that d in the above formula is the pixel width of the current target object. When calculating the shooting distance of other target objects, it needs to be replaced with the pixel width of the other target objects. For a detailed explanation of the calculation of pixel width, please refer to the relevant description in the above embodiment, which will not be repeated here.

[0134] S33 determines the spacing between each target object based on the geometric relationship between the shooting angle and the shooting distance.

[0135] Specifically, step S33 above may include:

[0136] S331, calculate the difference in shooting angle between different target objects.

[0137] When two different target objects are located to the left and right of the center of the target image, the x-img_w / 2 of one of the target objects will be negative. Therefore, the shooting angles γ1 and γ2 corresponding to the two different target objects will definitely have one negative value and one positive value, such as... Figure 6 As shown; when two different target objects are on the same side of the center of the target image, the two shooting angles γ1 and γ2 are both positive or both negative, so the difference in shooting angle between different target objects is |γ1-γ2|.

[0138] S332, based on the difference and the shooting distance of different target objects from the shooting lens, obtains the spacing between each target object.

[0139] Electronic devices can calculate the distance between any two target objects based on the difference in shooting angles and the shooting distances from different target objects to the shooting lens, using the law of cosines.

[0140] Specifically, step S332 above may include:

[0141] (1) Calculate the square of the shooting distance from different target objects to the shooting lens, and the cosine of the difference in shooting angle.

[0142] like Figure 6 As shown, if the shooting distances from any two different target objects to the camera lens are d1 and d2 respectively, then the square of the shooting distances from any two different target objects to the camera lens can be calculated as d1. 2 and d2 2 And the cosine value of the difference in shooting angles, cos(γ1-γ2). Since the cosine function is a symmetric function, the cosine value is always cos(γ1-γ2) regardless of whether the difference in shooting angles is positive or negative.

[0143] (2) Calculate the product between the shooting distance from different target objects to the shooting lens and the cosine value.

[0144] If the shooting distances from any two different target objects to the camera lens are d1 and d2 respectively, and the cosine value of the difference in the shooting angle is cos(γ1-γ2), then the product value d1d2cos(γ1-γ2) between the shooting distances from the target objects to the camera lens and the cosine value can be calculated.

[0145] (3) Based on the product value and the square of the shooting distance from different target objects to the shooting lens, the distance between each target object is calculated.

[0146] Based on the product value calculated above and the squared values ​​of the shooting distances from different target objects to the camera lens, the formula for calculating the distance between any two different target objects can be obtained as follows:

[0147]

[0148] Where d_o_a is the distance between any two different target objects O and target object A, d1 and d2 are the shooting distances from target object O and target object A to the shooting lens, respectively, and γ1-γ2 is the difference in the shooting angle between target object O and target object A.

[0149] S34, determine whether the distance between target objects of different categories is less than the preset safe distance.

[0150] The preset safety distance is the minimum distance between different categories of target objects that pose a safety hazard. For different categories of target objects that may pose a safety hazard if placed too close together, the electronic device calculates the distance between the different categories of target objects and compares it with the preset safety distance to determine whether the distance is less than the preset safety distance. When the distance between different categories of target objects is less than the preset safety distance, step S35 is executed; otherwise, it indicates that the distance between the target objects is safe.

[0151] S35 was determined to pose a safety hazard.

[0152] When the distance between different types of target objects is less than the preset safety distance, it indicates that the placement of the target objects is insufficient and poses a safety hazard. In this case, the electronic device can send a reminder message so that the user can adjust the placement of the target objects in a timely manner.

[0153] Taking oxygen and acetylene cylinders at a construction site as an example, if they are placed too close together, it could pose a safety hazard. Electronic equipment detects the oxygen and acetylene cylinders in the target image captured by a camera lens to identify them and calculates the distance between them to determine if it is less than a preset safety distance. If the distance is less than the preset safety distance, it indicates insufficient spacing between the oxygen and acetylene cylinders, posing a safety hazard. In this case, the electronic equipment can send a reminder message to the relevant person in charge at the construction site, enabling them to adjust the placement of the oxygen and acetylene cylinders in a timely manner, ensuring the safety of construction.

[0154] The target object spacing calculation method provided in this embodiment is based on the principle that objects appear larger when closer and smaller when farther away. It calculates the shooting distance from each target object to the camera lens by using the imaging correlation coefficient of the target object, the pixel width of the target object, and the actual width of the target image, ensuring accurate shooting distance calculation. By calculating the difference in shooting angles between different target objects and combining it with the law of cosines, the spacing between each target object is calculated based on this difference in shooting angles and the shooting distance from the different target objects to the camera lens. This method is simple to calculate and improves the efficiency of spacing calculation while ensuring accuracy. When the spacing between different types of target objects is less than a preset safety spacing, it is determined that there is a safety hazard. This allows for timely identification of whether there are safety hazards in the placement of target objects, enabling the repositioning of target objects with safety hazards to ensure safety.

[0155] This embodiment also provides a distance measurement device for a target object, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.

[0156] This embodiment provides a device for calculating the distance to a target object, such as... Figure 7 As shown, it includes:

[0157] The acquisition module 41 is used to acquire a target image captured by the shooting lens, wherein the target image includes at least two target objects. For detailed explanation, please refer to the relevant descriptions in the above method embodiments, which will not be repeated here.

[0158] The first determining module 42 is used to determine the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object from the target image. For detailed explanation, please refer to the relevant descriptions in the above method embodiments, which will not be repeated here.

[0159] The second determining module 43 is used to determine the spacing between each target object based on the geometric relationship between the shooting angle and the shooting distance. For detailed explanation, please refer to the relevant descriptions in the above method embodiments; they will not be repeated here.

[0160] In this embodiment, the target object distance measurement device is presented in the form of a functional unit. Here, a unit refers to an ASIC circuit, a processor and memory that execute one or more software or fixed programs, and / or other devices that can provide the above functions.

[0161] Further functional descriptions of the above modules are the same as those in the corresponding embodiments described above, and will not be repeated here.

[0162] This invention also provides a mobile terminal having the above-described features. Figure 7 The distance measuring device for the target object shown.

[0163] Please see Figure 8 , Figure 8 This is a schematic diagram of the structure of a terminal provided in an optional embodiment of the present invention, such as... Figure 8As shown, the terminal may include: at least one processor 501, such as a CPU (Central Processing Unit), at least one communication interface 503, memory 504, and at least one communication bus 502. The communication bus 502 is used to enable communication between these components. The communication interface 503 may include a display screen and a keyboard; optionally, the communication interface 503 may also include a standard wired interface or a wireless interface. The memory 504 may be high-speed RAM (Random Access Memory) or non-volatile memory, such as at least one disk storage device. Optionally, the memory 504 may also be at least one storage device located remotely from the aforementioned processor 501. The processor 501 may be combined with... Figure 7 The described apparatus has an application program stored in memory 504, and a processor 501 calls the program code stored in memory 504 to perform any of the above method steps.

[0164] The communication bus 502 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The communication bus 502 can be divided into an address bus, a data bus, and a control bus, etc. For ease of representation, Figure 8 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.

[0165] The memory 504 may include volatile memory, such as random-access memory (RAM); the memory may also include non-volatile memory, such as flash memory, hard disk drive (HDD) or solid-state drive (SSD); the memory 504 may also include a combination of the above types of memory.

[0166] The processor 501 can be a central processing unit (CPU), a network processor (NP), or a combination of CPU and NP.

[0167] The processor 501 may further include a hardware chip. This hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0168] Optionally, memory 504 is also used to store program instructions. Processor 501 can call the program instructions to implement the functions described in this application. Figures 1 to 3 The method for calculating the distance between target objects shown in the embodiment.

[0169] This invention also provides a non-transitory computer storage medium storing computer-executable instructions that can execute the processing method of the target object distance calculation method in any of the above method embodiments. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk drive (HDD), or solid-state drive (SSD), etc.; the storage medium may also include combinations of the above types of memory.

[0170] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A method of measuring the distance of a target object, characterized by, include: Acquire a target image captured by a camera lens, wherein the target image includes at least two target objects; The shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object are determined from the target image; the shooting angle is the angle between two lines, one of which is the line connecting the center coordinate point of the target object in the target image and the shooting lens, and the other line is the line connecting the projection point of the center coordinate point of the target object on the target plane and the shooting lens, and the target plane is the two-dimensional plane determined by the shooting lens and the central axis of the target image; Based on the geometric relationship between the shooting angle and the shooting distance, the spacing between each target object is determined; The step of determining the spacing between the target objects based on the geometric relationship between the shooting angle and the shooting distance includes: Calculate the difference in the shooting angle between different target objects; Based on the difference and the different shooting distances of the target objects to the shooting lens, the spacing between each target object is obtained.

2. The method according to claim 1, characterized in that, Determining the shooting angle corresponding to each target object from the target image includes: Obtain the actual distance from the target object to the target plane; The shooting angle corresponding to the target object is determined based on the ratio of the actual distance from the target object to the target plane to the shooting distance from the target object to the shooting lens.

3. The method according to claim 2, characterized in that, The step of obtaining the actual distance from the target object to the target plane includes: Obtain the pixel width of the target object, the actual width of the target object, the actual width of the target image, and the center x-coordinate of the target object in the target image; Based on the actual width of the target object, the actual width of the target image, the center horizontal coordinate of the target object in the target image, and the pixel width of the target object, the actual distance from the target object to the target plane is calculated.

4. The method according to claim 3, characterized in that, The calculation of the actual distance from the target object to the target plane based on the actual width of the target object, the actual width of the target image, the center horizontal coordinate of the target object in the target image, and the pixel width of the target object includes: Obtain the center abscissa of the target image, calculate the difference between the center abscissa of the target object in the target image and the center abscissa of the target image, and obtain the first difference; Calculate the ratio between the pixel width of the target object and the actual width of the target object to obtain a first ratio; The actual distance from the target object to the target plane is calculated based on the fact that the ratio between the first difference and the actual distance from the target object to the target plane is equal to the first ratio.

5. The method according to claim 3, characterized in that, Obtaining the pixel width of the target object includes: Obtain the target bounding box corresponding to the target object, as well as the target pixel width and target pixel height of the target bounding box; The tilt angle of the target object is calculated based on the target pixel width and the target pixel height. The pixel width of the target object is calculated based on the geometric relationship between the tilt angle, the target pixel width, and the target pixel height.

6. The method according to claim 5, characterized in that, The step of calculating the tilt angle of the target object based on the target pixel width and the target pixel height includes: Obtain the actual height of the target object, calculate the ratio of the actual height of the target object to the actual width of the target object, and obtain a second ratio. Calculate the ratio of the target pixel width to the target pixel height to obtain a third ratio; The tilt angle corresponding to the target object is calculated based on the product and difference of the second ratio and the third ratio.

7. The method according to claim 6, characterized in that, The calculation of the ratio of the target pixel width to the target pixel height to obtain the third ratio includes: Determine whether the target object in the target image is occluded; When the target object in the target image is occluded, adjust the target pixel width; The third ratio is adjusted based on the target pixel height and the adjusted target pixel width.

8. The method according to claim 6, characterized in that, Based on the geometric relationship between the tilt angle, the target pixel width, and the target pixel height, the pixel width of the target object is calculated, including: Determine whether the tilt angle is a preset angle; When the tilt angle is not the preset angle, calculate the cosine value of the tilt angle and the sine value of the tilt angle; The pixel width of the target object is calculated based on the product of the target pixel height and the cosine of the tilt angle, and the product of the target pixel width and the sine of the tilt angle.

9. The method according to claim 8, characterized in that, The step of calculating the pixel width of the target object based on the geometric relationship between the tilt angle, the target pixel width of the target bounding box, and the target pixel height of the target bounding box further includes: When the tilt angle is a preset angle, the pixel width of the target object is calculated based on the target pixel height and the second ratio.

10. The method according to claim 1, characterized in that, Determining the shooting distance from each target object to the shooting lens from the target image includes: Obtain the imaging correlation coefficient corresponding to the target object; Based on the imaging correlation coefficient, the pixel width of the target object, and the actual width of the target image, the shooting distance from each of the target objects to the shooting lens is calculated.

11. The method according to claim 1, characterized in that, The process of obtaining the spacing between various target objects based on the difference and the different shooting distances of the target objects to the shooting lens includes: Calculate the square of the shooting distance from the target object to the shooting lens for different targets, and the cosine of the difference in the shooting angle; Calculate the product between the shooting distance of the target object to the shooting lens and the cosine value for different targets; Based on the product value and the square of the shooting distance from the target object to the shooting lens, the distance between each target object is calculated.

12. The method according to claim 1, characterized in that, Also includes: Determine whether the distance between the target objects of different categories is less than a preset safety distance; When the distance between target objects of different categories is less than the preset safety distance, it is determined that there is a safety hazard.

13. A device for measuring the distance to a target object, characterized in that, include: An acquisition module is used to acquire a target image captured by a camera lens, wherein the target image includes at least two target objects; The first determining module is used to determine the shooting distance from each target object to the shooting lens and the shooting angle corresponding to each target object from the target image; the shooting angle is the angle between two lines, one of which is the line connecting the center coordinate point of the target object in the target image and the shooting lens, and the other line is the line connecting the projection point of the center coordinate point of the target object on the target plane and the shooting lens; the target plane is a two-dimensional plane determined by the shooting lens and the central axis of the target image. The second determining module is used to determine the spacing between the target objects based on the geometric relationship between the shooting angle and the shooting distance; The step of determining the spacing between the target objects based on the geometric relationship between the shooting angle and the shooting distance includes: Calculate the difference in the shooting angle between different target objects; Based on the difference and the different shooting distances of the target objects to the shooting lens, the spacing between each target object is obtained.

14. An electronic device, characterized in that, include: The device includes a memory and a processor, which are interconnected. The memory stores computer instructions, and the processor executes the computer instructions to perform the distance calculation method for the target object as described in any one of claims 1-12.

15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions for causing a computer to execute the distance calculation method for the target object according to any one of claims 1-12.

Citation Information

Patent Citations

  • Target object positioning method and device, storage medium and electronic equipment

    CN111292372A

  • Target detection method and device based on monocular image

    CN112183241A

  • Multi-target reconnaissance and distance measurement method based on monocular camera

    CN112781562A