Moving object detection method and apparatus, terminal device, and storage medium
By downsampling the images in the terminal device and establishing background templates, the problems of inaccurate moving object detection and high computational load in the existing technology are solved, and more efficient and accurate moving object detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-23
- Publication Date
- 2026-03-24
AI Technical Summary
Existing moving object detection methods suffer from inaccurate detection and high computational load in terminal devices, and are particularly poor in terms of environmental adaptability.
By acquiring the first and second images after downsampling, detail images are extracted and a background template is established. The background template is then used to perform motion detection on the target pixels in the first and second images, reducing computational load and improving detection accuracy.
It effectively reduces the computational load of detection, improves the accuracy of moving object detection, reduces environmental impact, and achieves more standardized moving object detection.
Smart Images

Figure CN114998162B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of motion detection technology, and in particular to a method, apparatus, terminal device and storage medium for detecting moving objects. Background Technology
[0002] Currently, when terminal devices capture images or videos, ghosting may occur. This ghosting may be due to objects moving in the image or video that the lens cannot capture in time, resulting in multiple moving objects appearing in the image or video. To remove ghosting from images or videos, it is necessary to accurately detect moving objects. Currently, commonly used moving object detection methods usually involve the problem of threshold selection, which has poor adaptability to environmental factors. Furthermore, images or videos usually contain a large number of pixels, so there are situations where the detection is inaccurate or the computational load is too large. Summary of the Invention
[0003] This invention provides a method, apparatus, terminal device, and storage medium for detecting moving objects, in order to solve the problems of inaccurate detection or large computational load in commonly used moving object detection methods in the prior art.
[0004] In a first aspect, a method for detecting moving objects is provided, the method comprising: acquiring a first image and a second image, wherein a first time corresponding to the first image is earlier than a second time corresponding to the second image, and the first image is an image after downsampling processing;
[0005] Extract the detail images from the first image, and create a background template based on the detail images;
[0006] Based on the background template, motion detection is performed on the first target pixel in the first image and the second target pixel in the second image to obtain pixel motion detection results;
[0007] Based on the pixel motion detection results, the moving object between the first time point and the second time point is determined;
[0008] Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel.
[0009] As an optional implementation, in a first aspect of the present invention, the detail image includes: a background image and a texture image, and the extraction of the detail image from the first image includes:
[0010] The first image is filtered using a Gaussian filter to obtain the background image and the texture image.
[0011] As an optional implementation, in a first aspect of the present invention, the step of establishing a background template based on the detailed image includes:
[0012] In the texture image, texture pixels are determined, and in the background image, a plurality of background pixels corresponding to the texture pixels are determined;
[0013] The background template is established based on the texture pixels and the plurality of background pixels.
[0014] As an optional implementation, in a first aspect of the present invention, establishing the background template based on the texture pixels and the plurality of background pixels includes:
[0015] Multiple initial reference images are acquired, each initial reference image including a reference pixel corresponding to the texture pixel;
[0016] Based on the pixel values of the texture pixels and the pixel values of the multiple background pixels, the pixel values of the reference pixels in each initial reference image are determined to obtain multiple target reference images;
[0017] The background template is established based on the multiple target reference images.
[0018] As an optional implementation, in a first aspect of the present invention, the step of performing motion detection on a first target pixel in the first image and a second target pixel in the second image based on the background template to obtain a pixel motion detection result includes:
[0019] The pixel value of the second target pixel is compared with the pixel value of the reference pixel in the multiple target reference images to obtain multiple pixel differences;
[0020] If the first quantity is detected to be greater than the quantity threshold, then the second target pixel is determined to be a background pixel relative to the first target pixel, where the first quantity is the number of pixel differences less than the pixel threshold among the plurality of pixel differences;
[0021] If the second quantity is detected to be greater than the quantity threshold, then the second target pixel is determined to be a foreground pixel relative to the first target pixel, and the second quantity is the number of pixels whose difference is greater than or equal to the pixel threshold.
[0022] As an optional implementation, in a first aspect of the present invention, acquiring the first image and the second image includes:
[0023] Acquire the first frame image and the second frame image;
[0024] The first frame image and the second frame image are downsampled respectively to obtain the first image and the second image, where the first image corresponds to the first frame image and the second image corresponds to the second frame image.
[0025] As an optional implementation, in a first aspect of the present invention, after determining the moving object between the first time moment and the second time moment based on the pixel motion detection result, the method further includes:
[0026] The motion area of the moving object is determined based on the foreground pixels;
[0027] An initial motion image is obtained by filling the motion region with the background image;
[0028] The initial motion image is upsampled to obtain the target motion image, which includes the motion region and trajectory of the moving object.
[0029] In a second aspect, a moving object detection device is provided, the moving object detection device comprising: an acquisition module, configured to acquire a first image and a second image, wherein a first time corresponding to the first image is earlier than a second time corresponding to the second image, and the first image is an image after downsampling processing;
[0030] The detail extraction module is used to extract detail images from the first image and create a background template based on the detail images;
[0031] The processing module is used to perform motion detection on the first target pixel in the first image and the second target pixel in the second image according to the background template, and obtain pixel motion detection results;
[0032] The processing module is further configured to determine the moving object between the first time moment and the second time moment based on the pixel motion detection result;
[0033] Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel.
[0034] Thirdly, a terminal device is provided, the terminal device comprising:
[0035] Memory containing executable program code;
[0036] A processor coupled to the memory;
[0037] The processor calls the executable program code stored in the memory to execute the moving object detection method in the first aspect of the present invention.
[0038] Fourthly, a computer-readable storage medium is provided that stores a computer program that causes a computer to execute the moving object detection method of the first aspect of the present invention. The computer-readable storage medium includes ROM / RAM, a magnetic disk, or an optical disk, etc.
[0039] Fifthly, a computer program product is provided that, when the computer program product is run on a computer, causes the computer to perform some or all of the steps of any of the methods of the first aspect.
[0040] In a sixth aspect, an application publishing platform is provided for publishing computer program products, wherein when the computer program products are run on a computer, the computer performs some or all of the steps of any of the methods of the first aspect.
[0041] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:
[0042] In this embodiment of the invention, the terminal device can acquire a first image and a second image, where the first time point corresponding to the first image is earlier than the second time point corresponding to the second image. The first image is an image after downsampling. Detail images of the first image are extracted, and a background template is established based on these detail images. Motion detection is performed on a first target pixel in the first image and a second target pixel in the second image based on the background template to obtain pixel motion detection results. Based on the pixel motion detection results, a moving object between the first and second time points is determined. Here, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image corresponding to the first target pixel. Through this scheme, the terminal device can detect the downsampled image, eliminating the need to detect every pixel in the original image, thus significantly reducing the computational load. The terminal device performs detection based on the corresponding pixels in the second and first images, and establishes a background template after detail extraction of the first image. This background template serves as a benchmark when detecting the second image, making the detection of moving objects more standardized and reducing the influence of the environment, thereby effectively improving the accuracy of moving object detection. Attached Figure Description
[0043] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0044] Figure 1 This is a flowchart illustrating a moving object detection method provided in an embodiment of the present invention. Figure 1 ;
[0045] Figure 2 This is a schematic diagram of image processing for a moving object detection method provided in an embodiment of the present invention;
[0046] Figure 3 This is a flowchart illustrating a moving object detection method provided in an embodiment of the present invention. Figure 2 ;
[0047] Figure 4 This is a schematic diagram of the structure of a moving object detection device provided in an embodiment of the present invention;
[0048] Figure 5 This is a schematic diagram of the structure of a terminal device provided in an embodiment of the present invention. Detailed Implementation
[0049] 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, not all, of the embodiments of the present invention. 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.
[0050] The terms "first" and "second," etc., used in the specification and claims of this invention are used to distinguish different objects, rather than to describe a specific order of objects. For example, "first target pixel" and "second target pixel," etc., are used to distinguish different target pixels, rather than to describe a specific order of target pixels.
[0051] The terms “comprising” and “having” and any variations thereof in this invention are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such process, method, product or device.
[0052] It should be noted that in the embodiments of the present invention, the terms "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present the relevant concepts in a specific manner.
[0053] The moving object detection device involved in the embodiments of this application can be a terminal device, or a functional module and / or functional entity set in the terminal device that can implement the moving object detection method. The specific device can be determined according to actual usage requirements, and this application embodiment does not impose any limitations. It should be noted that the terminal device can be an electronic device such as a mobile phone, tablet computer, laptop computer, PDA, vehicle-mounted terminal device, wearable device, Ultra-Mobile Personal Computer (UMPC), netbook, or Personal Digital Assistant (PDA). Wearable devices can be smartwatches, smart bracelets, watch phones, etc., and this application embodiment does not impose any limitations.
[0054] Example 1
[0055] like Figure 1 As shown, this embodiment of the invention provides a method for detecting moving objects, which may include the following steps:
[0056] 101. Obtain the first image and the second image.
[0057] In this embodiment of the invention, the terminal device can acquire a first image at a first moment and a second image at a second moment.
[0058] In this embodiment, the first moment is earlier than the second moment, and the time interval between the first moment and the second moment can be a preset time interval or can be arbitrarily set. This embodiment of the invention does not impose any limitations.
[0059] It should be noted that the first image is a downsampled image. Downsampling is a common method for reducing image size. It can make the image fit the display area and generate a thumbnail of the corresponding image. By downsampling an image of size M*N by a factor of s, an image of size (M / s)*(N / s) can be obtained. Of course, s should be a common divisor of M and N. If it is a matrix image, it is to turn each s*s window of the original image into a pixel. The pixel value of this pixel is the average value of all pixel values in the s*s window.
[0060] Optionally, acquiring the first image and the second image may specifically include: acquiring the first frame image and the second frame image; performing downsampling processing on the first frame image and the second frame image respectively to obtain the first image and the second image.
[0061] In this implementation, both the first image and the second image can be downsampled images. That is, the terminal device can first acquire the first frame image and the second frame image, and then downsample both the first frame image and the second frame image to obtain the first image and the second image. Specifically, the first image is obtained by downsampling the first frame image, and the second image is obtained by downsampling the second frame image.
[0062] It should be noted that the first moment corresponding to the first frame is earlier than the second moment corresponding to the second frame.
[0063] During the downsampling process of the first frame image and the second frame image, the terminal device can obtain the coordinates of each pixel in the first frame image and the second frame image respectively, then remove the pixels with fixed coordinate values, and stitch the remaining pixels together to form the first image and the second image according to the original coordinate order.
[0064] For example, such as Figure 2 As shown, assuming the first frame image 21 is a 12*12 image, the terminal device can remove pixels 211 in the 3rd row, 212 in the 6th row, and 213 in the 9th row, as well as pixels 214 in the 3rd column, 215 in the 6th column, and 216 in the 9th column from the first frame image 21. Then, the remaining pixels are stitched together in the original order to obtain the first image 22. The second frame image is processed in the same way.
[0065] With this optional implementation, the terminal device can downsample both the first frame image and the second frame image to obtain the first image and the second image. In this way, the first image and the second image have lower resolution and fewer pixels compared to the first frame image and the second frame image. This greatly reduces the workload when the terminal device processes the first image and the second image in the future, as it does not need to traverse all pixels, thus improving the efficiency of moving object detection.
[0066] 102. Extract the detail image of the first image and create a background template based on the detail image.
[0067] In this embodiment of the invention, the terminal device can perform detail extraction processing on the first image, that is, extract the detail image in the first image.
[0068] It should be noted that an image can be decomposed into two layers: a base layer and a detail layer. The base layer contains low-frequency information of the image, reflecting the intensity changes of the image at a large scale; the detail layer contains high-frequency information of the image, reflecting the details of the image at a small scale.
[0069] In this embodiment of the invention, the terminal device needs to separate the background layer and texture layer in the first image to obtain a detail image. This detail image may include a background image and a texture image, where the background image is the background layer in the first image, and the texture image is the texture layer in the first image. The terminal device can create a background template based on the detail image, which can serve as a reference for moving object detection of pixels in the second image.
[0070] It should be noted that since the background template is used as a reference, in order to improve the accuracy of moving object detection, the number of background templates can be set to a large number. Generally, the number of background templates can be 20, 30, etc.
[0071] 103. Based on the background template, perform motion detection on the first target pixel in the first image and the second target pixel in the second image to obtain the pixel motion detection result.
[0072] In this embodiment of the invention, the terminal device needs to perform motion detection on each pixel in the second image. Moreover, during the motion detection process, each pixel in the second image is compared with the corresponding pixel in the first image, so that the terminal device can obtain the pixel motion detection result for each pixel.
[0073] Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel.
[0074] Optionally, the terminal device can use a Visual Background Extractor (Vibe) algorithm to perform motion detection on the first target pixel in the first image and the second target pixel in the second image.
[0075] The Vibe algorithm is a foreground detection algorithm based on background updates. Its principle is to extract the pixel values around the pixel point (x, y) (i.e., the first target pixel point) and the previous pixel values to build a sample set of pixel points (i.e., the background template). Then, the pixel value at the (x, y) point of another frame (i.e., the second target pixel point) is compared with the pixel value in the sample set. If the distance between it and the pixel value in the sample set is greater than a certain threshold, the pixel point is considered to be a foreground pixel point; otherwise, it is considered a background pixel point.
[0076] Optionally, the pixel motion detection results may include: background pixels and foreground pixels, wherein background pixels are pixels that do not change, that is, pixels that do not move between the first time moment and the second time moment; and foreground pixels are pixels that change, that is, pixels that move between the first time moment and the second time moment.
[0077] 104. Based on the pixel motion detection results, determine the moving object between the first and second time moments.
[0078] In this embodiment of the invention, the terminal device can obtain the pixel motion detection results of each pixel in the second image, and thus know which pixels in the second image are foreground pixels and which pixels are background pixels. Then, the object composed of the foreground pixels is identified as a moving object, which means that there is motion between the moving object at the first time and the second time.
[0079] This invention provides a method for detecting moving objects. A terminal device can acquire a first image and a second image, where the first image corresponds to a first time point earlier than the second image corresponds to a second time point. The first image is a downsampled image. The method involves extracting detail images from the first image and establishing a background template based on these detail images. Motion detection is then performed on a first target pixel in the first image and a second target pixel in the second image based on the background template, yielding pixel motion detection results. Based on these pixel motion detection results, a moving object between the first and second time points is determined. The first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image corresponding to the first target pixel. This method allows the terminal device to detect moving objects in downsampled images, eliminating the need to detect every pixel in the original image and significantly reducing computational load. The method also allows for detection based on corresponding pixels in the second and first images, and the establishment of a background template after detail extraction in the first image. This background template serves as a benchmark when detecting moving objects in the second image, making the detection more standardized and reducing environmental influences, thus effectively improving the accuracy of moving object detection.
[0080] Example 2
[0081] like Figure 3 As shown in the figure, an embodiment of the present invention provides a method for detecting moving objects, which may further include the following steps:
[0082] 301. Obtain the first image and the second image.
[0083] 302. Filter the first image using a Gaussian filter to obtain the background image and texture image.
[0084] Optionally, the terminal device can separate the background image and the texture image using various filtering methods, such as mean filter, Gaussian filter, guided filter, Gabor filter, etc.
[0085] Optionally, Gaussian filtering is a commonly used method. Specifically, the logic of Gaussian filtering is to remove the texture layer from the original image to obtain the background layer, and then subtract the background layer from the original image to obtain the texture layer. It can be expressed by the following formula: B = f(I), D = IB, where I is the original image, i.e., the first image; B is the background layer, i.e., the background image; D is the texture layer, i.e., the texture image; and f(x) is the Gaussian filtering process.
[0086] Furthermore, in Gaussian filtering, the first image can be processed using multiple superimposed filters, i.e., I(x, y). R1 =Gaussian1(I(x,y)) in ), σ1=1.0, R1=r; I(x, y) R2 =Gaussian2(I(x,y)) in ), σ2=2.0, R2=2r; I(x, y) R3 =Gaussian3(I(x,y)) in ), σ3=4.0, R3=4r; the terminal device can perform three filters on the first image using the above formula, and then fuse the filtered results, i.e., I(x,y). Detail1 =I(x,y)-I(x,y) R1 I(x, y) Detail2 =I(x, y) R1 -I(x, y) R2 ;I(x, y) Detail3 =I(x, y) R2 -I(x, y) R3 This yields three texture sub-images, which are then weighted together to calculate I(x, y). Detail =(1-w1*sgn(I(x,y)) Detail1 ))*I(x,y) Detail1 +w2*I(x, y) Detail2 +w3*I(x, y) Detail3 Where w1, w2, and w3 are I(x, y) respectively. Detail1 I(x, y) Detail2 and I(x, y) Detail3 The weights of I(x, y) Detail This refers to the texture image, I(x, y).in -I(x, y) Detail This is the background image.
[0087] 303. Determine the texture pixels in the texture image and the multiple background pixels corresponding to the texture pixels in the background image.
[0088] In this embodiment of the invention, after the terminal device determines the texture image and the background image, the pixels in the texture image are all called texture pixels. For a texture pixel, there are multiple background pixels in the background image that correspond to the texture pixel.
[0089] It should be noted that since both the texture image and the background image are separated from the first image, the coordinates of each pixel in the texture image and the background image are corresponding. Therefore, for any texture pixel, the multiple background pixels corresponding to it are the background pixels that are within a certain distance from the texture pixel, such as the eight adjacent background pixels around the texture pixel.
[0090] Optionally, the terminal device can set the image pixel grayscale range, and determine the pixels in the texture image whose pixel values are within the image pixel grayscale range as texture pixels. The image pixel grayscale range can be set by the terminal device itself, or it can be determined based on historical detection data.
[0091] 304. Create a background template based on the texture pixels and multiple background pixels.
[0092] Optionally, a background template can be established based on the texture pixel and multiple background pixels. Specifically, this may include: acquiring multiple initial reference images, each initial reference image including a reference pixel corresponding to the texture pixel; determining the pixel value of the reference pixel in each initial reference image based on the pixel value of the texture pixel and the pixel values of multiple background pixels to obtain multiple target reference images; and establishing a background template based on the multiple target reference images.
[0093] In this implementation, the terminal device can first acquire multiple initial reference images. Each initial reference image has the same size as the texture image and the background image, and each initial reference image also includes reference pixels corresponding to the pixels in the texture image and the background image. Since the background template serves as a reference, to improve the accuracy of moving object detection, the number of initial reference images in the background template can be set relatively large; typically, the number of initial reference images in the background template can be 10, 20, etc.
[0094] It should be noted that the terminal device determines the pixel value of the texture pixel and the pixel value of the corresponding multiple background pixels, and randomly assigns the pixel value of the reference pixel in each initial reference image based on these pixel values, thereby obtaining multiple target reference images with assigned pixel values to establish a background template.
[0095] For example, suppose that texture pixel A in a texture image corresponds to eight adjacent background pixels B around A in a background image. There are 10 initial reference images, each containing a reference pixel corresponding to A, denoted as Ai (i = 1 to 10). The terminal device can determine the pixel value of texture pixel A and the pixel values of the eight background pixels B, and then randomly assign values to Ai (i = 1 to 10) based on these nine pixel values. Assuming the pixel value of A is 100, and the pixel values of the eight background pixels B are 66, 54, 29, 31, 10, 5, 43, and 28 respectively, then Ai (i = 1 to 10) can be: A1 = 66, A2 = 10, A3 = 100, A4 = 28, A5 = 5, A6 = 54, A7 = 66, A8 = 31, A9 = 29, and A10 = 43. Of course, other pixel values can also be randomly assigned.
[0096] It should be noted that the terminal device can perform the above operation on each reference pixel in the initial reference image, so that each reference pixel in each initial reference image in the background template is determined based on the pixel values of the texture image and the background image.
[0097] 305. Compare the pixel value of the second target pixel with the pixel values of the reference pixels in multiple target reference images to obtain multiple pixel differences.
[0098] In this embodiment of the invention, multiple target reference images are determined based on the pixel values of the texture image and background image included in the first image. Therefore, the terminal device can compare each pixel in the second image with each reference pixel in the multiple target reference images to obtain multiple pixel differences.
[0099] For example, suppose the terminal device obtains the pixel values of the reference pixels in 10 target reference images as A1=66, A2=10, A3=100, A4=28, A5=5, A6=54, A7=66, A8=31, A9=29, A10=43; and the pixel value of the corresponding second target pixel D in the second image is 85. Then, the difference between D and Ai (i=1~10) can be calculated to obtain 10 pixel difference values, which are 19, 75, -15, 57, 80, 31, 19, 54, 56, and 42.
[0100] 306. If the first number is detected to be greater than the number threshold, then the second target pixel is determined to be a background pixel relative to the first target pixel.
[0101] In this embodiment of the invention, the terminal device can set a quantity threshold and a pixel threshold, compare multiple pixel differences with the pixel threshold respectively, determine a first quantity that is less than the pixel threshold, and compare the first quantity with the quantity threshold. If the first quantity is greater than the quantity threshold, it can be said that the second target pixel does not change much compared with the first target pixel, so the second target pixel can be determined as a background pixel.
[0102] 307. If the second quantity is detected to be greater than the quantity threshold, then the second target pixel is determined to be a foreground pixel relative to the first target pixel.
[0103] In this embodiment of the invention, the terminal device can set a quantity threshold and a pixel threshold, compare multiple pixel differences with the pixel threshold respectively, determine a second quantity that is greater than or equal to the pixel threshold, and compare the second quantity with the quantity threshold. If the second quantity is greater than the quantity threshold, it can be said that the second target pixel has a large change compared with the first target pixel, so the second target pixel can be determined as a foreground pixel.
[0104] 308. Based on the pixel motion detection results, determine the moving object between the first and second time moments.
[0105] Optionally, when performing motion detection on the first target pixel in the first image and the second target pixel in the second image, an initial result template can be set. The size of the initial result template is the same as that of the first image and the second image, and the result pixels in the initial result template correspond to the first target pixel in the first image and the second target pixel in the second image, respectively. The pixel value of the result pixels in the initial result template is 0.
[0106] It should be noted that when the second target pixel is determined to be a foreground pixel, the pixel value of the corresponding pixel in the initial result template can be set to 255, that is, the originally black pixel is adjusted to white. When the second target pixel is determined to be a background pixel, the pixel value of the corresponding pixel in the initial result template remains unchanged, that is, it remains the originally black pixel. The terminal device can use this to traverse all the result pixels in the initial result template to obtain the target result template. If the target result template is entirely white, it means that all pixels have changed between the first and second time points; if the target result template is entirely black, it means that all pixels have not changed between the first and second time points; if the target result template contains both black and white pixels, it means that some pixels have changed between the first and second time points. In this case, the terminal device can determine the moving object based on the white pixels in the target result template.
[0107] 309. Determine the motion area of the moving object based on the foreground pixels.
[0108] In this embodiment of the invention, after the terminal device determines the foreground pixels and background pixels, it can combine all the foreground pixels to obtain the motion area of the moving object.
[0109] 310. Fill the motion area with the background image to obtain the initial motion image.
[0110] In this embodiment of the invention, the terminal device can fill the motion region with the background image separated from the first image, that is, the motion region only includes foreground pixels, and then merge it into the background image to obtain a complete image, that is, the initial motion image.
[0111] 311. Upsample the initial motion image to obtain the target motion image.
[0112] In this embodiment of the invention, since the terminal device has performed downsampling processing when acquiring the first image and the second image, the terminal device can perform upsampling processing on the initial motion image to restore the initial motion image to the size of the original image, that is, the target motion image can be obtained. The target motion image can include the motion area and motion trajectory of the moving object.
[0113] It should be noted that upsampling refers to expanding and enlarging an image or feature map to generate the required size. It is often used in feature fusion and usually uses interpolation algorithms for upsampling. The pixel value of the target pixel in the upsampled target motion image can be determined by the pixel value of the target pixel in the initial motion image and the pixel values of multiple surrounding pixels.
[0114] This invention provides a method for detecting moving objects. A terminal device can perform Gaussian filtering on a downsampled first image to separate the texture image and the background image. Then, a background template is established based on the pixel values of texture pixels in the texture image and background pixels in the background image. In motion detection, each pixel in the second image is compared with reference pixels in multiple target reference images in the background template to determine foreground and background pixels. Finally, moving objects and motion regions are determined based on the foreground pixels, and upsampling is performed to obtain the target motion image. This method allows the terminal device to detect downsampled images without needing to detect every pixel in the original image, significantly reducing the computational load. The terminal device performs detection based on corresponding pixels in the second and first images, and establishes a background template after extracting texture and background from the first image. This background template serves as a benchmark when detecting the second image, making motion object detection more standardized and reducing environmental influences, thus effectively improving the accuracy of motion object detection.
[0115] Example 3
[0116] like Figure 4 As shown, an embodiment of the present invention provides a moving object detection device, which includes:
[0117] The acquisition module 401 is used to acquire a first image and a second image, wherein the first time corresponding to the first image is earlier than the second time corresponding to the second image, and the first image is an image after downsampling processing;
[0118] The detail extraction module 402 is used to extract detail images from the first image and create a background template based on the detail images;
[0119] Processing module 403 is used to perform motion detection on the first target pixel in the first image and the second target pixel in the second image based on the background template, and obtain pixel motion detection results;
[0120] The processing module 403 is also used to determine the moving object between the first time moment and the second time moment based on the pixel motion detection results;
[0121] Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel.
[0122] Optionally, the detail extraction module 402 is specifically used to filter the first image using a Gaussian filter to obtain a background image and a texture image.
[0123] Optionally, the processing module 403 is specifically used to determine texture pixels in the texture image and to determine multiple background pixels corresponding to the texture pixels in the background image;
[0124] The processing module 403 is specifically used to create a background template based on texture pixels and multiple background pixels.
[0125] Optionally, the acquisition module 401 is specifically used to acquire multiple initial reference images, each initial reference image including a reference pixel corresponding to a texture pixel.
[0126] The processing module 403 is specifically used to determine the pixel value of the reference pixel in each initial reference image based on the pixel value of the texture pixel and the pixel values of multiple background pixels, so as to obtain multiple target reference images;
[0127] The processing module 403 is specifically used to create a background template based on multiple target reference images.
[0128] Optionally, the processing module 403 is specifically used to compare the pixel value of the second target pixel with the pixel value of the reference pixel in multiple target reference images to obtain multiple pixel differences;
[0129] The processing module 403 is specifically used to determine that the second target pixel is a background pixel relative to the first target pixel if the first number is detected to be greater than the number threshold. The first number is the number of pixel differences that are less than the pixel threshold.
[0130] The processing module 403 is specifically used to determine that if the second quantity is detected to be greater than the quantity threshold, the second target pixel is a foreground pixel relative to the first target pixel, and the second quantity is the number of pixels whose difference is greater than or equal to the pixel threshold.
[0131] Optionally, the acquisition module 401 is specifically used to acquire the first frame image and the second frame image;
[0132] The processing module 403 is specifically used to perform downsampling processing on the first frame image and the second frame image respectively to obtain the first image and the second image, where the first image corresponds to the first frame image and the second image corresponds to the second frame image.
[0133] Optionally, the processing module 403 is specifically used to determine the motion area of the moving object based on the foreground pixels;
[0134] Processing module 403 is specifically used to fill the motion region with the background image to obtain an initial motion image;
[0135] The processing module 403 is specifically used to perform upsampling processing on the initial motion image to obtain the target motion image, which includes the motion area and motion trajectory of the moving object.
[0136] In this embodiment of the invention, each module can implement the moving object detection method provided in the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.
[0137] like Figure 5 As shown, embodiments of the present invention also provide a terminal device, which may include:
[0138] Memory 501 storing executable program code;
[0139] Processor 502 coupled to memory 501;
[0140] In this process, the processor 502 calls the executable program code stored in the memory 501 to execute the moving object detection method executed by the terminal device in the above method embodiments.
[0141] This invention provides a computer-readable storage medium storing a computer program that causes a computer to perform some or all of the steps of the methods described in the above embodiments.
[0142] This invention also provides a computer program product, wherein when the computer program product is run on a computer, the computer performs some or all of the steps of the methods described in the above method embodiments.
[0143] This invention also provides an application publishing platform, which is used to publish computer program products. When the computer program products are run on a computer, the computer performs some or all of the steps of the methods described in the above method embodiments.
[0144] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of the invention. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Those skilled in the art should also recognize that the embodiments described in the specification are optional embodiments, and the actions and modules involved are not necessarily essential to the invention.
[0145] In various embodiments of the present invention, it should be understood that the sequence number of each process does not necessarily imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0146] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; they can be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0147] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0148] If the integrated units described above are implemented as software functional units and sold or used as independent products, they can be stored in a computer-accessible memory. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several requests to cause a computer device (which can be a personal computer, server, or network device, specifically a processor in the computer device) to execute some or all of the steps of the methods described in the various embodiments of the present invention.
[0149] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, including read-only memory (ROM), random access memory (RAM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), one-time programmable read-only memory (OTPROM), electrically-Erasable Programmable Read-Only Memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, disk storage, magnetic tape storage, or any other computer-readable medium capable of carrying or storing data.
Claims
1. A method for detecting moving objects, characterized in that, The method includes: Acquire a first image and a second image, wherein the first time corresponding to the first image is earlier than the second time corresponding to the second image, and both the first image and the second image are images after downsampling processing; Extract the detail images from the first image, and create a background template based on the detail images; Based on the background template, motion detection is performed on the first target pixel in the first image and the second target pixel in the second image to obtain pixel motion detection results; Based on the pixel motion detection results, the moving object between the first time point and the second time point is determined; Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel; The detailed image includes: a background image and a texture image, and the extraction of the detailed image from the first image includes: The first image is filtered using a Gaussian filter to obtain the background image and the texture image; The step of creating a background template based on the detailed image includes: In the texture image, texture pixels are determined, and in the background image, a plurality of background pixels corresponding to the texture pixels are determined; The background template is established based on the texture pixels and the plurality of background pixels; The step of establishing the background template based on the texture pixels and the plurality of background pixels includes: Multiple initial reference images are acquired, each initial reference image including a reference pixel corresponding to the texture pixel; Based on the pixel values of the texture pixels and the pixel values of the multiple background pixels, the pixel values of the reference pixels in each initial reference image are determined to obtain multiple target reference images; The background template is established based on the multiple target reference images.
2. The method according to claim 1, characterized in that, The step of performing motion detection on the first target pixel in the first image and the second target pixel in the second image based on the background template to obtain pixel motion detection results includes: The pixel value of the second target pixel is compared with the pixel value of the reference pixel in the multiple target reference images to obtain multiple pixel differences; If the first quantity is detected to be greater than the quantity threshold, then the second target pixel is determined to be a background pixel relative to the first target pixel, and the first quantity is the number of pixel differences less than the pixel threshold among the plurality of pixel differences; If the second quantity is detected to be greater than the quantity threshold, then the second target pixel is determined to be a foreground pixel relative to the first target pixel, and the second quantity is the number of pixels whose difference is greater than or equal to the pixel threshold.
3. The method according to any one of claims 1 to 2, characterized in that, The acquisition of the first image and the second image includes: Acquire the first frame image and the second frame image; The first frame image and the second frame image are downsampled respectively to obtain the first image and the second image, where the first image corresponds to the first frame image and the second image corresponds to the second frame image.
4. The method according to any one of claims 1 to 2, characterized in that, After determining the moving object between the first time moment and the second time moment based on the pixel motion detection results, the method further includes: The motion area of the moving object is determined based on the foreground pixels; An initial motion image is obtained by filling the motion region with the background image; The initial motion image is upsampled to obtain the target motion image, which includes the motion region and trajectory of the moving object.
5. A moving object detection device, characterized in that, The detailed image includes: a background image and a texture image; the moving object detection device includes: The acquisition module is used to acquire a first image and a second image, wherein the first time corresponding to the first image is earlier than the second time corresponding to the second image, and both the first image and the second image are images after downsampling processing; The detail extraction module is used to extract detail images from the first image and create a background template based on the detail images; The processing module is used to perform motion detection on the first target pixel in the first image and the second target pixel in the second image according to the background template, and obtain pixel motion detection results; The processing module is further configured to determine the moving object between the first time moment and the second time moment based on the pixel motion detection result; Wherein, the first target pixel is any pixel in the first image, and the second target pixel is the pixel in the second image that corresponds to the first target pixel; The detail extraction module is further configured to filter the first image using a Gaussian filter to obtain the background image and the texture image; The processing module is further configured to determine texture pixels in the texture image and to determine a plurality of background pixels corresponding to the texture pixels in the background image; The background template is established based on the texture pixels and the plurality of background pixels; The acquisition module is also used to acquire multiple initial reference images, each initial reference image including a reference pixel corresponding to the texture pixel; The processing module is further configured to determine the pixel value of the reference pixel in each initial reference image based on the pixel value of the texture pixel and the pixel value of the plurality of background pixels, so as to obtain a plurality of target reference images; The processing module is also used to establish the background template based on the multiple target reference images.
6. A terminal device, characterized in that, include: Memory containing executable program code; and the processor coupled to the memory; The processor calls the executable program code stored in the memory to execute the moving object detection method as described in any one of claims 1 to 4.
7. A computer-readable storage medium, characterized in that, include: The computer-readable storage medium stores computer instructions that, when executed by a processor, implement the moving object detection method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
A moving object detection method and device based on a Gaussian mixture background model
CN109949337A
Target area detection method and device, storage medium and electronic equipment
CN114332702A