A method and device for detecting camera movement being blocked
By performing grayscale processing and binarization of video images collected by the camera, combined with threshold comparison and adaptive brightness adjustment, the problem of camera occlusion or movement judgment is solved, ensuring the normal progress of monitoring quality and image recognition processing.
Patent Information
- Application Number
- CN202111187567.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-12
- Publication Date
- 2025-01-10
- Estimated Expiration
- 2041-10-12
AI Technical Summary
During machine vision monitoring, the camera may be blocked or moved unnaturally, resulting in reduced monitoring quality and difficulty in image recognition processing.
By extracting the two frames of the front and back images collected by the camera, the grayscale processing, the frame difference method difference processing and the binary processing are performed. According to the comparison between the number of pixels with a grayscale value of 255 and the preset threshold, it is determined whether the camera is blocked or moved. , and adjust the threshold according to the image brightness.
Accurately determine whether the camera is blocked or moved, and ensure the normal progress of monitoring quality and image recognition processing.
Smart Images

Figure CN113822223B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition and security supervision, and in particular to a method and device for detecting blocked movement of a camera. Background Art
[0002] With the rapid development of machine vision technology, using machine vision to replace human eyes has become a trend in the development of intelligence in all walks of life. Machine vision mainly relies on the real-time images transmitted by the camera during the monitoring process to perform further image recognition processing. However, in the process of realizing real-time camera monitoring, the camera may be blocked or move unnaturally, which affects the monitoring quality of the camera and creates difficulties for the subsequent image recognition processing process. Summary of the invention
[0003] In order to overcome the problems existing in the related art, the present invention provides a method and device for detecting the movement of a camera being blocked.
[0004] According to a first aspect of an embodiment of the present invention, there is provided a method for detecting movement of a camera being blocked, comprising:
[0005] Extract the front and back two frames of the video captured by the camera respectively, and perform grayscale processing on the images to obtain grayscale images;
[0006] A frame difference method is used to obtain a difference image of the grayscale images of the two frames of images;
[0007] Binarizing the difference image to obtain a binary image;
[0008] Whether the camera is blocked or moved is determined based on a comparison result between the number of pixels with a grayscale value of 255 in the binary image and the determination threshold.
[0009] Further, the judgment threshold includes an image movement value and an occlusion value;
[0010] The step of comparing the number of pixels with a gray value of 255 in the binary image with a judgment threshold to determine whether the camera is blocked or moved specifically includes:
[0011] If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved;
[0012] If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
[0013] Furthermore, before determining whether the camera is blocked or moved according to the comparison result of the number of pixels with a gray value of 255 in the binary image and a preset threshold, the method further includes:
[0014] The number of pixels whose grayscale values are greater than a preset value in the grayscale image of the previous frame is counted, and the counted number is compared with the pixel value of the image, and the judgment threshold is determined according to the comparison result.
[0015] Further, determining the judgment threshold according to the comparison result specifically includes:
[0016] Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels with grayscale values greater than the preset value in the grayscale image of the previous frame image to the image pixel value is k, then
[0017] Current motion judgment threshold m=a+k*(ba), current occlusion judgment threshold n=c+k*(dc);
[0018] The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
[0019] According to a second aspect of an embodiment of the present invention, there is provided an apparatus for detecting movement of a camera being blocked, comprising:
[0020] A grayscale processing module is used to extract the front and back two frames of the video captured by the camera, and perform grayscale processing on the images to obtain grayscale images;
[0021] A difference processing module, used for obtaining a difference image of the grayscale images of the two preceding and following frames of images by using a frame difference method;
[0022] A binarization module, used for performing binarization processing on the difference image to obtain a binary image;
[0023] The comparison and judgment module is used to judge whether the camera is blocked or moved according to the comparison result of the number of pixels with a gray value of 255 in the binary image and the judgment threshold.
[0024] Further, the judgment threshold includes an image movement value and an occlusion value;
[0025] The comparison and judgment module is specifically used for:
[0026] If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved;
[0027] If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
[0028] Furthermore, the device also includes:
[0029] A judgment threshold determination module is used to count the number of pixels with grayscale values greater than a preset value in the grayscale image of the previous frame of the image before the comparison judgment module determines whether the camera is blocked or moved based on the comparison result of the number of pixels with grayscale values of 255 in the binary image with a preset threshold, and compare the counted number with the pixel value of the image to determine the judgment threshold based on the comparison result.
[0030] Furthermore, the judgment threshold determination module is specifically used to:
[0031] Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels with grayscale values greater than the preset value in the grayscale image of the previous frame image to the image pixel value is k, then
[0032] Current motion judgment threshold m=a+k*(ba), current occlusion judgment threshold n=c+k*(dc);
[0033] The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
[0034] According to a third aspect of an embodiment of the present invention, a terminal device is provided, including:
[0035] Processor; and
[0036] The memory stores executable codes thereon, and when the executable codes are executed by the processor, the processor is caused to execute the method as described above.
[0037] According to a fourth aspect of an embodiment of the present invention, there is provided a non-transitory machine-readable storage medium having executable code stored thereon, which, when executed by a processor of an electronic device, causes the processor to execute the method as described above.
[0038] The technical solution provided by the embodiments of the present invention may have the following beneficial effects:
[0039] The present invention can accurately determine whether the camera is blocked or moved by processing the video images collected by the camera, thereby facilitating the back-end operation and maintenance personnel to take measures in a timely manner, ensuring the monitoring quality of the camera and facilitating the subsequent image recognition processing process.
[0040] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] The above and other objects, features and advantages of the present invention will become more apparent through a more detailed description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, wherein like reference numerals generally represent like components throughout the exemplary embodiments of the present invention.
[0042] Figure 1 is a flow chart of a method for detecting blocked movement of a camera according to an exemplary embodiment of the present invention;
[0043] Figure 2 is a structural block diagram of a device for detecting movement of a camera being blocked according to an exemplary embodiment of the present invention;
[0044] Figure 3 It is a schematic diagram showing the structure of a computing device according to an exemplary embodiment of the present invention. DETAILED DESCRIPTION
[0045] The preferred embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the preferred embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to make the present invention more thorough and complete, and to fully convey the scope of the present invention to those skilled in the art.
[0046] The terms used in the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The singular forms "a", "the" and "the" used in the present invention and the appended claims are also intended to include plural forms unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0047] It should be understood that although the terms "first", "second", "third", etc. may be used to describe various information in the present invention, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present invention, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "multiple" is two or more, unless otherwise clearly and specifically defined.
[0048] The technical solutions of the embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0049] Figure 1 The figure is a flow chart showing a method for detecting blocked movement of a camera according to an exemplary embodiment of the present invention.
[0050] See also Figure 1 , the method comprising:
[0051] 110. Extract the front and rear two frames of the video captured by the camera respectively, and perform grayscale processing on the images to obtain grayscale images;
[0052] 120. Obtain a difference image of the grayscale images of the two preceding and following frames of images by using a frame difference method;
[0053] 130. Binarize the difference image to obtain a binary image;
[0054] 140. Determine whether the camera is blocked or moved according to a comparison result between the number of pixels with a grayscale value of 255 in the binary image and a determination threshold.
[0055] Specifically, in this embodiment, the Opencv absdiff frame difference method can be used to obtain the difference image of the grayscale images of the previous and next two frames of images. Further, the Opencv threshold threshold can be used to filter out the noise in the difference matrix of the difference image to obtain a neat difference matrix. The filtering method here can specifically use the THRESH_BINARY method.
[0056] The specific process of binarizing the difference image to obtain the binary image is as follows: a judgment threshold is given in advance, and each pixel in the difference image is judged. If the grayscale value of the pixel is greater than the threshold, the grayscale value of the pixel is changed to 255, otherwise it is changed to 0. After all the pixels in the difference image are judged, the pixels with grayscale values equal to 255 are counted, thereby obtaining the number of pixels with a large difference in grayscale values between the previous and next frames of the image, which can be recorded as differ_count.
[0057] Generally, when the camera is blocked, the grayscale values of the pixels in the two frames of images before and after differ greatly, so the value of differ_count is larger. When the camera is moved, the value of differ_count is smaller than that when it is blocked. Therefore, differ_count can be compared with the judgment threshold to determine whether the camera is blocked or moved based on the comparison result.
[0058] A method for detecting whether a camera is blocked or moved is provided in an embodiment of the present invention. By processing the video images captured by the camera, it is possible to accurately determine whether the camera is blocked or moved, thereby facilitating backend operation and maintenance personnel to take timely measures to ensure the monitoring quality of the camera and facilitate subsequent image recognition processing.
[0059] Optionally, in this embodiment, the judgment threshold includes an image movement value and an occlusion value;
[0060] Step 140 specifically includes:
[0061] If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved;
[0062] If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
[0063] In this embodiment, when it is determined that the camera is moved or blocked, a video of a preset length can be captured and saved as evidence. When it is determined that the camera is not moved or blocked, a video of a preset length can be captured and saved as evidence.
[0064] Optionally, as an embodiment of the present invention, the method includes:
[0065] 210. Extract the front and rear two frames of the video captured by the camera respectively, and perform grayscale processing on the images to obtain grayscale images;
[0066] 220. Obtain a difference image of the grayscale images of the two preceding and following frames of images by using a frame difference method;
[0067] 230. Binarize the difference image to obtain a binary image;
[0068] 240. Count the number of pixels whose grayscale values are greater than a preset value in the grayscale image of the previous frame of image, compare the counted number with the pixel value of the image, and determine a judgment threshold according to the comparison result;
[0069] 250. Determine whether the camera is blocked or moved according to a comparison result between the number of pixels with a grayscale value of 255 in the binary image and a determination threshold.
[0070] Specifically, the inventors found in their research that in some specific scenes or time periods (such as dark places indoors or underground or at night), due to different lighting conditions, if a fixed judgment threshold is used, the camera may be blocked and the movement may be judged incorrectly or the camera may not be judged to be abnormal. To address this phenomenon, in this embodiment, the judgment threshold can be adaptively changed according to the brightness of the image acquired by the camera to restore the normal judgment function. The specific implementation steps are as follows: after each grayscale image captured by the video is acquired: first, the number of pixel points in the image whose grayscale value is greater than a preset value is counted, and the counted number is compared with the pixel value of the image. Here, the pixel value of the image can be obtained through the get function, and the ratio of the statistical number to the image pixel value corresponds to different judgment thresholds, and the two are positively correlated, that is, the smaller the ratio, the smaller the corresponding judgment threshold, and vice versa, so that the judgment threshold can be adaptively changed with the image brightness.
[0071] Optionally, in this embodiment, the process of determining the judgment threshold according to the comparison result in step 240 specifically includes:
[0072] Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels with grayscale values greater than the preset value in the grayscale image of the previous frame image to the image pixel value is k, then
[0073] Current motion judgment threshold m=a+k*(ba), current occlusion judgment threshold n=c+k*(dc);
[0074] The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
[0075] Specifically, for example, assuming that the occlusion judgment threshold range is 0.2-0.8, the motion judgment threshold range is 0.1-0.4, and the ratio of the statistical number to the pixel value is 30%, then the current occlusion judgment threshold is 0.2+0.6*30%=0.38, and the current motion judgment threshold is 0.1+0.3*30%=0.19. The updated threshold is used again to judge whether the camera is occluded by motion.
[0076] Corresponding to the above method embodiment, this embodiment provides a device for detecting the movement of a camera being blocked. Figure 2 is a structural block diagram of the device according to an exemplary embodiment of the present invention.
[0077] See also Figure 2 , the device comprises:
[0078] A grayscale processing module is used to extract the front and back two frames of the video captured by the camera, and perform grayscale processing on the images to obtain grayscale images;
[0079] A difference processing module, used for obtaining a difference image of the grayscale images of the two preceding and following frames of images by using a frame difference method;
[0080] A binarization module, used for performing binarization processing on the difference image to obtain a binary image;
[0081] The comparison and judgment module is used to judge whether the camera is blocked or moved according to the comparison result of the number of pixels with a gray value of 255 in the binary image and the judgment threshold.
[0082] Optionally, in this embodiment, the judgment threshold includes an image movement value and an occlusion value;
[0083] The comparison and judgment module is specifically used for:
[0084] If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved;
[0085] If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
[0086] Optionally, in this embodiment, the device further includes:
[0087] A judgment threshold determination module is used to count the number of pixels with grayscale values greater than a preset value in the grayscale image of the previous frame of the image before the comparison judgment module determines whether the camera is blocked or moved based on the comparison result of the number of pixels with grayscale values of 255 in the binary image with a preset threshold, and compare the counted number with the pixel value of the image to determine the judgment threshold based on the comparison result.
[0088] Optionally, in this embodiment, the judgment threshold determination module is specifically used to:
[0089] Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels with grayscale values greater than the preset value in the grayscale image of the previous frame image to the image pixel value is k, then
[0090] Current motion judgment threshold m=a+k*(ba), current occlusion judgment threshold n=c+k*(dc);
[0091] The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
[0092] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated again here.
[0093] Figure 3 It is a schematic diagram showing the structure of a computing device according to an exemplary embodiment of the present invention.
[0094] See also Figure 3 , the computing device 300 includes a memory 310 and a processor 320 .
[0095] The processor 320 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or the processor may be any conventional processor, etc.
[0096] The memory 310 may include various types of storage units, such as system memory, read-only memory (ROM), and permanent storage devices. Among them, ROM can store static data or instructions required by the processor 320 or other modules of the computer. The permanent storage device may be a readable and writable storage device. The permanent storage device may be a non-volatile storage device that does not lose the stored instructions and data even after the computer is powered off. In some embodiments, the permanent storage device uses a large-capacity storage device (such as a magnetic or optical disk, flash memory) as a permanent storage device. In some other embodiments, the permanent storage device may be a removable storage device (such as a floppy disk, optical drive). The system memory may be a readable and writable storage device or a volatile readable and writable storage device, such as a dynamic random access memory. The system memory may store some or all instructions and data required by the processor at run time. In addition, the memory 310 may include any combination of computer-readable storage media, including various types of semiconductor memory chips (DRAM, SRAM, SDRAM, flash memory, programmable read-only memory), and disks and / or optical disks may also be used. In some embodiments, the memory 310 may include a readable and / or writable removable storage device, such as a laser disc (CD), a read-only digital versatile disc (such as a DVD-ROM, a double-layer DVD-ROM), a read-only Blu-ray disc, an ultra-density optical disc, a flash memory card (such as an SD card, a mini SD card, a Micro-SD card, etc.), a magnetic floppy disk, etc. The computer-readable storage medium does not include carrier waves and transient electronic signals transmitted wirelessly or wired.
[0097] The memory 310 stores executable codes, and when the executable codes are processed by the processor 320 , the processor 320 can execute part or all of the methods described above.
[0098] The scheme of the present invention has been described in detail above with reference to the accompanying drawings. In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments. Those skilled in the art should also be aware that the actions and modules involved in the specification are not necessarily required by the present invention. In addition, it can be understood that the steps in the method of the embodiment of the present invention can be adjusted in order, merged and deleted according to actual needs, and the modules in the device of the embodiment of the present invention can be merged, divided and deleted according to actual needs.
[0099] In addition, the method according to the present invention may also be implemented as a computer program or a computer program product, which includes computer program code instructions for executing part or all of the steps in the above method of the present invention.
[0100] Alternatively, the present invention may also be implemented as a non-temporary machine-readable storage medium (or computer-readable storage medium, or machine-readable storage medium) on which executable code (or computer program, or computer instruction code) is stored. When the executable code (or computer program, or computer instruction code) is executed by a processor of an electronic device (or computing device, server, etc.), the processor executes part or all of the steps of the above-mentioned method according to the present invention.
[0101] Those skilled in the art will further appreciate that the various illustrative logical blocks, modules, circuits, and algorithm steps described in connection with the disclosure herein may be implemented as electronic hardware, computer software, or a combination of both.
[0102] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system and method according to multiple embodiments of the present invention. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or code, and the part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0103] The embodiments of the present invention have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The terms used herein are selected to best explain the principles of the embodiments, practical applications, or improvements to the technology in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.
Claims
1. A method for detecting camera movement when it is blocked, characterized in that: include: Extract the front and back two frames of the video captured by the camera respectively, and perform grayscale processing on the images to obtain grayscale images; A frame difference method is used to obtain a difference image of the grayscale images of the two frames of images; Binarizing the difference image to obtain a binary image; Counting the number of pixels whose grayscale values are greater than a preset value in the grayscale image of the previous frame of image, and comparing the counted number with the pixel value of the image, and determining a judgment threshold according to the comparison result; Determine whether the camera is blocked or moved according to a comparison result between the number of pixels with a gray value of 255 in the binary image and the judgment threshold; The step of determining the judgment threshold according to the comparison result specifically includes: Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels whose grayscale values in the grayscale image of the previous frame image are greater than the preset value to the image pixel value is k, then the current motion judgment threshold m = a + k* (ba), the current occlusion judgment threshold n = c + k* (dc); The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
2. The method according to claim 1, characterized in that The judgment threshold includes an image movement value and an occlusion value; The step of comparing the number of pixels with a gray value of 255 in the binary image with a judgment threshold to determine whether the camera is blocked or moved specifically includes: If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved; If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
3. A device for detecting the movement of a camera being blocked, characterized in that: include: A grayscale processing module is used to extract the front and back two frames of the video captured by the camera, and perform grayscale processing on the images to obtain grayscale images; A difference processing module, used for obtaining a difference image of the grayscale images of the two preceding and following frames of images by using a frame difference method; A binarization module, used for performing binarization processing on the difference image to obtain a binary image; A comparison and judgment module, used to judge whether the camera is blocked or moved according to a comparison result between the number of pixels with a gray value of 255 in the binary image and a judgment threshold; A judgment threshold determination module, used for counting the number of pixels with grayscale values greater than a preset value in the grayscale image of the previous frame of image before the comparison judgment module determines whether the camera is blocked or moved based on the comparison result of the number of pixels with grayscale values of 255 in the binary image and the preset threshold, and comparing the counted number with the pixel value of the image, and determining the judgment threshold according to the comparison result; Wherein, the judgment threshold determination module is specifically used for: Assume that the range of the motion judgment threshold is [a, b], the range of the occlusion judgment threshold is [c, d], and the ratio of the number of pixels with grayscale values greater than the preset value in the grayscale image of the previous frame image to the image pixel value is k, then Current motion judgment threshold m=a+k*(ba), current occlusion judgment threshold n=c+k*(dc); The image movement value is obtained by multiplying the image pixel value with the current movement judgment threshold, and the occlusion value is obtained by multiplying the image pixel value with the current occlusion judgment threshold.
4. The device according to claim 3, characterized in that The judgment threshold includes an image movement value and an occlusion value; The comparison and judgment module is specifically used for: If the number of pixels with a grayscale value of 255 in the binary image is greater than or equal to the image movement value and less than or equal to the occlusion value, it is determined that the camera is moved; If the number of pixels with a grayscale value of 255 in the binary image is greater than the occlusion value, it is determined that the camera is blocked.
5. A terminal device, characterized in that: include: processor; as well as A memory having executable codes stored thereon, which, when executed by the processor, causes the processor to execute the method according to claim 1 or 2.
6. A non-transitory machine-readable storage medium having executable code stored thereon, characterized in that: When the executable code is executed by a processor of an electronic device, the processor is caused to execute the method as claimed in claim 1 or 2.
Citation Information
Patent Citations
Method and apparatus for detecting interference of camera
CN107948465A