A real-time counting method and system for people entering and exiting based on depth camera
The real-time counting method of people entering and exiting through the depth camera, using technologies such as image scanning and rectangular expansion, solves the problem of efficiency and accuracy of counting people in elevators, achieves real-time and accurate statistics in complex environments, and reduces resource waste and safety hazards.
Patent Information
- Application Number
- CN202210489562.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2042-05-06
AI Technical Summary
The existing elevator personnel entry and exit counting technology has problems such as low measurement efficiency, poor accuracy, inability to be used in dark environments, large amount of calculations in complex environments, and inability to achieve real-time judgment, resulting in waste of resources and potential safety hazards.
The real-time counting method of people entering and exiting based on the depth camera is used to achieve real-time dynamic statistics and counting of pedestrians of different heights through image scanning, point set division, binarization, rectangular expansion, generalized distance matrix matching and motion trajectory establishment.
It improves the accuracy and real-time performance of counting, is suitable for complex scenarios, reduces the time complexity of the algorithm, and achieves fast operation and efficient people counting.
Smart Images

Figure CN114882404B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of machine vision algorithms, and in particular to a method and system for real-time counting of people entering and exiting based on a depth camera. Background Art
[0002] As the number of floors increases, the elevator is always running at full power, which consumes a lot of energy and causes serious waste of resources. Adjusting the elevator operating power according to the number of people in the elevator can save a lot of energy. Existing technologies mainly use grating and weight sensors, RGB cameras, and neural networks to count the number of people entering and leaving the elevator.
[0003] Traditional gratings and weight sensors have disadvantages such as low measurement efficiency and poor accuracy, which will lead to large errors during use. At the same time, with low efficiency, there will be problems such as congestion at the entrance of the building and elevator, and even some safety hazards.
[0004] The counting of RGB cameras is limited by light issues and cannot be used in darker environments. If fill light is used, it will affect the comfort of riding in the elevator.
[0005] The recognition of human features using neural networks through deep learning is limited by complex environments such as dense crowds, people of different heights, and people leaning against each other. It requires a lot of information to be processed and requires a huge amount of calculation, making it impossible to achieve real-time judgment.
[0006] The above problems need to be solved urgently. To this end, a real-time counting method and system for the number of people entering and leaving based on a depth camera is proposed. Summary of the invention
[0007] The technical problem to be solved by the present invention is how to realize real-time dynamic statistics of pedestrians of different heights, and provides a real-time counting method for the number of people entering and leaving based on a depth camera.
[0008] The present invention solves the above technical problems through the following technical solutions, and the present invention comprises the following steps:
[0009] S1: Image Scanning
[0010] For each frame of the depth map, scan the frame according to the set scanning step size Nstep to obtain the pixel point set Sp;
[0011] S2: Point set partitioning
[0012] Compare the depth values of the pixels in the set Sp with the current value Hg of the shortest head position in the previous frame. Pixels greater than Hg are stored in the ground set Sgp, and pixels less than Hg are stored in the non-ground set Shp.
[0013] S3: Binarization
[0014] Take the pth g Percentile, where p g Take 85 to 95, then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame; take the pth from the non-ground set Shp h Percentile Hh, where p h Take 5 to 10, binarize the depth map according to the sum Hn of Hh and a head length constant Ln, extract the minimum bounding rectangle of the binary image and remove the minimum bounding rectangle with one side of the length and width less than 20 to 40 mm, and record the remaining minimum bounding rectangle as the newly obtained potential head area set Snph;
[0015] S4: Overlap judgment
[0016] The position overlap between each element of the set Snph and the already obtained potential head area set Saph is judged, and if there is no overlap, the element is added to the set Saph;
[0017] S5: Rectangular Extension
[0018] Expand each minimum bounding rectangle in the set Snph, delete the points in the set Shp that are within the expanded rectangle, and delete the elements above Hn in the set Shp to form a new set Shp;
[0019] S6: Adaptive Segmentation
[0020] Repeat steps S3 to S5 until the number of elements in the set Shp is less than the set threshold Nmhp, that is, the adaptive segmentation of the current frame is completed; the set Saph is recorded as the potential head area set Scph of the current frame;
[0021] S7: Generalized distance matrix construction
[0022] Establish a generalized distance matrix Md between the potential head region set Scph of the current frame and the potential head region set Shph of the historical frame;
[0023] S8: Set Matching
[0024] The elements of the generalized distance matrix Md are matched in order from small to large to complete the matching of the set Scph and the set Shph; if an element in the set Shph is matched for multiple consecutive frames, the element is upgraded to a head region; if an element in the set Shph is not matched for multiple consecutive frames, the element is deleted; all head regions constitute the head region set Sp;
[0025] S9: Motion trajectory establishment
[0026] Establish the motion trajectory of each element in the set Sp according to the center position of the element;
[0027] S10: Judgment and Statistics
[0028] The entry and exit directions and statistical counts are determined through the motion trajectory of the elements in the set Sp.
[0029] Furthermore, in step S1, the depth map is obtained by photographing the depth camera fixedly mounted on the elevator door frame perpendicular to the ground.
[0030] Furthermore, in step S3, the depth map is binarized, that is, pixels less than Hn are set to 1, and pixels greater than or equal to Hn are set to 0.
[0031] Furthermore, in step S4, the set Saph is set to an empty set before processing each frame.
[0032] Furthermore, in step S5, each element of the set Snph is expanded according to a set ratio value, and the expansion method is to expand the lengths of the two diagonals of the minimum circumscribed rectangle to the set lengths respectively.
[0033] Furthermore, in step S7, for each element in the set Shph, its position in the current frame is predicted based on its historical position information, and a generalized distance matrix Md is established based on the continuity of the head movement. The value in the rth row and cth column is the generalized distance between the midpoint of the rth element of the set Shph and the cth element of the set Scph. The generalized distance matrix Md is as follows:
[0034]
[0035] Furthermore, in the step S8, the minimum bounding rectangle T of each element in the set Snph is matched one by one with the minimum bounding rectangles of all elements in the set Saph. If any minimum bounding rectangle Ts of an element in Saph has more than z vertices in T, or the distance between the center points of the two rectangles is less than the length of any side of the two rectangles, it means that T has been detected and is directly discarded; otherwise, it is considered that a new element is detected and T is stored in the set Saph.
[0036] Furthermore, in step S8, the number of potential head regions in the historical frame is recorded as Nh; the number of potential head regions in the current frame is recorded as Nc; when the row where the minimum element of the generalized distance matrix Md is located is Rm and the column is Cn, it means that the Cnth element of the set Scph matches the Rmth element of the set Shph; then the elements of the Rmth row and Cnth column of the generalized distance matrix Md are set to a constant Nmax; repeat the above two steps until all elements in the matrix Md are Nmax, indicating that the matching is completed, and the number of matching pairs is recorded as Np; if Np is equal to Nh, it means that all elements of the set Shph match the elements of the set Scph. If matched, the set Scph generates Nc-Nh new elements; if Np is equal to Nc, it means that all elements of the set Scph are matched with the elements of the set Shph, and there are Nh-Nc elements of the set Shph that are not matched; if an element of the set Shph is not matched for Nnot consecutive frames, it means that the head area is out of the field of view, and the element is deleted from the set Shph; all elements of the set Scph and all remaining elements in the set Shph constitute the potential head area set Shph of the historical frame of the next frame; if an element of the set Shph is matched for Nfud consecutive frames, the potential head area is upgraded to the head area.
[0037] Furthermore, in step S10, if an element of the set Sp has been counted, the element is deleted.
[0038] The present invention also provides a real-time counting system for people entering and exiting based on a depth camera, which uses the above method to perform real-time counting of people entering and exiting, including:
[0039] An image scanning module is used to scan each frame of the depth map according to a set scanning step length Nstep to obtain a pixel point set Sp;
[0040] Point set partitioning module, used to compare the depth value of the pixel points in the set Sp with the current value Hg of the shortest head position in the previous frame, and store the pixel points greater than Hg in the ground set Sgp, and the pixel points less than Hg in the non-ground set Shp;
[0041] Binarization module is used to take the pth g Percentile, where p g Take 85 to 95, then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame; take the pth from the non-ground set Shp h Percentile Hh, where p hTake 5 to 10, binarize the depth map according to the sum Hn of Hh and a head length constant Ln, extract the minimum bounding rectangle of the binary image and remove the minimum bounding rectangle with one side of the length and width less than 20 to 40 mm, and record the remaining minimum bounding rectangle as the newly obtained potential head area set Snph;
[0042] An overlap judgment module is used to judge the position overlap between each element of the set Snph and the obtained potential head area set Saph. If there is no overlap, the element is added to the set Saph;
[0043] The rectangle expansion module is used to expand each minimum circumscribed rectangle in the set Snph, delete the points in the set Shp that are within the expanded rectangle, and delete the elements above Hn in the set Shp to form a new set Shp;
[0044] The adaptive segmentation module is used to repeat steps S3 to S5 until the number of elements in the set Shp is less than the set threshold Nmhp, that is, the adaptive segmentation of the current frame is completed; the set Saph is recorded as the potential head area set Scph of the current frame;
[0045] A matrix building module is used to build a generalized distance matrix Md between a potential head region set Scph of a current frame and a potential head region set Shph of a historical frame;
[0046] The set matching module is used to match the elements of the generalized distance matrix Md in ascending order to complete the matching of the set Scph and the set Shph; if an element in the set Shph is matched for multiple consecutive frames, the element is upgraded to a head region; if an element in the set Shph is not matched for multiple consecutive frames, the element is deleted; all head regions constitute the head region set Sp;
[0047] A trajectory establishment module is used to establish the motion trajectory of each element in the set Sp according to the center position of the element;
[0048] The judgment and statistics module is used to judge the entry and exit direction and count the movement trajectory of the elements of the set Sp;
[0049] The central processing module is used to issue instructions to other modules to complete related actions;
[0050] The image scanning module, point set division module, binarization module, overlap judgment module, rectangle expansion module, adaptive segmentation module, adaptive segmentation module, set matching module, trajectory establishment module, judgment and statistics module are all connected to the central processing module in communication.
[0051] Compared with the prior art, the present invention has the following advantages: the real-time counting method for the number of people entering and exiting based on the depth camera scans each frame according to a certain scanning step length to obtain a set of pixel points without scanning the entire frame, which greatly reduces the time complexity of the algorithm; the current value of the shortest head position of the next frame is obtained from the current frame, and the shortest head position is updated in real time with good accuracy; adaptive segmentation is performed on each frame to avoid frame loss during tracking, and it is suitable for complex scenes such as pedestrians with large height differences and mutual dependence, and the process is simple, stable and reliable; the potential head area set of the historical frame is matched with the potential head area set of the current frame using the generalized distance to form the potential head area set of the historical frame for the next frame, and the potential head area that is continuously matched to multiple reals is upgraded to the head area, and the head area set is updated in real time, which can have very good accuracy, stability and real-time performance; the entire process processes two-dimensional regular depth data, and there is no algorithm with high time complexity, so the running speed is fast and the real-time performance is strong, which is worthy of being promoted and used. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 is a method flow chart of a method for real-time counting of people entering and exiting based on a depth camera in Embodiment 1 of the present invention;
[0053] Figure 2 is a schematic diagram of the installation structure of the depth camera in the first embodiment of the present invention;
[0054] Figure 3 is a schematic diagram of single frame adaptive segmentation in Embodiment 2 of the present invention;
[0055] Figure 4 is a schematic diagram of the minimum rectangle in the second embodiment of the present invention;
[0056] Figure 5 This is a schematic diagram of the expansion of the minimum rectangular frame in the second embodiment of the present invention;
[0057] Figure 6 is a schematic diagram of single frame adaptive segmentation in Embodiment 3 of the present invention;
[0058] Figure 7 is a schematic diagram of the minimum rectangle in the third embodiment of the present invention;
[0059] Figure 8 This is a schematic diagram of the minimum rectangular frame expansion in the third embodiment of the present invention;
[0060] Fig. 9 This is a schematic diagram of matching the current frame with the historical frame in the fourth embodiment of the present invention;
[0061] Fig.10 This is a schematic diagram of matching the current frame with the historical frame in Embodiment 5 of the present invention;
[0062] Fig.11This is a schematic diagram of entry and exit judgment in Embodiment 6 of the present invention;
[0063] Fig.12 This is a schematic diagram of entry and exit judgment in the seventh embodiment of the present invention. DETAILED DESCRIPTION
[0064] The following is a detailed description of an embodiment of the present invention. This embodiment is implemented on the premise of the technical solution of the present invention, and a detailed implementation method and a specific operation process are given, but the protection scope of the present invention is not limited to the following embodiment.
[0065] Embodiment 1
[0066] like Figure 1 As shown, this embodiment provides a technical solution: a real-time counting method for people entering and leaving based on a depth camera, comprising: Figure 1 steps.
[0067] like Figure 2 As shown, first, the depth camera is fixed and vertically shoots the scene to obtain a regular depth image with a resolution of 640*480, and counts the number of people entering and leaving the field of view in real time. According to the elevator specifications, the elevator door height Hdoor is between 2000 and 3000. A minimum head height constant Cmh=800~1200 is taken, and the current value of the minimum head position in the first frame is manually specified Hg=Hdoor-Cmh. All distance units are mm.
[0068] Embodiment 2
[0069] This embodiment is a specific description of the single frame adaptive segmentation step in the method of embodiment 1, and the specific process is as follows:
[0070] (1) Figure 3 As shown, people enter the field of view one by one, and there is a certain interval between people. For this frame, according to a certain scanning step length Nstep = 10-100, scan this frame to obtain a pixel point set Sp; the depth value of the pixel point in Sp is compared with Hg, and the pixel point greater than Hg is stored in the potential head point set (ground set) Sgp, and the pixel point less than Hg is stored in the impossible potential head point set (non-ground set) Shp.
[0071] From the ground set Sgp, the percentile range is 85 to 95. For example, p g =90 percentile, then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame.
[0072] (2) Figure 4 As shown, the percentile range from 5 to 10 is taken from the non-ground set Shp. For example, the pth h=7 percentile Hh, according to Hh and the sum Hn of a head length constant Ln=90~150, the depth map is binarized and the pixels smaller than Hn are set to 1.
[0073] Clear the newly obtained potential head area set Snph.
[0074] Extract the minimum bounding rectangle of the binary image and remove the minimum bounding rectangle with one side less than 20-40 mm in length and width, which can be 30 mm here. The remaining two minimum bounding rectangles are recorded as T1 and T2 and added to the newly obtained potential head region set Snph.
[0075] (3) The potential head regions that have been obtained are recorded as set Saph, which is set to an empty set before processing each frame; the new potential head regions that are obtained are recorded as set Snph.
[0076] Because the set Saph is empty, there is no overlap judgment. Two new potential head areas T1 and T2 are detected, and the elements T1 and T2 in the set Snph are stored in the set Saph.
[0077] (4) Figure 5 As shown, the minimum bounding rectangles T1 and T2 in the set Snph are expanded according to a ratio value kep1, the elements in the set Shp that are within the rectangles are deleted, and the elements above Hn in the set Shp are deleted to form a new set Shp. For example, the lengths of the two diagonals of the minimum bounding rectangle T1 in the set Snph are Ndiag1 and Ndiag2 respectively, and the expansion ratio is selected as kep1=1.25~1.35, and the minimum bounding rectangle T1 in the set Snph can be expanded to Ndiag1*kep1 and Ndiag2*kep1 along the diagonal direction respectively.
[0078] (5) At this time, the number of elements in the set Shp is greater than the threshold Nmph=20~50, and the segmentation continues.
[0079] (6) Figure 4 As shown, take the pth h Percentile Hh, based on the sum Hn of Hh and the head length constant Ln, the depth map is binarized and pixels smaller than Hn are set to 1.
[0080] Clear the newly obtained potential head area set Snph.
[0081] The minimum bounding rectangle is extracted from the binary image and the minimum bounding rectangle with too small size is removed. The remaining three minimum bounding rectangles are recorded as T3, T4 and T5 and added to the newly obtained potential head area set Snph.
[0082] (7) The potential head regions that have been obtained are recorded as a set Saph; the new potential head regions that are obtained are recorded as a set Snph.
[0083] At this time, the set Snph has the minimum circumscribed rectangles T3, T4 and T5 of three elements, and the set Saph has the minimum circumscribed rectangles T1 and T2 of two elements.
[0084] The minimum bounding rectangles T3, T4 and T5 of the two elements in Snph are matched with the minimum bounding rectangles T1 and T3 in the set Saph respectively. If the minimum bounding rectangle T1 of the element in the set Saph has more than Ncp=1~3 vertices in T3, then T3 has been detected and is directly discarded; if the minimum bounding rectangle T2 of the element in the set Saph has more than Ncp=1~3 vertices in T4, then T4 has been detected and is directly discarded; if the minimum bounding rectangles T1 and T2 in the set Saph have no more than Ncp vertices in T5, and the midpoint distance between T1 and T5 is greater than the length of any side of T1 and T5, and the midpoint distance between T2 and T5 is greater than the length of any side of T2 and T5, then T5 is a new element and T5 is stored in the set Saph.
[0085] (8) Figure 5 As shown, the minimum circumscribed rectangles T3, T4 and T5 of the elements of the set Snph are expanded according to a proportional value, and the elements in the set Shp that are within the rectangles are deleted. At the same time, the elements above Hn in the set Shp are deleted to form a new set Shp.
[0086] For example, the lengths of the two diagonals of the minimum circumscribed rectangle T3 in the set Snph are Ndiag3 and Ndiag4 respectively, and the expansion ratio can be kep2=1.05-1.15, and the minimum circumscribed rectangle T2 in the set Snph is expanded to Ndiag3*kep2 and Ndiag4*kep2 respectively along the diagonal direction.
[0087] (9) At this time, the number of elements in the set Shp is less than the threshold Nmph, and the adaptive segmentation of the current frame is completed. The set Saph is the potential head region set Scph of the current frame. At this time, the set Scph contains three elements: T1, T2 and T5.
[0088] Embodiment 3
[0089] This embodiment is a specific description of the single frame adaptive segmentation step in the method of embodiment 1, and the specific process is as follows:
[0090] (1) Figure 6As shown, people enter the field of view one by one, with no gap between people. For this frame, scan this frame at a certain scanning step length Nstep = 10 to 100 to obtain a pixel point set Sp. The depth value of the pixel in Sp is compared with Hg. The pixel values greater than Hg are stored in the potential head point set (ground set) Sgp, and the pixel values less than Hg are stored in the impossible potential head point set (non-ground set) Shp. The percentile range from 85 to 95 can be taken from the ground set Sgp. For example, p g =92 percentile and then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame.
[0091] (2) Figure 7 As shown, the percentile range from 5 to 10 is taken from the non-ground set Shp. For example, p g =8 percentile, based on Hh and the sum Hn of a head length constant Ln=90~150, the depth map is binarized, and pixels less than Hn are set to 1, and pixels greater than or equal to Hn are set to 0.
[0092] Clear the newly obtained potential head area set Snph.
[0093] The minimum bounding rectangle is extracted from the binary image and the minimum bounding rectangle with too small size is removed. The remaining two minimum bounding rectangles are recorded as T1 and T2 and added to the newly obtained potential head area set Snph.
[0094] (3) The potential head regions that have been obtained are recorded as set Saph, which is set to an empty set before processing each frame; the new potential head regions that are obtained are recorded as set Snph.
[0095] Because the set Saph is empty, there is no overlap judgment. Two new potential head areas T1 and T2 are detected. The elements T1 and T2 in the set Snph are stored in the set Saph.
[0096] (4) Figure 8 As shown, the minimum circumscribed rectangular frames T1 and T2 in the set Snph are expanded according to a ratio value kep1, the elements in the set Shp located within the rectangles are deleted, and the elements above Hn in the set Shp are deleted to form a new set Shp.
[0097] For example, the lengths of the two diagonals of the minimum circumscribed rectangle T1 in the set Snph are Ndiag1 and Ndiag2 respectively, and the expansion ratio is selected as kep1=1.25~1.35, so that the minimum circumscribed rectangle T1 in the set Snph can be expanded to Ndiag1*kep1 and Ndiag2*kep1 along the diagonal direction respectively.
[0098] (5) At this time, the number of elements in the set Shp is greater than the threshold Nmph=20~50, and the segmentation continues.
[0099] (6) Figure 7 As shown, the percentile range from 5 to 10 is taken from the non-ground set Shp. For example, p g =8 percentile, based on Hh and the sum Hn of a head length constant Ln=90~150, the depth map is binarized, and pixels less than Hn are set to 1, and pixels greater than or equal to Hn are set to 0.
[0100] Clear the newly obtained potential head area set Snph.
[0101] The minimum bounding rectangle is extracted from the binary image and the minimum bounding rectangle with too small size is removed. The remaining two minimum bounding rectangles are recorded as T3 and T4 and added to the newly obtained potential head area set Snph.
[0102] (7) The potential head regions that have been obtained are recorded as a set Saph; the new potential head regions that are obtained are recorded as a set Snph.
[0103] At this time, the set Snph has three-element minimum enclosing rectangles T3 and T4, and the set Saph has two-element minimum enclosing rectangles T1 and T2.
[0104] The minimum bounding rectangles T3 and T4 of the two elements in Snph are matched with the minimum bounding rectangles T1 and T3 in the set Saph respectively. If the minimum bounding rectangle T1 of the element in the set Saph has more than Ncp=1~3 vertices in T3, then T3 has been detected and is directly discarded; if the minimum bounding rectangles T1 and T2 in the set Saph have no more than Ncp vertices in T4, and the midpoint distance between T1 and T4 is greater than the length of any side of T1 and T4, and the midpoint distance between T2 and T4 is greater than the length of any side of T2 and T4, then T4 is a new element and T4 is stored in the set Saph.
[0105] (8) Figure 8 As shown, the minimum circumscribed rectangles T3 and T4 of the elements of the set Snph are expanded according to a proportional value, the elements in the set Shp that are within the rectangles are deleted, and the elements above Hn in the set Shp are deleted to form a new set Shp.
[0106] For example, the lengths of the two diagonals of the minimum circumscribed rectangle T3 in the set Snph are Ndiag3 and Ndiag4 respectively, and the expansion ratio can be kep2=1.05-1.15, and the minimum circumscribed rectangle T2 in the set Snph is expanded to Ndiag3*kep2 and Ndiag4*kep2 respectively along the diagonal direction.
[0107] (9) At this time, the number of elements in the set Shp is less than the threshold Nmph, and the adaptive segmentation of the current frame is completed. The set Saph is the potential head region set Scph of the current frame. At this time, the set Scph contains three elements: T1, T2 and T4.
[0108] Embodiment 4
[0109] This embodiment is a specific description of the step of matching the current frame and the historical frame in the method of Embodiment 1. The specific process is as follows:
[0110] (1) Fig. 9 As shown, the potential head area of the historical frame is recorded as a set Shph. Assume that there are 3 elements T1, T2 and T3 in the set Shph at this time, where T1 matches 3 frames continuously to form a head area Sp, T2 has matched 2 frames continuously, and T3 has only one frame of data. The potential head area of the current frame is recorded as a set Scph. There are 3 elements in the set Scph, namely T4, T5 and T6.
[0111] For each element in the set Shph, if the number of historical continuous matching frames is greater than Nhm=2-3, the midpoint position of the current frame is predicted based on the midpoint change value of its historical position information, and its generalized distance is obtained based on the continuity of the head movement:
[0112] d=max(0,d ou +d1+d2+d3)
[0113] where d ou is the Euclidean distance between the midpoint position of the historical frame element or its predicted value and the midpoint position of the current frame element. d1, d2, and d3 are the reward and penalty values of the minimum circumscribed rectangle size, ratio, and number of historical frames of the elements in the set Shph for the Euclidean distance, as follows:
[0114] d1=ksize*[Nwidth-width]+ksize*[Nheight-height]
[0115] d2=kratio*[Nratio-ratio]
[0116] d3 = khf * [Nhf - history_frame]
[0117] Where width is the width of the minimum bounding rectangle, height is the height of the minimum bounding rectangle, ratio is the ratio of the segmented contour area to the minimum bounding rectangle, and history_frame is the number of historical frames.
[0118] Among them, kszie = 1 to 3, Nwidth = 60 to 80, Nheight = 60 to 80, kratio = 1 to 5, Nratio = 60 to 80, khf = 1 to 2, Nhf = 2 to 4, if d1, d2, d3 are all 0, then d is the Euclidean distance.
[0119] A generalized distance matrix Md is established. The value in the rth row and cth column is the generalized distance between the rth element of the set Shph and the cth element of the set Scph. The generalized distance matrix Md is as follows:
[0120]
[0121] (2) The number of potential head regions in the historical frame Nh=3; the number of potential head regions in the current frame Nc=3.
[0122] The row where the minimum element of the generalized distance matrix Md is located is R2, and the column is C2, which means that the C2th element of the set Scph matches the R2th element of the set Shph.
[0123] The elements in the R2th row and C2th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax=1000.
[0124]
[0125] The row where the minimum element of the generalized distance matrix Md is located is R1, and the column is C1, which means that the C1-th element of the set Scph matches the R1-th element of the set Shph.
[0126] The elements in the R1th row and C1th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax=1000.
[0127]
[0128] The row where the minimum element of the generalized distance matrix Md is located is R3, and the column is C3, which means that the C3th element of the set Scph matches the R3th element of the set Shph.
[0129] The elements in the R3th row and C3th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax=1000.
[0130]
[0131] All elements in the matrix Md are Nmax, which means that the matching is completed and the number of matching pairs Np=3.
[0132] Np=Nh=Nc, the three elements T1, T2 and T3 in the set Shph and the three elements T4, T5 and T6 in the set Scph are completely matched, and no elements are added or lost.
[0133] All elements of the set Scph are added to the historical frames of the matched elements in the set Shph to form the potential head region set Shph of the historical frames of the next frame.
[0134] The elements T1 and T2 of the set Shph are matched for three consecutive frames, and the two elements are upgraded to the head region.
[0135] All head regions constitute a head region set Sp, and at this time, the set Sp contains two elements T1 and T2 historical frame data.
[0136] (3) Fig. 9 As shown, according to S p The data stored in the memory is used to establish the motion trajectories tra1 and tra2 of the head area set Sp.
[0137] Embodiment 5
[0138] This embodiment is a specific description of the step of matching the current frame and the historical frame in the method of Embodiment 1. The specific process is as follows:
[0139] (1) Fig.10 As shown, the potential head area of the historical frame is recorded as a set Shph. Assume that there are 3 elements T1, T2 and T3 in the set Shph at this time, where T1 has been matched for 3 frames continuously to form a head area Sp, T2 has been matched for 2 frames continuously, and T3 has been matched for 2 frames continuously. The potential head area of the current frame is recorded as a set Scph. There are 3 elements in the set Scph, namely T4, T5 and T6.
[0140] For each element in the set Shph, if the number of historical continuous matching frames is greater than Nhm=2-3, the midpoint position of the current frame is predicted based on the midpoint change value of its historical position information, and its generalized distance is obtained based on the continuity of the head movement:
[0141] d=max(0,d ou +d1+d2+d3)
[0142] where d ou is the Euclidean distance between the midpoint position of the historical frame element or its predicted value and the midpoint position of the current frame element. d1, d2, and d3 are the reward and penalty values of the minimum circumscribed rectangle size, ratio, and number of historical frames of the elements in the set Shph for the Euclidean distance, as follows:
[0143] d1=ksize*[Nwidth-width]+ksize*[Nheight-height]
[0144] d2=kratio*[Nratio-ratio]
[0145] d3 = khf * [Nhf - history_frame]
[0146] Where width is the width of the minimum bounding rectangle, height is the height of the minimum bounding rectangle, ratio is the ratio of the segmented contour area to the minimum bounding rectangle, and history_frame is the number of historical frames.
[0147] Among them, kszie = 1 to 3, Nwidth = 60 to 80, Nheight = 60 to 80, kratio = 1 to 5, Nratio = 60 to 80, khf = 1 to 2, Nhf = 2 to 4, if d1, d2, d3 are all 0, then d is the Euclidean distance.
[0148] A generalized distance matrix Md is established. The value in the rth row and cth column is the generalized distance between the rth element of the set Shph and the cth element of the set Scph. The generalized distance matrix Md is as follows:
[0149]
[0150] (2) The number of potential head regions in the historical frame Nh=3; the number of potential head regions in the current frame Nc=3.
[0151] The row where the minimum element of the generalized distance matrix Md is located is R2, and the column is C2, which means that the C2th element of the set Scph matches the R2th element of the set Shph.
[0152] The elements of the R2th row and C2th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax = 1000, and we get:
[0153]
[0154] The row where the minimum element of the generalized distance matrix Md is located is R1, and the column is C1, which means that the C1-th element of the set Scph matches the R1-th element of the set Shph.
[0155] The elements of the R1th row and C1th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax = 1000, and we get:
[0156]
[0157] The row where the minimum element of the generalized distance matrix Md is located is R3, and the column is C3, which means that the C3th element of the set Scph matches the R3th element of the set Shph.
[0158] The elements of the R3th row and C3th column of the generalized distance matrix Md can be set to a sufficiently large constant Nmax = 1000, and we get:
[0159]
[0160] All elements in the matrix Md are Nmax, which means that the matching is completed and the number of matching pairs Np=3.
[0161] Np=Nh=Nc, the three elements T1, T2 and T3 in the set Shph and the three elements T4, T5 and T6 in the set Scph are completely matched, and no elements are added or lost.
[0162] All elements of the set Scph are added to the historical frames of the matched elements in the set Shph to form the potential head region set Shph of the historical frames of the next frame.
[0163] The elements T1, T2 and T3 of the set Shph are matched for three consecutive frames, and the three elements are upgraded to the head area.
[0164] All head regions constitute a head region set Sp, and at this time, the set Sp contains two elements T1 and T2 historical frame data.
[0165] (3) Fig.10 As shown, according to S p The data stored in the memory is used to establish the motion trajectories tra1, tra2 and tra3 of the head area set Sp.
[0166] Embodiment 6
[0167] This embodiment is a specific description of the entry and exit judgment step in the method of embodiment 1, which is as follows:
[0168] like Fig.11As shown, two standard lines for entry and exit can be established. The standard line on the left side of the camera's field of view can be set as the entry standard line L1, and the standard line on the right side can be set as the exit standard line L2. It can be set that if a person appears from the left side of L1 and moves to the right side of L2, it is considered that a person is going out, and if a person appears from the right side of L2 and moves to the left side of L1, it is considered that a person is going out. tra1 appears from the left side of L1 and moves to the right side of L2, and a person goes out. tra2 appears from the right side of L2 and moves to the left side of L1, and a person enters. tra3 appears from the right side of L2 and stops between L1 and L2, and does not reach the left side of L1, so it is not considered that a person enters. When judging a person's entry or exit, delete the data corresponding to this person in the head area set Sp and the potential head area set Shph of the historical frame.
[0169] Embodiment 7
[0170] This embodiment is a specific description of the entry and exit judgment step in the method of embodiment 1, which is as follows:
[0171] like Fig.12 As shown, two standard lines for entering and exiting can be established. The standard line on the left side of the camera's field of view can be set as the standard line for entering L1, and the standard line on the right side can be set as the standard line for exiting L2. It can be set that if a person appears from the left side of L1 and moves to the right side of L2, it is considered that a person is exiting, and if a person appears from the right side of L2 and moves to the left side of L1, it is considered that a person is exiting. If tra1 appears from the left side of L1 but does not reach the right side of L2, it is not considered that a person is exiting. If tra2 enters from the right side of L2 but does not reach the left side of L1, it is not considered that a person is entering. If tra3 appears from the right side of L2 and reaches the left side of L1, and continues from the left side of L1 to the right side of L2, it is considered that a person is entering and a person is exiting. When judging a person's entry or exit, delete the data corresponding to this person in the head area set Sp and the potential head area set Shph of the historical frame.
[0172] The above embodiment is based on Visual Studio 2019 software, uses the third-party library OpenCV, and adopts C++ language code to implement the entire system. It runs in the Windows 10 system with an AMD-R7-5800H CPU, and processes a regular depth image with a resolution of 640x480 obtained by a single-frame depth camera. The calculation time is within 4ms and the counting accuracy is above 99%.
[0173] Although the embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and are not to be construed as limitations of the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. A real-time counting method for people entering and exiting based on a depth camera, characterized in that: The following steps are involved: S1: Image Scanning For each frame of the depth map, scan the frame according to the set scanning step size Nstep to obtain the pixel point set Sp; S2: Point set partitioning Compare the depth values of the pixels in the set Sp with the current value Hg of the shortest head position in the previous frame. Pixels greater than Hg are stored in the ground set Sgp, and pixels less than Hg are stored in the non-ground set Shp. S3: Binarization Take the pth g Percentile, where p g Take 85 to 95, then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame; take the pth from the non-ground set Shp h Percentile Hh, where p h Take 5 to 10, binarize the depth map according to the sum Hn of Hh and a head length constant Ln, extract the minimum bounding rectangle of the binary image and remove the minimum bounding rectangle with one side of the length and width less than 20 to 40 mm, and record the remaining minimum bounding rectangle as the newly obtained potential head area set Snph; S4: Overlap judgment The position overlap between each element of the set Snph and the already obtained potential head area set Saph is judged, and if there is no overlap, the element is added to the set Saph; S5: Rectangular Extension Expand each minimum bounding rectangle in the set Snph, delete the points in the set Shp that are within the expanded rectangle, and delete the elements above Hn in the set Shp to form a new set Shp; S6: Adaptive Segmentation Repeat steps S3 to S5 until the number of elements in the set Shp is less than the set threshold Nmhp, that is, the adaptive segmentation of the current frame is completed; the set Saph is recorded as the potential head area set Scph of the current frame; S7: Generalized distance matrix construction Establish a generalized distance matrix Md between the potential head region set Scph of the current frame and the potential head region set Shph of the historical frame; S8: Set Matching The elements of the generalized distance matrix Md are matched in order from small to large to complete the matching of the set Scph and the set Shph; if an element in the set Shph is matched for multiple consecutive frames, the element is upgraded to a head region; if an element in the set Shph is not matched for multiple consecutive frames, the element is deleted; all head regions constitute the head region set Sp; S9: Motion trajectory establishment Establish the motion trajectory of each element in the set Sp according to the center position of the element; S10: Judgment and Statistics The entry and exit directions and statistical counts are determined through the motion trajectory of the elements in the set Sp.
2. According to claim 1, a method for real-time counting of people entering and exiting based on a depth camera is characterized in that: In step S1, the depth map is obtained by photographing the depth camera fixedly mounted on the elevator door frame perpendicular to the ground.
3. The method for real-time counting of people entering and exiting based on a depth camera according to claim 1, characterized in that: In step S3, the depth map is binarized, that is, pixels less than Hn are set to 1, and pixels greater than or equal to Hn are set to 0.
4. The method for real-time counting of people entering and exiting based on a depth camera according to claim 1, characterized in that: In step S4, the set Saph is set to an empty set before processing each frame.
5. The method for real-time counting of people entering and exiting based on a depth camera according to claim 1, characterized in that: In step S5, each element of the set Snph is expanded according to a set ratio value, and the expansion method is to expand the lengths of the two diagonals of the minimum circumscribed rectangle to the set lengths respectively.
6. The method for real-time counting of people entering and exiting based on a depth camera according to claim 1, characterized in that: In step S7, for each element in the set Shph, its position in the current frame is predicted based on its historical position information, and a generalized distance matrix Md is established based on the continuity of the head movement. The value in the rth row and cth column is the generalized distance between the midpoint of the rth element of the set Shph and the cth element of the set Scph. The generalized distance matrix Md is as follows:
7. The method for real-time counting of people entering and exiting based on a depth camera according to claim 6, characterized in that: In step S8, the minimum bounding rectangle T of each element in the set Snph is matched one by one with the minimum bounding rectangles of all elements in the set Saph. If any minimum bounding rectangle Ts of an element in Saph has more than z vertices in T, or the distance between the center points of the two rectangles is less than the length of any side of the two rectangles, it means that T has been detected and is directly discarded; otherwise, it is considered that a new element is detected and T is stored in the set Saph.
8. The method for real-time counting of people entering and exiting based on a depth camera according to claim 7, characterized in that: In step S8, the number of potential head regions in the historical frame is recorded as Nh; the number of potential head regions in the current frame is recorded as Nc; when the row where the minimum element of the generalized distance matrix Md is located is Rm and the column is Cn, it means that the Cnth element of the set Scph matches the Rmth element of the set Shph; then the elements of the Rmth row and Cnth column of the generalized distance matrix Md are set to a constant Nmax; repeat the above operation until all elements in the matrix Md are Nmax, indicating that the matching is completed, and the number of matching pairs is recorded as Np; if Np is equal to Nh, it means that all elements of the set Shph match the elements of the set Scph. , the set Scph generates Nc-Nh new elements; if Np is equal to Nc, it means that all elements of the set Scph are matched with the elements of the set Shph, and there are Nh-Nc elements of the set Shph that are not matched; if an element of the set Shph is not matched for Nnot consecutive frames, it means that the head area is out of the field of view, and the element is deleted from the set Shph; all elements of the set Scph and all remaining elements in the set Shph constitute the potential head area set Shph of the historical frame of the next frame; if an element of the set Shph is matched for Nfud consecutive frames, the potential head area is upgraded to the head area.
9. A method for real-time counting of people entering and exiting based on a depth camera according to claim 1 or 8, characterized in that: In step S10, if an element of the set Sp has been counted, the element is deleted.
10. A real-time counting system for people entering and exiting based on a depth camera, using the method according to any one of claims 1 to 9 to perform real-time counting of people entering and exiting, comprising: An image scanning module is used to scan each frame of the depth map according to a set scanning step length Nstep to obtain a pixel point set Sp; Point set partitioning module, used to compare the depth value of the pixel points in the set Sp with the current value Hg of the shortest head position in the previous frame, and store the pixel points greater than Hg in the ground set Sgp, and the pixel points less than Hg in the non-ground set Shp; Binarization module is used to take the pth g Percentile, where p g Take 85 to 95, then subtract the shortest head height constant Cmh to get the current value Hg of the shortest head position in the next frame; take the pth from the non-ground set Shp h Percentile Hh, where p h Take 5 to 10, binarize the depth map according to the sum Hn of Hh and a head length constant Ln, extract the minimum bounding rectangle of the binary image and remove the minimum bounding rectangle with one side of the length and width less than 20 to 40 mm, and record the remaining minimum bounding rectangle as the newly obtained potential head area set Snph; An overlap judgment module is used to judge the overlap between each element of the set Snph and the obtained potential head area set Saph. If there is no overlap, the element is added to the set Saph. The rectangle expansion module is used to expand each minimum circumscribed rectangle in the set Snph, delete the points in the set Shp that are within the expanded rectangle, and delete the elements above Hn in the set Shp to form a new set Shp; The adaptive segmentation module is used to repeat steps S3 to S5 until the number of elements in the set Shp is less than the set threshold Nmhp, that is, the adaptive segmentation of the current frame is completed; the set Saph is recorded as the potential head area set Scph of the current frame; A matrix building module is used to build a generalized distance matrix Md between a potential head region set Scph of a current frame and a potential head region set Shph of a historical frame; The set matching module is used to match the elements of the generalized distance matrix Md in ascending order to complete the matching of the set Scph and the set Shph; if an element in the set Shph is matched for multiple consecutive frames, the element is upgraded to a head region; if an element in the set Shph is not matched for multiple consecutive frames, the element is deleted; all head regions constitute the head region set Sp; A trajectory establishment module is used to establish the motion trajectory of each element in the set Sp according to the center position of the element; The judgment and statistics module is used to judge the entry and exit direction and count the movement trajectory of the elements of the set Sp; The central processing module is used to issue instructions to other modules to complete related actions; The image scanning module, point set division module, binarization module, overlap judgment module, rectangle expansion module, adaptive segmentation module, adaptive segmentation module, set matching module, trajectory establishment module, judgment and statistics module are all connected to the central processing module in communication.
