A camera spatial positioning method based on a single image
Through a single image-based camera spatial positioning method, linear clusters and plane unidirectional matrix transformation, combined with PnP method, the problem of camera pose estimation in the prior art requires three-dimensional reconstruction and multiple images, and fast and simple camera positioning is achieved.
Patent Information
- Application Number
- CN202311741853.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-18
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2043-12-18
AI Technical Summary
In the prior art, camera pose estimation in AR applications requires three-dimensional reconstruction, and the method based on multiple images has a large amount of computing and slow positioning speed in small-scale scenarios, which cannot meet specific needs.
设计了一种基于单张图像的相机空间定位方法,通过获取图像中的直线簇或近似矩形,寻找近似直线对或矩形,获得平面单应矩阵进行图像变换,设置特征点并逆投影,最后通过PnP法获得相机的位姿。
It realizes that camera spatial positioning can be performed with only a single picture, avoids the steps of three-dimensional reconstruction, simplifies operations, and improves positioning speed and accuracy.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a camera space positioning method, in particular to a camera space positioning method based on a single image, and belongs to the field of visual positioning. Background Art
[0002] Camera pose estimation plays a vital role in the implementation of AR (Augmented Reality). Accurate pose estimation is a necessary condition for accurately superimposing virtual objects in real scenes.
[0003] In the prior art, in AR applications, before estimating the camera pose, the scene needs to be reconstructed in three dimensions, which is generally done using the SLAM (Simultaneous Localization And Mapping) method. The basis of SLAM is multi-view geometry theory. For real-time video applications such as AR, it must meet certain parallax requirements, so multiple images are needed for camera positioning.
[0004] In the prior art, for small-scale scenes, the PnP method (Perspective-n-Point) can also be used to solve the camera positioning problem. However, the prerequisite for the PnP algorithm to solve the camera posture is that the 3D coordinates of n (n>3) three-dimensional reference points and their corresponding 2D coordinates on the image must be obtained in advance. The larger n is, the more robust the algorithm is. The 3D coordinates of the reference points are generally obtained through three-dimensional reconstruction methods. Both SLAM and SfM (Structure from Motion) three-dimensional reconstruction methods require the participation of multiple images.
[0005] In some small-scale AR scenarios, only relative positioning is required. The existing three-dimensional reconstruction positioning based on multiple images is relatively complex, and the amount of calculation and positioning speed cannot meet specific needs.
[0006] Due to the above reasons, it is necessary to propose a simple and fast positioning method for planar small-scale AR scenes. Summary of the invention
[0007] In order to overcome the above problems, the present invention has conducted in-depth research and designed a camera spatial positioning method based on a single image, comprising the following steps:
[0008] S1, obtaining a cluster of straight lines or an approximate rectangle in the original image scene; when a cluster of straight lines is obtained, searching for at least one pair of approximate straight line pairs in the cluster of straight lines, wherein the approximate straight line pair refers to two straight lines that are approximately parallel or approximately perpendicular;
[0009] The approximate rectangle refers to the contour line obtained after photographing the actual rectangular object;
[0010] S2. Obtain a plane homography matrix, and transform the original image by the plane homography matrix to obtain a transformed image, wherein the plane homography matrix is a transformation matrix that can map an approximate straight line pair into a completely parallel or perpendicular straight line pair, or can map an approximate rectangle into a rectangle;
[0011] S3, setting feature points on the transformed image, and using the plane homography matrix to inversely project the feature points to the original image to obtain image coordinates of the feature points in the original image;
[0012] S4. According to the coordinates of the feature points in the transformed image and the coordinates on the original image, the position and posture of the camera are obtained by the PnP method.
[0013] In a preferred embodiment, in step S1, the searching for at least one pair of approximate straight line pairs in the straight line cluster is obtained by filtering the straight line cluster.
[0014] In a preferred embodiment, in S1, the filtering includes distance filtering.
[0015] In a preferred implementation, in S1, the original picture refers to a single picture taken by a camera.
[0016] In a preferred embodiment, S3 includes the following sub-steps:
[0017] S31, setting feature points on the transformed image;
[0018] S32, using the image plane of the transformed image as the z=0 plane, constructing a three-dimensional coordinate system based on the transformed image, and obtaining the coordinate value of the feature point in the three-dimensional coordinate system, which is called the transformed feature point coordinate;
[0019] S33. Transform the coordinates of the transformed feature points using a plane homography matrix to obtain the coordinates of the feature points in the original image.
[0020] In a preferred embodiment, the approximately parallel straight lines refer to straight lines with an angle between the two straight lines being less than 10 degrees, and the approximately vertical lines refer to straight lines with an angle between the two straight lines being 80 to 100 degrees.
[0021] In a preferred embodiment, before step S1, there is further step S0 of preprocessing the image; the preprocessing includes one or more of image grayscale, image equalization, contrast enhancement, image denoising, and skeleton extraction.
[0022] The present invention also discloses a camera space positioning device based on a single image, comprising a straight line cluster acquisition module, an image transformation module, a feature point extraction module and a posture solution module.
[0023] The straight line acquisition module is used to acquire a straight line cluster or an approximate rectangle in the original image scene;
[0024] The image transformation module is used to obtain a plane homography matrix, and transform the image through the plane homography matrix to obtain a transformed image;
[0025] The feature point extraction module is used to set the feature points on the transformed image, reversely project the feature points to the original image, and obtain the image coordinates of the feature points in the original image;
[0026] The posture solving module obtains the positioning of the camera through the PnP method according to the coordinates of the feature points in the transformed image and the coordinates of the feature points on the original image.
[0027] The present invention also provides an electronic device, comprising:
[0028] at least one processor; and
[0029] A memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any of the methods described above.
[0030] The present invention also provides a computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute any of the above-mentioned methods.
[0031] The beneficial effects of the present invention include:
[0032] (1) Only a single image is needed to achieve camera spatial positioning;
[0033] (2) Camera spatial positioning can be achieved without 3D reconstruction;
[0034] (3) The positioning method is simple, the amount of calculation is low, and the positioning speed is fast. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] Figure 1 A schematic flow chart of a camera spatial positioning method based on a single image according to a preferred embodiment of the present invention is shown;
[0036] Figure 2 A schematic diagram of an original image of a camera space positioning method based on a single image according to a preferred embodiment of the present invention is shown;
[0037] Figure 3 A schematic diagram of straight line recognition of a camera space positioning method based on a single image according to a preferred embodiment of the present invention is shown;
[0038] Figure 4 A schematic diagram showing transformation of an original image in a camera space positioning method based on a single image according to a preferred embodiment of the present invention is shown. DETAILED DESCRIPTION
[0039] The present invention will be further described in detail below through the accompanying drawings and embodiments. Through these descriptions, the characteristics and advantages of the present invention will become more clear and distinct.
[0040] The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration." Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments. Although various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless otherwise noted.
[0041] According to a single-image-based camera spatial positioning method provided by the present invention, the camera is spatially positioned for an AR scene with similar straight-line edges, and further, the camera is spatially positioned for objects with parallel or vertical straight-line edges in the AR scene.
[0042] Furthermore, positioning can be performed after the camera captures a single image, without waiting for the camera to provide multiple images.
[0043] Further, the method comprises the following steps:
[0044] S1, obtaining a cluster of straight lines or an approximate rectangle in the original image scene; when a cluster of straight lines is obtained, searching for at least one pair of approximate straight line pairs in the cluster of straight lines, wherein the approximate straight line pair refers to two straight lines that are approximately parallel or approximately perpendicular;
[0045] The approximate rectangle refers to the contour line obtained after photographing the actual rectangular object;
[0046] S2. Obtain a plane homography matrix, and transform the original image by the plane homography matrix to obtain a transformed image, wherein the plane homography matrix is a transformation matrix that can map an approximate straight line pair into a completely parallel or perpendicular straight line pair, or can map an approximate rectangle into a rectangle;
[0047] S3, setting feature points on the transformed image, and using the plane homography matrix to inversely project the feature points to the original image to obtain image coordinates of the feature points in the original image;
[0048] S4. According to the coordinates of the feature points in the transformed image and the coordinates of the feature points in the original image, the position and posture of the camera are obtained by the PnP method.
[0049] Preferably, before step S1, there is further step S0 of preprocessing the image; by preprocessing the image, the image complexity is reduced and the image data is simplified, so as to facilitate the subsequent acquisition and detection of straight lines.
[0050] Furthermore, in the present invention, there is no particular limitation on the specific preprocessing method, which may include one or more of image grayscale, image equalization, contrast enhancement, image denoising, skeleton extraction, and the like.
[0051] The original image refers to a single image taken by a camera. The present invention can obtain the camera posture through a single image taken by a camera, and the positioning speed is faster.
[0052] In step S1, the straight line is obtained by Hough transform, which is a feature detection method widely used in image analysis, computer vision and digital image processing.
[0053] Furthermore, through Hough transform, multiple straight line segments in the image can be identified to obtain straight line clusters in the image scene.
[0054] In a preferred embodiment, the step of searching for at least one pair of approximate straight line pairs in the straight line cluster is obtained by filtering the straight line cluster.
[0055] Preferably, the process of filtering to obtain approximately parallel straight line pairs includes the following sub-steps:
[0056] S101, selecting the longest straight line in the straight line cluster;
[0057] S102, searching for a line that is approximately parallel to the longest line, and if there is no approximately parallel line, deleting the longest line; if there is an approximately parallel line, combining all the approximately parallel lines with the longest line into at least one approximately parallel line pair, and removing the line in the approximately parallel line pair from the line cluster;
[0058] S103, repeat steps S101 to S102 to process the remaining lines in the line cluster.
[0059] Preferably, in S102, the approximately parallel straight lines refer to straight lines where the angle between the two straight lines is less than an angle threshold. More preferably, the angle threshold is set to 10 degrees.
[0060] Preferably, the filtering further includes distance filtering:
[0061] When the distance between two approximately parallel straight lines is less than a distance threshold, the shorter straight line is deleted. More preferably, the distance threshold is set to 0.2 times the minimum value of the image width and the image height. In the present invention, by setting a distance threshold, multiple straight lines at the same position are screened out to avoid affecting subsequent processing.
[0062] Preferably, the process of filtering to obtain approximately vertical straight line pairs includes the following sub-steps:
[0063] S111. Select the longest straight line in the straight line cluster;
[0064] S112, searching for a straight line that is approximately perpendicular to the longest straight line, and if there is no approximately perpendicular straight line, deleting the longest straight line; if there is an approximately perpendicular straight line, combining all the approximately perpendicular straight lines with the longest straight line into at least one approximately perpendicular straight line pair, and removing the straight line in the approximately perpendicular straight line pair from the straight line cluster;
[0065] S113. Repeat steps S111 to S112 to process the remaining lines in the line cluster.
[0066] The pair of approximately perpendicular straight lines refers to two straight lines whose included angle is 80 to 100 degrees.
[0067] In step S2, the plane homography matrix is obtained by performing least squares optimization on a pair of approximate straight lines or an approximate rectangle. In the present invention, the specific obtaining method is not limited, and those skilled in the art can obtain it in any known manner, such as by using the method provided in OpenCV.
[0068] In a preferred embodiment, when there are multiple pairs of approximate straight line pairs, the plane homography matrix is calculated for each pair of approximate straight line pairs respectively, and then they are checked against each other; if all pass the check, then any pair of approximate straight line pairs is selected to calculate the plane homography matrix; if the check does not pass, then the plane homography matrix is calculated for the pair of approximate straight line pairs with the longest straight line length.
[0069] Furthermore, the original image can be transformed by the plane homography matrix, such as Figure 4 As shown, a transformed image is obtained, in which the straight lines in the straight line pair are completely parallel or perpendicular.
[0070] Preferably, S3 includes the following sub-steps:
[0071] S31, setting feature points on the transformed image;
[0072] S32, using the image plane of the transformed image as the z=0 plane, constructing a three-dimensional coordinate system based on the transformed image, and obtaining the coordinate value of the feature point in the three-dimensional coordinate system, which is called the transformed feature point coordinate;
[0073] S33. Transform the coordinates of the transformed feature points using a plane homography matrix to obtain the coordinates of the feature points in the original image.
[0074] In step S31, there is no restriction on the specific type of feature points, which may be any type of feature points such as optical flow points, ORB points, SIFT points, SURF points, etc. Those skilled in the art may freely select them according to their needs.
[0075] Preferably, S31 includes the following sub-steps:
[0076] S311, obtaining feature points at different positions on the transformed image;
[0077] S312, constructing a priority queue using the modulus of the feature point as the strength of the feature point, and placing all feature points into the priority queue;
[0078] S313. By using the Delaunary triangulation method, the feature points in the priority queue are inserted into the triangulated network in sequence, and the 150-200 strongest feature points are selected from the priority queue in descending order of distance, and these feature points are retained, and the feature points at other positions are deleted.
[0079] In S311, any known method may be used to obtain feature points at different positions on the image, for example, by calling an Open CV algorithm library.
[0080] In S313, the Delaunary triangulation method can speed up the search efficiency and improve the spatial positioning speed;
[0081] Furthermore, by selecting the 150-200 strongest feature points from the priority queue in descending order of distance, the obtained feature points can take into account both strength and mutual distance dispersion, greatly improving the positioning accuracy.
[0082] More preferably, S313 includes the following sub-steps:
[0083] S3131, setting a distance threshold;
[0084] S3132 traverses the priority queue, and for each feature point, obtains three adjacent feature points corresponding to the three vertices of the triangle where the feature point is located, calculates the minimum distance between the three adjacent feature points and the feature point, and when the minimum distance is greater than the distance threshold, selects the feature point and removes the feature point from the priority queue to obtain a new priority queue;
[0085] S3133, reduce the distance threshold, repeat step S3132, traverse the new priority queue, and select feature points;
[0086] S3134. Repeat step S3133 and reduce the distance threshold multiple times until the number of selected feature points reaches 150-200.
[0087] Preferably, in S3131, initially, the distance threshold is set to a larger value, for example, 1 / 2 of the minimum length and width of the image.
[0088] Preferably, in S3132, the distance threshold is reduced according to the golden ratio.
[0089] In step S4, the camera positioning can be obtained by using the PnP method (Perspective-n-Point, n-point perspective method) according to the transformed feature point coordinates of the feature points and the coordinates of the original image.
[0090] The projection transformation matrix M is obtained by combining the PnP algorithm with the least squares rule, so that the two-dimensional coordinate points obtained after the transformed feature point coordinates are transformed by the M matrix have the smallest deviation from the corresponding coordinate points of the feature points on the original image in the sense of least squares.
[0091] When solving the M matrix, the strength of the feature point and the distance from the feature point to the center point of the transformed image are used as the weight of the least squares calculation to improve the stability of the algorithm. The greater the strength of the feature point, the greater the weight, and the farther the distance from the feature point to the center point of the transformed image, the greater the weight.
[0092] Preferably, based on the result of the first solution, feature points with errors greater than a specific threshold are eliminated and then the solution is performed again, so as to improve the accuracy of the final solution.
[0093] Example
[0094] Example 1
[0095] To position the camera, after the camera captures a single image, perform the following steps:
[0096] Step S0, preprocessing the image; the preprocessing includes image grayscale, contrast enhancement, and image denoising;
[0097] S1, obtaining a cluster of straight lines in the original image scene; searching for at least one pair of approximate straight line pairs in the cluster of straight lines, wherein the approximate straight line pair refers to two straight lines that are approximately parallel and the angle between the two straight lines is less than 10 degrees;
[0098] S2, obtaining a plane homography matrix, transforming the image by the plane homography matrix to obtain a transformed image;
[0099] S3, setting feature points on the transformed image, inversely projecting the feature points to the original image, and obtaining image coordinates of the feature points in the original image;
[0100] S4. According to the coordinates of the feature points in the transformed image and the coordinates of the feature points in the original image, the position and posture of the camera are obtained by the PnP method.
[0101] In step S1, the straight line is obtained by Hough transform, and the filtering includes the following sub-steps:
[0102] S101, selecting the longest straight line in the straight line cluster;
[0103] S102, searching for a line that is approximately parallel to the longest line, and if there is no approximately parallel line, deleting the longest line; if there are approximately parallel lines, combining all the approximately parallel lines with the longest line into at least one approximately parallel line pair, and removing the line in the approximately parallel line pair from the line cluster;
[0104] S103, repeat steps S101 to S102 to process the remaining straight lines in the straight line library cluster
[0105] The filtering also includes distance filtering:
[0106] When the distance between two parallel straight lines is less than a distance threshold, the shorter straight line is deleted. More preferably, the distance threshold is set to 0.2 times the minimum value of the image width and the image height.
[0107] In step S2, the plane homography matrix is obtained by performing a least squares optimization solution on the approximate straight line pairs.
[0108] In step S3, feature points are extracted from the transformed image, and the feature points are optical flow points.
[0109] S3 includes the following sub-steps:
[0110] S31, setting feature points on the transformed image;
[0111] S32, using the image plane of the transformed image as the z=0 plane, constructing a three-dimensional coordinate system based on the transformed image, and obtaining the coordinate value of the feature point in the three-dimensional coordinate system, which is called the transformed feature point coordinate;
[0112] S33. Transform the coordinates of the transformed feature points using a plane homography matrix to obtain the coordinates of the feature points in the original image.
[0113] S31 includes the following sub-steps:
[0114] S311, obtaining feature points at different positions on the transformed image;
[0115] S312, constructing a priority queue using the modulus of the feature point as the strength of the feature point, and placing all feature points into the priority queue;
[0116] S313. By using the Delaunary triangulation method, the feature points in the priority queue are inserted into the triangulated network in sequence, and the 150 strongest feature points are selected from the priority queue in descending order of distance. These feature points are retained, and the feature points at other positions are deleted.
[0117] S313 includes the following sub-steps:
[0118] S3131, setting a distance threshold, wherein the distance threshold is set to 1 / 2 of the minimum length and width of the image;
[0119] S3132 traverses the priority queue, and for each feature point, obtains three adjacent feature points corresponding to the three vertices of the triangle where the feature point is located, calculates the minimum distance between the three adjacent feature points and the feature point, and when the minimum distance is greater than the distance threshold, selects the feature point and removes the feature point from the priority queue to obtain a new priority queue;
[0120] S3133, reduce the distance threshold, repeat step S3132, traverse the new priority queue, and select feature points;
[0121] S3134. Repeat step S3133 and reduce the distance threshold multiple times until the number of selected feature points reaches 150.
[0122] In step S4, the camera positioning is obtained by the PnP method according to the coordinates of the feature points in the transformed image.
[0123] Comparative Example 1
[0124] Using the same camera, the SFM (Structure From Motion) method is used to obtain camera positioning. The SFM method is currently the most commonly used camera positioning method.
[0125] Experimental example
[0126] After obtaining the camera positioning in Example 1 and Comparative Example 1, the camera positioning accuracy is tested using a common testing method in the industry. Specifically,
[0127] For Example 1, 150 detection points are set on the shooting target, and an image with a size of 960 pixels * 720 pixels is taken as the original image; for Comparative Example 1, in addition to this image, two more images of the same size are taken as the original images;
[0128] According to the positioning relationship of the camera, the 150 detection points set on the target are reprojected onto the captured image to obtain the reprojected detection points;
[0129] The reprojected detection points are compared with the image detection points to obtain the detection point deviation, which is called the reprojection error. The size of the reprojection error is used as a measure of positioning accuracy. The smaller the error, the higher the positioning accuracy.
[0130] The camera positioning accuracy test results in Example 1 and Comparative Example 1 are shown in Table 1.
[0131] Table 1
[0132]
[0133] It can be seen from the table that although the positioning method in Example 1 only needs to capture one image, the positioning accuracy obtained by the method in Example 1 is almost the same as that of the method in Comparative Example 1.
[0134] The present invention also provides a camera space positioning device based on a single image, comprising a straight line cluster acquisition module, an image transformation module, a feature point extraction module and a posture solution module.
[0135] The straight line acquisition module is used to acquire straight line clusters or approximate rectangles in the original image scene, preferably extracting straight line clusters in the image through Hough transform;
[0136] The image transformation module is used to obtain a plane homography matrix, and transform the original image through the plane homography matrix to obtain a transformed image;
[0137] The feature point extraction module is used to set the feature points on the transformed image, reversely project the feature points to the original image, and obtain the image coordinates of the feature points in the original image;
[0138] The posture solving module obtains the positioning of the camera through the PnP method according to the coordinates of the feature points in the transformed image and the coordinates of the feature points on the original image.
[0139] Various embodiments of the methods and devices described above in the present invention can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs, which may be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general programmable processor, which may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0140] The program code for implementing the method of the present invention can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or server.
[0141] In the context of the present invention, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0142] To provide interaction with a user, the methods and apparatus described herein may be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0143] The methods and apparatus described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communications network). Examples of communications networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0144] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship between the client and the server is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services ("Virtual Private Server", or "VPS" for short). The server may also be a server of a distributed system, or a server combined with a blockchain.
[0145] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in the present disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution disclosed in the present invention can be achieved, and this document does not limit this.
Claims
1. A camera spatial positioning method based on a single image, characterized in that: The following steps are involved: S1, obtaining a cluster of straight lines or an approximate rectangle in the original image scene; when a cluster of straight lines is obtained, searching for at least one pair of approximate straight line pairs in the cluster of straight lines, wherein the approximate straight line pair refers to two straight lines that are approximately parallel or approximately perpendicular; The approximate rectangle refers to the contour line obtained after photographing the actual rectangular object; S2. Obtain a plane homography matrix, and transform the original image by the plane homography matrix to obtain a transformed image, wherein the plane homography matrix is a transformation matrix that can map an approximate straight line pair into a completely parallel or perpendicular straight line pair, or can map an approximate rectangle into a rectangle; S3, setting feature points on the transformed image, and using the plane homography matrix to inversely project the feature points to the original image to obtain image coordinates of the feature points in the original image; S4, obtaining the position and posture of the camera by the PnP method according to the coordinates of the feature points in the transformed image and the coordinates of the feature points in the original image; S3 includes the following sub-steps: S31, setting feature points on the transformed image; S32, using the image plane of the transformed image as the z=0 plane, constructing a three-dimensional coordinate system based on the transformed image, and obtaining the coordinate value of the feature point in the three-dimensional coordinate system, which is called the transformed feature point coordinate; S33. Transform the coordinates of the transformed feature points using a plane homography matrix to obtain the coordinates of the feature points in the original image.
2. The camera spatial positioning method based on a single image according to claim 1, characterized in that: In step S1, at least one pair of approximate straight line pairs is found in the straight line cluster, and is obtained by filtering the straight line cluster.
3. The camera spatial positioning method based on a single image according to claim 2, characterized in that: In S1, the filtering includes distance filtering.
4. The camera spatial positioning method based on a single image according to claim 1, characterized in that: In S1, the original image refers to a single image taken by a camera.
5. The camera spatial positioning method based on a single image according to claim 1, characterized in that: The approximately parallel straight lines refer to straight lines where the angle between the two straight lines is less than 10 degrees, and the approximately perpendicular straight lines refer to straight lines where the angle between the two straight lines is 80 to 100 degrees.
6. The camera spatial positioning method based on a single image according to claim 1, characterized in that: Before step S1, there is also step S0 of preprocessing the image; the preprocessing includes one or more of image grayscale, image equalization, contrast enhancement, image denoising, and skeleton extraction.
7. An electronic device comprising: at least one processor; as well as A memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor so that the at least one processor can execute the method of any one of claims 1-6.
8. A computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-6.
Citation Information
Patent Citations
Camera internal reference and external reference estimation method and device, computer equipment and storage medium
CN113658279A