Method, system, electronic device and storage medium for extracting foreground image

Through differential calculation and grayscale processing, the foreground image is automatically extracted, which solves the problem of cumbersome manual operation in the prior art, and realizes fast and simple foreground image processing.

CN111462148BActive Publication Date: 2025-01-14BEIJING JINGDONG SHANGKE INFORMATION TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN201910058866.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-01-22
Publication Date
2025-01-14
Estimated Expiration
2039-01-22

AI Technical Summary

Technical Problem

The process of extracting foreground images in the prior art requires manual operation, which is highly technically dependent and cumbersome and takes a long time.

Method used

The difference between the background image and the image to be extracted is obtained through differential operation, and the channels are separated for grayscale and binarization. The pixel value is set to 0 according to specific conditions to remove background information, and the foreground image can be automatically extracted, and the outline can be widened to further Remove background effects.

Benefits of technology

It realizes automatic extraction of foreground images, reduces technical dependence, simplifies processing processes, and improves efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN111462148B_ABST
    Figure CN111462148B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, system, electronic device and storage medium for extracting a foreground image. The method includes: obtaining a background image; obtaining an image to be extracted; performing a differential operation on the background image and the image to be extracted, and obtaining a first image according to the result of the differential operation; dividing the first image into three channels of R, G and B to obtain a first sub-image of each channel; graying and binarizing the first sub-image of each channel in turn to obtain a second sub-image of each channel; obtaining all first coordinates that meet a first condition, the first condition including: the gray value of the second sub-image with the same color as the background image at the first coordinate is 255, and the gray value of the second sub-image with a different color from the background image at the first coordinate is 0; setting the pixel value at the first coordinate in the first image to 0 to obtain a foreground image. The present invention eliminates the technical dependence of the current foreground image extraction on technical production personnel, and the processing process is fast and simple.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and in particular to a method, system, electronic device and storage medium for extracting a foreground image. Background Art

[0002] Blue screen technology is commonly used in film and television shooting. Specifically, by shooting image information on a blue background of the same color, the special color information of the background color is used to distinguish the foreground and background, thereby achieving the purpose of extracting foreground information. In current film and television production, relevant technical production personnel use image and audio processing software to manually extract the foreground image from each frame of video image. The extraction process of the foreground image is highly dependent on the technical production personnel's skills, and the processing process is cumbersome and time-consuming. Summary of the invention

[0003] The technical problem to be solved by the embodiments of the present invention is to overcome the defect of manually extracting a foreground image in the prior art, and to provide a method, system, electronic device and storage medium for extracting a foreground image.

[0004] The embodiments of the present invention solve the above technical problems through the following technical solutions:

[0005] A method for extracting a foreground image, characterized in that the method comprises:

[0006] Obtain a background image, wherein the color of the background image is any one of R (Red), G (Green), and B (Blue);

[0007] Acquire an image to be extracted, wherein the image to be extracted is an image captured with the background image as the background;

[0008] Performing a differential operation on the background image and the image to be extracted, and obtaining a first image according to a result of the differential operation;

[0009] Divide the first image into three channels of R, G, and B to obtain a first sub-image of each channel;

[0010] The first sub-image of each channel is gray-scaled and binarized in sequence to obtain the second sub-image of each channel, wherein the gray-scale value in the second sub-image includes 0 and 255;

[0011] Obtain all first coordinates that meet a first condition, where the first condition includes:

[0012] The grayscale value of the second sub-image having the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image having a different color from the background image at the first coordinate is 0;

[0013] The pixel values ​​at the first coordinates in the first image are set to 0 to obtain a foreground image.

[0014] Preferably, the step of performing a differential operation on the background image and the image to be extracted and obtaining the first image according to the result of the differential operation comprises:

[0015] Performing a difference operation on the background image and the image to be extracted to obtain a second image;

[0016] Divide the second image into three channels of R, G, and B to obtain a third sub-image of each channel;

[0017] The third sub-image of each channel is gray-scaled and binarized in sequence to obtain a fourth sub-image of each channel, wherein the gray-scale value in the fourth sub-image includes 0 and 255;

[0018] Get all second coordinates that meet the second condition, where the second condition includes:

[0019] The grayscale value of the fourth sub-image of at least one channel at the second coordinate is 255;

[0020] The pixel values ​​at other positions in the image to be extracted except the second coordinate are set to 0 to obtain a first image.

[0021] Preferably, after the step of obtaining the first image, the method further comprises:

[0022] extracting a first contour of the first image;

[0023] Widening the width of the first contour to a preset width to obtain a second contour;

[0024] extracting a contour image from the first image according to the second contour;

[0025] The step of dividing the first image into three channels of R, G, and B to obtain a first sub-image of each channel comprises:

[0026] The contour image is divided into three channels of R, G, and B to obtain the first sub-image of each channel.

[0027] Preferably, when the step of obtaining the first image includes obtaining the fourth sub-image of each channel, in the step of widening the width of the first contour to a preset width, the preset width is determined by the following steps:

[0028] In the fourth sub-image of each channel, obtain the minimum horizontal coordinate and the maximum horizontal coordinate with a grayscale value of 255;

[0029] In the fourth subgraph of each channel, let the difference between the maximum horizontal coordinate and the minimum horizontal coordinate be the middle width;

[0030] The preset width is determined according to the middle width in the fourth sub-image of each channel.

[0031] Preferably, the image to be extracted is a frame of image in a video to be extracted which is taken with the background image as the background, and the step of obtaining the image to be extracted includes:

[0032] Acquire a frame of image to be extracted from the video to be extracted;

[0033] After the step of obtaining the foreground image, the method further comprises:

[0034] Determine whether the video to be extracted includes images to be extracted that have not been acquired in other frames;

[0035] If so, another frame of the image to be extracted that has not been obtained is obtained from the video to be extracted, and the step of performing a differential operation on the background image and the image to be extracted is continued, and the step of obtaining the first image according to the result of the differential operation is performed.

[0036] An electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the electronic device implements any of the above-mentioned methods for extracting a foreground image when the processor executes the computer program.

[0037] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of any of the above-mentioned methods for extracting a foreground image.

[0038] A system for extracting a foreground image, characterized in that the system comprises:

[0039] A background image acquisition module is used to acquire a background image, wherein the color of the background image is any one of R, G, and B;

[0040] An image acquisition module to be extracted, used to acquire an image to be extracted, wherein the image to be extracted is an image captured with the background image as the background;

[0041] A first image acquisition module, used for performing a differential operation on the background image and the image to be extracted, and obtaining a first image according to the result of the differential operation;

[0042] A first sub-image acquisition module, used for dividing the first image into three channels of R, G and B, and obtaining a first sub-image of each channel;

[0043] A second sub-image acquisition module is used to sequentially grayscale and binarize the first sub-images of each channel to obtain a second sub-image of each channel, wherein the grayscale values ​​in the second sub-image include 0 and 255;

[0044] The first coordinate acquisition module is used to acquire all first coordinates that meet a first condition, where the first condition includes:

[0045] The grayscale value of the second sub-image having the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image having a different color from the background image at the first coordinate is 0;

[0046] The foreground image acquisition module is used to set the pixel value at the first coordinate in the first image to 0 to obtain a foreground image.

[0047] Preferably, the first image acquisition module includes:

[0048] A second image acquisition unit, used for performing a difference operation on the background image and the image to be extracted to obtain a second image;

[0049] A third sub-image acquisition unit, used for dividing the second image into three channels of R, G and B to obtain a third sub-image of each channel;

[0050] A fourth sub-image acquisition unit is used to sequentially grayscale and binarize the third sub-images of each channel to obtain a fourth sub-image of each channel, wherein the grayscale values ​​in the fourth sub-image include 0 and 255;

[0051] The second coordinate acquisition unit is used to acquire all second coordinates that meet a second condition, where the second condition includes:

[0052] The grayscale value of the fourth sub-image of at least one channel at the second coordinate is 255;

[0053] The first image acquisition unit is used to set the pixel values ​​at other positions in the image to be extracted except the second coordinate to 0 to obtain a first image.

[0054] Preferably, the system further comprises:

[0055] A first contour extraction module, used to extract a first contour of the first image;

[0056] A second contour acquisition module, used for widening the width of the first contour to a preset width to obtain a second contour;

[0057] A contour image extraction module, used for extracting a contour image from the first image according to the second contour;

[0058] The first sub-image acquisition module is specifically used for:

[0059] The contour image is divided into three channels of R, G, and B to obtain the first sub-image of each channel.

[0060] Preferably, when the first image acquisition module includes a fourth sub-image acquisition unit, the second contour acquisition module includes:

[0061] An endpoint abscissa obtaining unit, used to obtain the minimum abscissa and the maximum abscissa of the gray value of 255 in the fourth sub-image of each channel;

[0062] An intermediate width obtaining unit, used for setting the difference between the maximum horizontal coordinate and the minimum horizontal coordinate as the intermediate width in the fourth sub-graph of each channel;

[0063] The preset width determination unit is used to determine the preset width according to the middle width in the fourth sub-image of each channel.

[0064] Preferably, the image to be extracted is a frame of image in a video to be extracted that is taken with the background image as the background, and the image to be extracted acquisition module is specifically used for:

[0065] Acquire a frame of image to be extracted from the video to be extracted;

[0066] The system further comprises:

[0067] A judgment module, used for judging whether the video to be extracted includes images to be extracted that have not been acquired in other frames after calling the foreground image acquisition module;

[0068] If so, the to-be-extracted image acquisition module is called to acquire another frame of the to-be-extracted image that has not been acquired from the to-be-extracted video, and the first image acquisition module is continued to be called.

[0069] The positive progressive effect of the embodiments of the present invention is that: based on the differential operation, the background image information is preliminarily removed from the image to be extracted to obtain the first image, and then the pixel values ​​of the pixels with the same color as the background image in the first image are set to 0 to further remove the background image information and obtain the final foreground image, thereby eliminating the technical dependence of the extraction of the current foreground image on the technology of technical production personnel, and the processing process is fast and simple. BRIEF DESCRIPTION OF THE DRAWINGS

[0070] Figure 1 Flow chart of a method for extracting a foreground image according to Embodiment 1 of the present invention.

[0071] Figure 2 FIG. 4 is a schematic diagram of the hardware structure of an electronic device according to Embodiment 2 of the present invention.

[0072] Figure 3 This is a flowchart of step S3 in the method for extracting a foreground image according to embodiment 4 of the present invention.

[0073] Figure 4This is a partial flow chart of a method for extracting a foreground image according to Embodiment 7 of the present invention.

[0074] Figure 5 It is a schematic diagram of extracting a contour image according to the method for extracting a foreground image according to Embodiment 7 of the present invention.

[0075] Figure 6 Schematic diagram of modules of a system for extracting a foreground image according to embodiment 10 of the present invention.

[0076] Figure 7 Schematic diagram of an image acquisition module in a system for extracting a foreground image according to Embodiment 11 of the present invention.

[0077] Figure 8 Schematic diagram of the modules of a system for extracting a foreground image according to Embodiment 12 of the present invention. DETAILED DESCRIPTION

[0078] The present invention is further described below by way of examples, but the present invention is not limited to the scope of the examples.

[0079] Example 1

[0080] This embodiment provides a method for extracting a foreground image. Figure 1 , the method of this embodiment includes:

[0081] S1. Obtain a background image.

[0082] In this embodiment, the background image is denoted as C, and the color of the background image C can be any one of R, G, and B, wherein the width of the background image C is denoted as w, and the height is denoted as h.

[0083] S2. Obtain the image to be extracted.

[0084] In this embodiment, the image to be extracted is recorded as D, and the image to be extracted D is an image captured with the background image C as the background, wherein the width of the image to be extracted D is w, and the height is h.

[0085] It should be understood that the image D to be extracted may also be a frame of image in the video to be extracted that is taken with the background image C as the background. Then, step S2 specifically includes obtaining a frame of image to be extracted from the video to be extracted.

[0086] S3. Perform a differential operation on the background image and the image to be extracted, and obtain a first image according to the result of the differential operation.

[0087] In this embodiment, an initial foreground image is obtained by performing a difference operation on the background image and the image to be extracted. The initial foreground image is not processed in any way, and the initial foreground image is the first image, wherein the first image is recorded as A.

[0088] S4. Divide the first image into three channels of R, G, and B to obtain a first sub-image of each channel.

[0089] In this embodiment, the first image A is divided into three channels: R, G, and B. The first image A of the R channel is recorded as the first sub-image A. R , the first image A of the G channel is recorded as the first sub-image A G , the first image A of the B channel is recorded as the first sub-image A B .

[0090] S5. Grayscale and binarize the first sub-image of each channel in sequence to obtain the second sub-image of each channel.

[0091] In step S5, the first sub-graph A R Grayscale processing is performed to obtain A R1 , and then A can be R1 Specifically, in this embodiment, the preset threshold value may be A R1 The gray mean Gra_ R , then in A R1 In the example, let the gray value be higher than Gra_ R The gray value of the pixel is 255, which is lower than Gra_ R The gray value of the pixel is 0, and the second sub-image A is obtained R2 .

[0092] Similarly, for the first subgraph A G , A B After grayscale and binarization processing, the second sub-image A is obtained. G2 , A B2 .

[0093] S6. Obtain all first coordinates that meet the first condition.

[0094] This embodiment aims to filter out the background image information, so the first condition includes: the grayscale value of the second sub-image with the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image with a different color from the background image at the first coordinate is 0. Assuming that, in this embodiment, the background image C is a blue screen with color B, then for the pixel point at the first coordinate, there is, at A B2 The gray value is 255, in A R2 and A G2 The mid-gray value is 0.

[0095] S7. Set the pixel value at the first coordinate in the first image to 0 to obtain a foreground image.

[0096] In the first image A, the pixel values ​​of all the pixels at the first coordinates are set to 0 to filter out the background image information, thereby obtaining the final foreground image.

[0097] When the image D to be extracted is a frame of image in the video to be extracted that is taken with the background image C as the background, the method of this embodiment also includes a step of determining whether the video to be extracted includes other frames of the image to be extracted that have not been acquired. If so, another frame of the image to be extracted that has not been acquired is acquired from the video to be extracted, and steps S3-S7 are continued to be executed to obtain the final foreground image of all video frames in the video to be extracted.

[0098] This embodiment is based on differential operation, which preliminarily removes the background image information from the image to be extracted to obtain the first image, and then sets the pixel values ​​of the pixels with the same color as the background image in the first image to 0 to further remove the background image information and obtain the final foreground image. This eliminates the technical dependence of the extraction of the current foreground image on the technology of technical production personnel, and the processing process is fast and simple.

[0099] Example 2

[0100] This embodiment provides an electronic device, which can be expressed in the form of a computing device (for example, a server device), including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the method for extracting a foreground image provided in Embodiment 1 can be implemented when the processor executes the computer program.

[0101] Figure 2 FIG. 4 shows a schematic diagram of the hardware structure of this embodiment. Figure 2 As shown, the electronic device 9 specifically includes:

[0102] At least one processor 91, at least one memory 92, and a bus 93 for connecting different system components (including the processor 91 and the memory 92), wherein:

[0103] The bus 93 includes a data bus, an address bus, and a control bus.

[0104] The memory 92 includes a volatile memory, such as a random access memory (RAM) 921 and / or a cache memory 922 , and may further include a read-only memory (ROM) 923 .

[0105] Memory 92 also includes a program / utility 925 having a set (at least one) of program modules 924, such program modules 924 including but not limited to: an operating system, one or more application programs, other program modules and program data, each of which or some combination may include an implementation of a network environment.

[0106] The processor 91 executes various functional applications and data processing by running the computer programs stored in the memory 92, such as the method for extracting a foreground image provided in the first embodiment of the present invention.

[0107] The electronic device 9 can further communicate with one or more external devices 94 (e.g., keyboards, pointing devices, etc.). Such communication can be performed through an input / output (I / O) interface 95. In addition, the electronic device 9 can also communicate with one or more networks (e.g., local area networks (LANs), wide area networks (WANs), and / or public networks, such as the Internet) through a network adapter 96. The network adapter 96 communicates with other modules of the electronic device 9 through a bus 93. It should be understood that, although not shown in the figure, other hardware and / or software modules can be used in conjunction with the electronic device 9, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (disk array) systems, tape drives, and data backup storage systems, etc.

[0108] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present application, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.

[0109] Example 3

[0110] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method for extracting a foreground image provided in Embodiment 1 are implemented.

[0111] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.

[0112] In a possible implementation manner, the present invention can also be implemented in the form of a program product, which includes program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the steps of the method for extracting a foreground image in Example 1.

[0113] The program code for executing the present invention may be written in any combination of one or more programming languages, and may be executed entirely on a user device, partially on a user device, as an independent software package, partially on a user device and partially on a remote device, or entirely on a remote device.

[0114] Example 4

[0115] Based on the first embodiment, this embodiment provides a method for extracting a foreground image. Unlike the first embodiment, the initial foreground image is not processed. Figure 3 In this embodiment, step S3 specifically includes:

[0116] S31, performing a difference operation on the background image and the image to be extracted to obtain a second image.

[0117] In this embodiment, a second image, ie, an initial foreground image, is obtained by performing a difference operation on the background image C and the image to be extracted D. The second image is denoted as F.

[0118] S32, dividing the second image into three channels of R, G, and B to obtain a third sub-image of each channel.

[0119] In this embodiment, the second image F is divided into three channels: R, G, and B. The second image F of the R channel is recorded as the third sub-image F. R , the second image F of the G channel is recorded as the third sub-image F G , the second image F of channel B is recorded as the third sub-image F B .

[0120] S33, gray-scaling and binarization are performed on the third sub-image of each channel in sequence to obtain the fourth sub-image of each channel.

[0121] In step S33, the third sub-graph F R Grayscale processing is performed to obtain F R1 , and then F can be adjusted according to the preset threshold R1 Specifically, in this embodiment, the preset threshold value may be F R1 The gray mean Gra'_ R , then in F R1 In the example, let the gray value be higher than Gra'_ R The gray value of the pixel is 255, which is lower than Gra'_ R The gray value of the pixel is 0, and the fourth sub-image F is obtained. R2 .

[0122] Similarly, for the third subgraph F G 、F BAfter grayscale and binarization processing, the fourth sub-image F is obtained. G2 、F B2 .

[0123] S34. Obtain all second coordinates that meet the second condition.

[0124] This embodiment aims to preprocess the initial foreground image to preliminarily remove the background image information, so that the second condition includes: the gray value of the fourth sub-image of at least one channel at the second coordinate is 255. B2 If the grayscale value at a certain coordinate in the image is 255, then this coordinate is the second coordinate.

[0125] S35 , setting the pixel values ​​at other positions in the image to be extracted except the second coordinate to 0, to obtain a first image.

[0126] In the image D to be extracted, the pixel values ​​of all pixels other than the second coordinate are set to 0 to achieve preliminary filtering of the background image information to obtain the first image A. That is, in the first image A with a width of w and a height of h, the pixel value at the second coordinate is the pixel value at the second coordinate in the image D to be extracted, and the pixel values ​​at other coordinates are 0.

[0127] On the basis of Example 1, this embodiment further processes the initial foreground image to obtain the first image, and achieves preliminary filtering of background image information, so that the ultimately obtained foreground image can be better separated from the background image information.

[0128] Example 5

[0129] This embodiment provides an electronic device, which can be expressed in the form of a computing device (for example, a server device), including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the method for extracting a foreground image provided in Embodiment 4 can be implemented when the processor executes the computer program.

[0130] Example 6

[0131] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method for extracting a foreground image provided in Embodiment 4 are implemented.

[0132] Example 7

[0133] Based on Example 4, this example provides a method for extracting a foreground image. Figure 4 After step S3, the method of this embodiment further includes:

[0134] S8. Extract a first contour of the first image.

[0135] In step S8, a first contour with a width of a single pixel may be extracted from the first image A using a contour extraction function FindContours.

[0136] S9. Widen the width of the first contour to a preset width to obtain a second contour.

[0137] This embodiment aims to remove the background image information at the edge of the first image A, so as to avoid removing the foreground point with the same color as the background image in the first image A. In this embodiment, the fourth sub-image F R2 、F G2 、F B2 to determine the outline width.

[0138] Specifically, in the fourth subgraph F R2 In the example, get the minimum horizontal coordinate x with a grayscale value of 255 min_R2 and the maximum horizontal coordinate x max_R2 , let the middle width w R2 =x max_R2 -x min_R2 , so, in the fourth subgraph F G2 and F B2 , solve for the middle width w G2 and w B2 . Then we can give w R2 、w G2 、w B2 Set the weight to obtain the foreground width w of the first image A A Finally, according to the actual situation of the first image A, the foreground width w is determined A The ratio of the contour width to the contour width is used to determine the final contour width (the contour width is an integer). For example, in this embodiment, the ratio is 10:1.

[0139] S10. Extracting a contour image from the first image according to the second contour.

[0140] In step S10, edge image extraction of the first image A is implemented. Figure 5 As shown, the shaded part in the figure is the first image A, the first outline L1 is widened to the second outline L2, and the outline image P is extracted based on the second outline L2.

[0141] On the basis of extracting the contour image, the first image A is replaced by the contour image P in the subsequent steps. Specifically, in step S4, the contour image P is divided into three channels of R, G, and B to obtain the first sub-image P of each channel. R , P G , P B In step S5, the first subgraph P R , P G, P B Grayscale processing is performed to obtain P R1 , P G1 , P B1 , for P R1 , P G1 , P B1 Binarization is performed to obtain the second sub-graph P R2 , P G2 , P B2 In step S6, based on the second subgraph P R2 , P G2 , P B2 All first coordinates that meet the first condition are obtained. In step S7, the pixel value at the first coordinate in the contour image P is set to 0 to obtain the final foreground image.

[0142] Based on Example 4, this embodiment extracts the first contour of the first image, and obtains the second contour based on the first contour, thereby extracting the contour image of the first image and filtering out the background image information in the contour image to avoid removing the foreground points with the same color as the background image in the first image.

[0143] Example 8

[0144] This embodiment provides an electronic device, which can be expressed in the form of a computing device (for example, a server device), including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the method for extracting a foreground image provided in Embodiment 7 can be implemented when the processor executes the computer program.

[0145] Example 9

[0146] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the steps of the method for extracting a foreground image provided in Embodiment 7 are implemented.

[0147] Example 10

[0148] This embodiment provides a system for extracting a foreground image. Figure 6 , the system of this embodiment includes:

[0149] The background image acquisition module 1 is used to acquire the background image. In this embodiment, the background image is denoted as C, and the color of the background image C can be any one of R, G, and B, wherein the width of the background image C is denoted as w, and the height is denoted as h.

[0150] The image acquisition module 2 is used to acquire the image to be extracted. In this embodiment, the image to be extracted is recorded as D, and the image to be extracted D is an image taken with the background image C as the background, wherein the width of the image to be extracted D is w and the height is h.

[0151] It should be understood that the image D to be extracted may also be a frame of image in the video to be extracted that is taken with the background image C as the background. Then, the image acquisition module 2 to be extracted is specifically used to acquire a frame of image to be extracted from the video to be extracted.

[0152] The first image acquisition module 3 is used to perform a differential operation on the background image and the image to be extracted, and obtain a first image according to the result of the differential operation. In this embodiment, the initial foreground image is obtained after performing a differential operation on the background image and the image to be extracted, and no processing is performed on the initial foreground image, then the initial foreground image is the first image, wherein the first image is recorded as A.

[0153] The first sub-image acquisition module 4 is used to divide the first image into three channels, R, G, and B, and obtain the first sub-image of each channel. In this embodiment, the first image A is divided into three channels, R, G, and B, and the first image A of the R channel is recorded as the first sub-image A. R , the first image A of the G channel is recorded as the first sub-image A G , the first image A of the B channel is recorded as the first sub-image A B .

[0154] The second sub-image acquisition module 5 is used to sequentially grayscale and binarize the first sub-images of each channel to obtain the second sub-images of each channel. R Grayscale processing is performed to obtain A R1 , and then A can be R1 Specifically, in this embodiment, the preset threshold value may be A R1 The gray mean Gra_ R , then in A R1 In the example, let the gray value be higher than Gra_ R The gray value of the pixel is 255, which is lower than Gra_ R The gray value of the pixel is 0, and the second sub-image A is obtained R2 .

[0155] Similarly, for the first subgraph A G , A B After grayscale and binarization processing, the second sub-image A is obtained. G2 , A B2 .

[0156] The first coordinate acquisition module 6 is used to acquire all first coordinates that meet the first condition. This embodiment aims to filter out the background image information, so the first condition includes: the grayscale value of the second sub-image with the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image with a different color from the background image at the first coordinate is 0. Assuming that, in this embodiment, the background image C is a blue screen with color B, then for the pixel point at the first coordinate, there is, at A B2 The gray value is 255, in A R2 and A G2 The mid-gray value is 0.

[0157] The foreground image acquisition module 7 is used to set the pixel value at the first coordinate in the first image to 0 to obtain the foreground image. In the first image A, the pixel values ​​of all the pixels at the first coordinate are set to 0 to filter out the background image information, thereby obtaining the final foreground image.

[0158] When the image D to be extracted is a frame of image in the video to be extracted that is taken with the background image C as the background, the system of this embodiment also includes a judgment module, which is used to judge whether the video to be extracted includes other frames of images to be extracted that have not been acquired after calling the foreground image acquisition module. If so, the image acquisition module to be extracted is called to acquire another frame of the image to be extracted that has not been acquired from the video to be extracted, and the first image acquisition module is continued to be called.

[0159] This embodiment is based on differential operation, which preliminarily removes the background image information from the image to be extracted to obtain the first image, and then sets the pixel values ​​of the pixels with the same color as the background image in the first image to 0 to further remove the background image information and obtain the final foreground image. This eliminates the technical dependence of the extraction of the current foreground image on the technology of technical production personnel, and the processing process is fast and simple.

[0160] Embodiment 11

[0161] Based on the embodiment 10, this embodiment provides a system for extracting a foreground image. Unlike the embodiment 10, no processing is performed on the initial foreground image. Figure 7 In this embodiment, the first image acquisition module 3 specifically includes:

[0162] The second image acquisition unit 31 is used to perform a difference operation on the background image and the image to be extracted to obtain a second image. In this embodiment, the second image, namely the initial foreground image, is obtained by performing a difference operation on the background image C and the image to be extracted D. The second image is recorded as F.

[0163] The third sub-image acquisition unit 32 is used to divide the second image into three channels, R, G, and B, to obtain the third sub-image of each channel. In this embodiment, the second image F is divided into three channels, R, G, and B, and the second image F of the R channel is recorded as the third sub-image F. R , the second image F of the G channel is recorded as the third sub-image F G , the second image F of channel B is recorded as the third sub-image F B .

[0164] The fourth sub-image acquisition unit 33 is used to sequentially grayscale and binarize the third sub-image of each channel to obtain the fourth sub-image of each channel. R Grayscale processing is performed to obtain F R1 , and then F can be adjusted according to the preset threshold R1 Specifically, in this embodiment, the preset threshold value may be F R1 Gray mean Gra' R , then in F R1 In the example, let the gray value be higher than Gra'_ R The gray value of the pixel is 255, which is lower than Gra'_ R The gray value of the pixel is 0, and the fourth sub-image F is obtained. R2 .

[0165] Similarly, for the third subgraph F G 、F B After grayscale and binarization processing, the fourth sub-image F is obtained. G2 、F B2 .

[0166] The second coordinate acquisition unit 34 is used to acquire all second coordinates that meet the second condition. This embodiment aims to preprocess the initial foreground image to preliminarily remove the background image information. Thus, the second condition includes: the gray value of the fourth sub-image of at least one channel at the second coordinate is 255. For example, F B2 If the grayscale value at a certain coordinate in the image is 255, then this coordinate is the second coordinate.

[0167] The first image acquisition unit 35 is used to set the pixel values ​​at other positions in the image to be extracted except the second coordinate to 0, so as to obtain the first image. The pixel values ​​of all pixel points other than the second coordinate in the image to be extracted D are set to 0 to achieve preliminary filtering of background image information, so as to obtain the first image A. That is, in the first image A with a width of w and a height of h, the pixel value at the second coordinate is the pixel value at the second coordinate in the image to be extracted D, and the pixel values ​​at other coordinates are 0.

[0168] On the basis of Example 10, this embodiment further processes the initial foreground image to obtain the first image, and achieves preliminary filtering of background image information, so that the ultimately obtained foreground image can be better separated from the background image information.

[0169] Example 12

[0170] Based on Example 11, this embodiment provides a system for extracting a foreground image. Figure 8 Schematic diagram of the modules of this embodiment is shown. Figure 8 , the system of this embodiment also includes:

[0171] The first contour extraction module 8 is used to extract the first contour of the first image. In this embodiment, the contour extraction function FindContours can be used to extract the first contour of the first image A with a width of one pixel.

[0172] The second contour acquisition module 10 is used to widen the width of the first contour to a preset width to obtain a second contour. This embodiment aims to remove the background image information of the edge portion of the first image A, so as to avoid removing the foreground point with the same color as the background image in the first image A. In this embodiment, the fourth sub-image F R2 、F G2 、F B2 to determine the outline width.

[0173] Specifically, Figure 8 As shown, the second contour acquisition module 10 includes:

[0174] The horizontal coordinate acquisition unit 101 is used to obtain the horizontal coordinate of the fourth sub-graph F R2 In the example, get the minimum horizontal coordinate x with a grayscale value of 255 min_R2 and the maximum horizontal coordinate x max_R2 .

[0175] The intermediate width acquisition unit 102 is used to solve the intermediate width w R2 , let w R2 =x max_R2 -x min_R2 Thus, the intermediate width acquisition unit 102 also respectively G2 and F B2 , find the middle width w G2 and w B2 .

[0176] The preset width determination unit 103 is specifically configured to determine the width of the R2 、w G2 、w B2 Set the weight to obtain the foreground width w of the first image A AThen, according to the actual situation of the first image A, the foreground width w is determined A and the contour width to determine the final contour width (the contour width is an integer). For example, in this embodiment, the ratio is 10:1.

[0177] The contour image extraction module 11 is used to extract the contour image from the first image according to the second contour. In this embodiment, the edge image of the first image A is extracted. Figure 5 As shown, the shaded part in the figure is the first image A, the first outline L1 is widened to the second outline L2, and the outline image P is extracted based on the second outline L2.

[0178] On the basis of extracting the contour image, the contour image P replaces the first image A in the subsequent module calls. Specifically, the first sub-image acquisition module 4 is used to divide the contour image P into three channels of R, G, and B, and obtain the first sub-image P of each channel. R , P G , P B The second sub-image acquisition module 5 is used to obtain the first sub-image P R , P G , P B Grayscale processing is performed to obtain P R1 , P G1 , P B1 , for P R1 , P G1 , P B1 Binarization is performed to obtain the second sub-graph P R2 , P G2 , P B2 The first coordinate acquisition module 6 is used to obtain the coordinates of the second sub-graph P R2 , P G2 , P B2 All first coordinates meeting the first condition are obtained. The foreground image acquisition module 7 is used to set the pixel value at the first coordinate in the contour image P to 0 to obtain the final foreground image.

[0179] Based on Example 11, this embodiment extracts the first contour of the first image, and obtains the second contour based on the first contour, and then extracts the contour image of the first image, and filters out the background image information in the contour image to avoid removing the foreground points with the same color as the background image in the first image.

[0180] Although the specific embodiments of the present invention are described above, it should be understood by those skilled in the art that this is only for illustration and the protection scope of the present invention is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present invention, but these changes and modifications all fall within the protection scope of the present invention.

Claims

1. A method for extracting a foreground image, characterized in that: The method comprises: Obtain a background image, the color of the background image being any one of R, G, and B; Acquire an image to be extracted, wherein the image to be extracted is an image captured with the background image as the background; Performing a differential operation on the background image and the image to be extracted, and obtaining a first image according to a result of the differential operation; Divide the first image into three channels of R, G, and B to obtain a first sub-image of each channel; The first sub-image of each channel is gray-scaled and binarized in sequence to obtain the second sub-image of each channel, wherein the gray-scale value in the second sub-image includes 0 and 255; Obtain all first coordinates that meet a first condition, where the first condition includes: The grayscale value of the second sub-image having the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image having a different color from the background image at the first coordinate is 0; The pixel values ​​at the first coordinates in the first image are set to 0 to obtain a foreground image.

2. The method for extracting a foreground image according to claim 1, wherein: The step of performing a differential operation on the background image and the image to be extracted and obtaining the first image according to the result of the differential operation comprises: Performing a difference operation on the background image and the image to be extracted to obtain a second image; Divide the second image into three channels of R, G, and B to obtain a third sub-image of each channel; The third sub-image of each channel is gray-scaled and binarized in sequence to obtain a fourth sub-image of each channel, wherein the gray-scale value in the fourth sub-image includes 0 and 255; Get all second coordinates that meet the second condition, where the second condition includes: The grayscale value of the fourth sub-image of at least one channel at the second coordinate is 255; The pixel values ​​at other positions in the image to be extracted except the second coordinate are set to 0 to obtain a first image.

3. The method for extracting a foreground image according to claim 2, wherein: After the step of obtaining the first image, the method further comprises: extracting a first contour of the first image; Widening the width of the first contour to a preset width to obtain a second contour; extracting a contour image from the first image according to the second contour; The step of dividing the first image into three channels of R, G, and B to obtain a first sub-image of each channel comprises: The contour image is divided into three channels of R, G, and B to obtain the first sub-image of each channel.

4. The method for extracting a foreground image according to claim 3, wherein: When the step of obtaining the first image includes obtaining a fourth sub-image of each channel, in the step of widening the width of the first contour to a preset width, the preset width is determined by the following steps: In the fourth sub-image of each channel, obtain the minimum horizontal coordinate and the maximum horizontal coordinate with a grayscale value of 255; In the fourth subgraph of each channel, let the difference between the maximum horizontal coordinate and the minimum horizontal coordinate be the middle width; The preset width is determined according to the middle width in the fourth sub-image of each channel.

5. The method for extracting a foreground image according to claim 1, wherein: The image to be extracted is a frame of image in the video to be extracted which is taken with the background image as the background, and the step of obtaining the image to be extracted includes: Acquire a frame of image to be extracted from the video to be extracted; After the step of obtaining the foreground image, the method further comprises: Determine whether the video to be extracted includes images to be extracted that have not been acquired in other frames; If so, another frame of the image to be extracted that has not been obtained is obtained from the video to be extracted, and the step of performing a differential operation on the background image and the image to be extracted is continued, and the step of obtaining the first image according to the result of the differential operation is performed.

6. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method for extracting a foreground image according to any one of claims 1 to 5 is implemented.

7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for extracting a foreground image according to any one of claims 1 to 5 are implemented.

8. A system for extracting a foreground image, characterized in that: The system comprises: A background image acquisition module is used to acquire a background image, wherein the color of the background image is any one of R, G, and B; An image acquisition module to be extracted, used to acquire an image to be extracted, wherein the image to be extracted is an image captured with the background image as the background; A first image acquisition module, used for performing a differential operation on the background image and the image to be extracted, and obtaining a first image according to the result of the differential operation; A first sub-image acquisition module, used for dividing the first image into three channels of R, G and B, and obtaining a first sub-image of each channel; A second sub-image acquisition module is used to sequentially grayscale and binarize the first sub-images of each channel to obtain a second sub-image of each channel, wherein the grayscale values ​​in the second sub-image include 0 and 255; The first coordinate acquisition module is used to acquire all first coordinates that meet a first condition, where the first condition includes: The grayscale value of the second sub-image having the same color as the background image at the first coordinate is 255, and the grayscale value of the second sub-image having a different color from the background image at the first coordinate is 0; The foreground image acquisition module is used to set the pixel value at the first coordinate in the first image to 0 to obtain a foreground image.

9. The system for extracting a foreground image according to claim 8, characterized in that: The first image acquisition module comprises: A second image acquisition unit, used for performing a difference operation on the background image and the image to be extracted to obtain a second image; A third sub-image acquisition unit, used for dividing the second image into three channels of R, G and B to obtain a third sub-image of each channel; A fourth sub-image acquisition unit is used to sequentially grayscale and binarize the third sub-images of each channel to obtain a fourth sub-image of each channel, wherein the grayscale values ​​in the fourth sub-image include 0 and 255; The second coordinate acquisition unit is used to acquire all second coordinates that meet a second condition, where the second condition includes: The grayscale value of the fourth sub-image of at least one channel at the second coordinate is 255; The first image acquisition unit is used to set the pixel values ​​at other positions in the image to be extracted except the second coordinate to 0 to obtain a first image.

10. The system for extracting a foreground image according to claim 9, characterized in that: The system further comprises: A first contour extraction module, used to extract a first contour of the first image; A second contour acquisition module, used for widening the width of the first contour to a preset width to obtain a second contour; A contour image extraction module, used for extracting a contour image from the first image according to the second contour; The first sub-image acquisition module is specifically used for: The contour image is divided into three channels of R, G, and B to obtain the first sub-image of each channel.

11. The system for extracting a foreground image according to claim 10, characterized in that: When the first image acquisition module includes a fourth sub-image acquisition unit, the second contour acquisition module includes: An endpoint abscissa obtaining unit, used to obtain the minimum abscissa and the maximum abscissa of the gray value of 255 in the fourth sub-image of each channel; An intermediate width obtaining unit, used for setting the difference between the maximum horizontal coordinate and the minimum horizontal coordinate as the intermediate width in the fourth sub-graph of each channel; The preset width determination unit is used to determine the preset width according to the middle width in the fourth sub-image of each channel.

12. The system for extracting a foreground image according to claim 8, characterized in that: The image to be extracted is a frame of image in the video to be extracted which is taken with the background image as the background, and the image to be extracted acquisition module is specifically used for: Acquire a frame of image to be extracted from the video to be extracted; The system further comprises: A judgment module, used for judging whether the video to be extracted includes images to be extracted that have not been acquired in other frames after calling the foreground image acquisition module; If so, the to-be-extracted image acquisition module is called to acquire another frame of the to-be-extracted image that has not been acquired from the to-be-extracted video, and the first image acquisition module is continued to be called.

Citation Information

Patent Citations

  • Video image foreground detection method for traffic intersection scene and based on network physical system

    CN102930719A

  • Beautifying method and system for virtual scene live

    CN106713988A