Video data processing method and device, computer device and storage medium
By adding boundaries to the edges of the target image and performing composite image processing, the problems of low efficiency and insufficient accuracy of image background addition function verification are solved, and efficient and accurate verification results are achieved for automated verification.
Patent Information
- Application Number
- CN202110584720.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-05-27
- Publication Date
- 2025-11-25
- Estimated Expiration
- 2041-05-27
AI Technical Summary
In existing technologies, the verification efficiency of image background addition functions is low and the accuracy is difficult to guarantee, which is limited by the technical level of code analysts.
By adding the target image boundary to the edge of the target image, and calling the image background addition function to synthesize the image, the verification image is extracted from the synthesized image based on the boundary features, and the images are compared to determine the verification result.
The system automates the verification of the image background addition function, improving verification efficiency and accuracy and ensuring the reliability of the verification results.
Smart Images

Figure CN115410107B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a video data processing method and device, computer equipment and a storage medium. BACKGROUND
[0002] With the development of image processing technology, users have increasingly high requirements for the diversity of videos. Users can edit videos by adding backgrounds to the videos to make the videos more colorful. Therefore, whether the background adding function can be normally implemented in actual applications is a key factor to guarantee user experience.
[0003] In related technologies, whether the background adding function is normal is usually verified from the implementation code level of the image background adding function. However, this method is not only inefficient, but also is restricted by the technical level of code analysts, and the accuracy of verification is difficult to guarantee. SUMMARY
[0004] Therefore, it is necessary to provide an image processing method, device, computer equipment and storage medium capable of providing efficiency and accuracy of verifying the background adding function.
[0005] An image processing method, the method comprising:
[0006] obtaining a background image and a target image corresponding to an image background adding function;
[0007] adding a target image boundary to an image edge corresponding to the target image to obtain an intermediate image;
[0008] calling the image background adding function to synthesize the intermediate image and the background image to obtain a synthesized image;
[0009] determining a boundary position of the target image boundary in the synthesized image according to a boundary feature of the target image boundary;
[0010] extracting an image corresponding to the target image from the synthesized image based on the boundary position as a verification image;
[0011] obtaining an image comparison result between the verification image and the target image, and determining a verification result corresponding to the image background adding function based on the image comparison result.
[0012] An image processing device, the device comprising:
[0013] an obtaining module configured to obtain a background image and a target image corresponding to an image background adding function;
[0014] add a target image boundary to an image edge corresponding to the target image to obtain an intermediate image;
[0015] invoke the image background adding function to synthesize the intermediate image and the background image to obtain a synthesized image;
[0016] determine a boundary position of the target image boundary in the synthesized image according to a boundary feature of the target image boundary;
[0017] extract an image corresponding to the target image from the synthesized image as a verification image based on the boundary position;
[0018] obtain an image comparison result between the verification image and the target image, and determine a verification result corresponding to the image background adding function based on the image comparison result.
[0019] A computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0020] obtain a background image and a target image corresponding to an image background adding function;
[0021] add a target image boundary to an image edge corresponding to the target image to obtain an intermediate image;
[0022] invoke the image background adding function to synthesize the intermediate image and the background image to obtain a synthesized image;
[0023] determine a boundary position of the target image boundary in the synthesized image according to a boundary feature of the target image boundary;
[0024] extract an image corresponding to the target image from the synthesized image as a verification image based on the boundary position;
[0025] obtain an image comparison result between the verification image and the target image, and determine a verification result corresponding to the image background adding function based on the image comparison result.
[0026] A computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the following steps:
[0027] obtain a background image and a target image corresponding to an image background adding function;
[0028] add a target image boundary to an image edge corresponding to the target image to obtain an intermediate image;
[0029] The image background addition function is invoked to synthesize the intermediate image and the background image to obtain a composite image;
[0030] The boundary position of the target image boundary in the synthesized image is determined based on the boundary features of the target image boundary;
[0031] Based on the boundary position, an image corresponding to the target image is extracted from the synthetic image and used as a verification image;
[0032] Obtain the image comparison result between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison result.
[0033] The aforementioned image processing method, apparatus, computer equipment, and storage medium obtain a synthesized image by calling the image background addition function, extract an image corresponding to the target image from the synthesized image as a verification image, obtain the image comparison result between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison result. This achieves automated verification of the image background addition function and improves verification efficiency. Since a target image boundary is added to the image edge corresponding to the target image before synthesis to obtain an intermediate image, the intermediate image and the background image are synthesized when the image background addition function is called to obtain the synthesized image. During image extraction, the target image boundary is extracted based on the boundary position of the synthesized image, which can accurately extract the verification image. Therefore, when verifying the image background addition function based on this verification image, the verification accuracy can be improved. Attached Figure Description
[0034] Figure 1 This is an application environment diagram of an image processing method in one embodiment;
[0035] Figure 2 This is a flowchart illustrating an image processing method in one embodiment;
[0036] Figure 3 A schematic diagram of the interface for adding an image background function in one embodiment;
[0037] Figure 4 This is a schematic diagram illustrating the addition of a target image boundary to a target image in one embodiment;
[0038] Figure 5 This is a flowchart illustrating the image processing method in another embodiment;
[0039] Figure 6 This is a schematic diagram illustrating the effect of synthesized images in one embodiment;
[0040] Figure 7This is a schematic diagram of a verification image extracted in one embodiment;
[0041] Figure 8 This is a schematic diagram illustrating the setting of masked pixel values in one embodiment;
[0042] Figure 9 This is a structural block diagram of an image processing device in one embodiment;
[0043] Figure 10 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0044] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0045] The image processing method provided in this application can be applied to, for example... Figure 1 In the application environment shown, terminal 102 communicates with server 104 via a network. Terminal 102 can obtain the background image and target image corresponding to the image background addition function from server 104, add the target image boundary to the image edge corresponding to the target image to obtain an intermediate image, call the image background addition function to synthesize the intermediate image and the background image to obtain a synthesized image, further determine the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary, extract the image corresponding to the target image from the synthesized image based on the boundary position as a verification image, finally obtain the image comparison result between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison result.
[0046] The terminal 102 can be, but is not limited to, various personal computers, laptops, smartphones, tablets and portable wearable devices, and the server 104 can be implemented by a standalone server or a server cluster consisting of multiple servers.
[0047] In some embodiments, such as Figure 2 As shown, an image processing method is provided, which is applied to... Figure 1 Taking the terminal in the example, the explanation includes the following steps:
[0048] Step 202: Obtain the background image and target image corresponding to the image background addition function.
[0049] The image background addition function adds another image as a background to a given image. After addition, the two images are combined into a single image. The image to which the background is added is called the target image, and the image used as the background is called the background image. The target image can be a single image or a video frame. It can be understood that when adding a background image to a video frame, the background of the video is static; alternatively, different background images can be added to each video frame, in which case the background images corresponding to each video frame form a dynamic background video. Since the image background addition function is usually iteratively updated, and the corresponding code is modified during the update process, it needs to be validated after the update to ensure that the image background addition function functions correctly.
[0050] For example, such as Figure 3 As shown, this is a schematic diagram of the interface corresponding to the image background addition function. When the user selects the target image shown in (a) and the background image shown in (b), and clicks the "Frame Background" icon 302 corresponding to the background addition function in (c), the terminal will combine the target image and the background image to obtain image 304. After the combination is completed, the terminal interface can display the prompt message "Done".
[0051] Specifically, the terminal has a client installed for editing images or videos. This client can be a web client or an app (APP). The client has an image background addition function. The client automatically verifies the background addition function in response to a verification command. This verification command can be automatically triggered, for example, at preset intervals, or it can be triggered by user interaction, such as when the user clicks the "Automatic Verification" button on the client interface. During the verification process, the terminal first needs to obtain the background image and the target image corresponding to the image background addition function.
[0052] In some embodiments, the image background addition function can add a background to a single image. In this case, the terminal can acquire two images, using one image as the background image and the other as the target image. In other embodiments, the image background addition function can add a background to a video. In this case, the terminal can acquire a video and an image, using the image as the background image and sequentially using each frame of the video as the target image.
[0053] Step 204: Add target image boundaries to the image edges corresponding to the target image to obtain the intermediate image.
[0054] In this context, image edges refer to the boundaries of an image, specifically its outermost edges, such as the four sides of the image. A target image typically includes multiple image edges; for example, a two-dimensional image might have four: a top edge, a bottom edge, a left edge, and a right edge. The top and bottom edges are parallel, as are the left and right edges. The target image boundary refers to the set of pixels used to define the image edge. Specifically, the target image boundary can be a set of pixels added along the image edge, arranged according to certain rules to form a recognition edge that is parallel to the image edge. For example, a target image boundary could be a recognition edge formed by a predetermined number of red pixels continuously arranged along the image edge.
[0055] It is understandable that the length of the target image boundary at the edge of an image can be the same as or different from the length of the corresponding image edge. When the target image boundary has the same length as the corresponding image edge, the target image boundaries of each image edge can form a bounding box. This bounding box has the same shape as the target image and can enclose the target image.
[0056] Specifically, the terminal determines each image edge corresponding to the target image, adds the target image boundary to each image edge, and obtains an intermediate image. Based on the boundary features of the target image boundary, the terminal can identify the target image boundary from an image that includes that target image boundary.
[0057] Step 206: Use the image background addition function to composite the intermediate image and the background image to obtain the composite image.
[0058] Compositing refers to the process of obtaining a single image from two images. Specifically, it can involve stitching two images together, such as overlaying one image onto another. In the overlapping area, pixels from the overlaid image are not displayed; instead, pixels from the overlay image are shown. For example, if we composite an intermediate image A and a background image B, in the overlapping area, pixels from the intermediate image A are overlaid on those from the background image B. In this overlapping area, pixels from the background image B are replaced, and pixels from the intermediate image A are displayed, while pixels from the background image B are not.
[0059] Specifically, when the terminal calls the image background addition function to composite the intermediate image and the background image, if the image background addition function is working properly, the intermediate image can be moved to any specified position of the background image so that the intermediate image can accurately cover the image area of the background image. At this time, the intermediate image and the background image are composited into one image, which is the composite image. The background content of the composite image is the same as the background image, while the foreground content is the same as the intermediate image.
[0060] It is understood that in some embodiments, the position of the intermediate image in the composite image can be a standard position. A standard position means that the edges of the intermediate image are parallel to the spatial coordinate axes of each dimension. Taking a two-dimensional image as an example, a standard position means that the top and bottom edges of the image are horizontal, and the left and right edges are vertical. In other embodiments, the intermediate image can be rotated in the composite image at any rotation angle and direction. The rotation angle and direction can be preset as needed. The rotation angle can be any angle between 0 degrees and 360 degrees, and the rotation direction can be counterclockwise or clockwise.
[0061] It is understandable that when the image background addition function malfunctions, various errors may occur when the terminal calls the image background addition function to synthesize the intermediate image and the background image. For example, the intermediate image may only display part of the content in the synthesized image, the ratio of the intermediate image may not be the same as the target image, the center position of the intermediate image may not be the specified center position, the ratio of the synthesized image may not be the same as the background image, and the background content in the synthesized image may not correspond to the background image, etc.
[0062] In some embodiments, when the terminal composites an intermediate image and a background image, it can adjust the scale of the intermediate image and move the adjusted intermediate image to any specified position in the background image to composite the intermediate image and the background image into a single image. The scale adjustment can involve enlarging or shrinking the size of the intermediate image. The specific adjustment scale can be set as needed. For example, when the size of the intermediate image is the same as the size of the background image, or when the size of the intermediate image is larger than the size of the background image, the size of the intermediate image can be reduced to ensure that the background is fully displayed in the composite image.
[0063] Step 208: Determine the boundary position of the target image in the synthesized image based on the boundary features of the target image boundary.
[0064] The boundary features of the target image boundary refer to the image features of the target image boundary. Different types of target image boundaries have different image features. Specifically, the boundary features of the target image boundary can be the arrangement rules of the pixels forming the target image boundary. For example, the boundary features of the target image boundary can be the alternating arrangement of color blocks formed by pixels of different colors. The boundary position of the image boundary in the composite image refers to the position of the pixel set corresponding to the target image boundary in the composite image. In some embodiments, when the position of the intermediate image in the composite image is a standard position, the boundary position of the image boundary in the composite image can be the pixel row or pixel column where the image boundary is located.
[0065] Specifically, when the terminal adds the target image boundary to the image edge corresponding to the target image, it determines the boundary features of the target image boundary. Then, when it is necessary to determine the boundary position, the terminal can scan in the synthesized image. When a set of pixels that conforms to the boundary features of the target image boundary is scanned, the boundary position of the image boundary in the synthesized image is determined according to the position of the pixel set.
[0066] Step 210: Extract the image corresponding to the target image from the synthetic image based on the boundary location, and use it as the verification image.
[0067] The verification image refers to an image that can be used to verify the background addition function. The verification image corresponding to the target image refers to the image at the corresponding position of the target image in the synthesized image. That is, when the background addition function is working properly, the verification image is an image whose content is consistent with the target image.
[0068] Specifically, since the target image boundary is added to the corresponding image edge of the target image, the position of the image boundary in the synthesized image is determined, that is, the position of the image edge of the target image is determined. Thus, the region where the target image is located can be determined based on the position of each image edge of the target image. The terminal can extract the image in this region from the synthesized image. When the image background addition function is normal, the extracted image and the image content of the target image are consistent. Therefore, the terminal can use the extracted image as a verification image to verify the image background addition function.
[0069] Step 212: Obtain the image comparison results between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison results.
[0070] The image comparison result refers to the result obtained by comparing two images. The image comparison result is either similar or dissimilar. Similarity means the similarity between the images is greater than a similarity threshold or the difference is less than a difference threshold; dissimilarity means the similarity is less than a similarity threshold or the difference is greater than a difference threshold. The verification result refers to the result of verifying the background addition function. The verification result includes "verification correct" and "verification error." A "verification correct" result indicates that the background addition function is normal and can correctly add backgrounds; conversely, a "verification correct" result indicates that the background addition function is abnormal and an error occurred during the background addition process.
[0071] Specifically, the terminal can obtain the image comparison results between the verification image and the target image, and obtain the verification result based on the background addition function of the verification image according to the image comparison results. During the verification process, the terminal determines whether the verification image and the target image are similar. When the verification image and the target image are similar, the verification result is determined to be correct; when the verification image and the target image are similar, the verification result is determined to be incorrect.
[0072] In some embodiments, when the image comparison result is dissimilar, the terminal determines that the verification image and the target image are not similar. The terminal can then output a function error message corresponding to the image background addition function and initiate a function repair task corresponding to the image background addition function. The error message refers to information indicating an error in the verification function, and can be any one of voice prompts, text prompts, or video prompts.
[0073] In some embodiments, since the size of the target image may be adjusted when the terminal synthesizes the image, when the terminal obtains the image comparison result between the verification image and the target image, it can first compare the size of the verification image with the size of the target image. When the size of the verification image is the same as the size of the target image, the verification image and the target image are compared to obtain the comparison result. When the size of the verification image and the target image are different, the verification image and the target image are adjusted to be the same size before comparison.
[0074] In some embodiments, when obtaining the image comparison results between the verification image and the target image, the terminal can perform the comparison based on a hash algorithm. Specifically, a hash algorithm is used to calculate the binary sequence corresponding to the verification image and the target image respectively, obtaining the binary sequence corresponding to the verification image and the target image. Then, the Hamming distance between the binary sequences is calculated. When the Hamming distance is less than a distance threshold, the comparison result is determined to be that the verification image and the target image are similar; otherwise, when the Hamming distance is greater than the distance threshold, the comparison result is determined to be that the verification image and the target image are not similar. The hash algorithm includes one or more of perceptual hashing, mean hashing, and difference hashing algorithms.
[0075] In other embodiments, when the terminal obtains the image comparison results between the verification image and the target image, it can perform the comparison based on color similarity. Specifically, the color pixel difference between the verification image and the target image can be calculated. When the color similarity is greater than a similarity threshold, the comparison result is determined to be that the verification image and the target image are similar; conversely, when the color similarity is less than the similarity threshold, the comparison result is determined to be that the verification image and the target image are dissimilar. The color similarity can be calculated using a histogram algorithm or based on the pixel difference at the same position.
[0076] In other embodiments, to ensure accuracy, the terminal can combine the comparison results based on hash algorithms and the comparison results based on color similarity to determine the image comparison result. For example, if both the comparison results based on hash algorithms and the comparison results based on color similarity indicate that the verification image and the target image are similar, the image comparison result is determined to be that the verification image and the target image are similar; otherwise, it is determined that they are not similar.
[0077] In practical applications, since comparison calculations based on hash algorithms are relatively simple, a hash-based comparison can be performed first. If the comparison result shows that the two images are dissimilar, the color similarity-based comparison is no longer performed, and the final image comparison result is directly determined to be that the verification image and the target image are dissimilar. If the hash-based comparison result shows that the two images are similar, the color similarity-based comparison is performed. If the color similarity-based comparison result shows that the two images are dissimilar, the final image comparison result is determined to be that the verification image and the target image are dissimilar. If the color similarity-based comparison result shows that the two images are similar, the final image comparison result is determined to be that the verification image and the target image are similar.
[0078] Understandably, to improve efficiency, when comparing the verification image with the target image, the terminal can first obtain the size ratio between the corresponding spatial dimensions of the verification image and the size ratio of the target image in the same spatial dimension. By comparing the two obtained size ratios, if the two values are inconsistent, the comparison result can be directly determined as dissimilar, without needing to perform comparisons based on hash algorithms or color similarity. Only when the two obtained size ratios are consistent will a comparison based on hash calculation or color similarity be performed. Since size comparison calculation is simple, the comparison result between images with inconsistent sizes can be quickly determined, improving comparison efficiency and thus improving verification efficiency.
[0079] In the above image processing method, on the one hand, a composite image is obtained by calling the image background addition function. The image corresponding to the target image is extracted from the composite image as a verification image. The image comparison result between the verification image and the target image is obtained. Based on the image comparison result, the verification result corresponding to the image background addition function is determined, realizing the automated verification of the image background addition function and improving the verification efficiency. On the other hand, since the target image boundary is added to the image edge corresponding to the target image before the synthesis, an intermediate image is obtained. When the image background addition function is called for synthesis, the intermediate image and the background image are synthesized to obtain the composite image. When the image is extracted, it is extracted based on the boundary position of the target image boundary in the composite image. The verification image can be accurately extracted. Therefore, when the image background addition function is verified based on the verification image, the verification accuracy can be improved.
[0080] In this embodiment of the application, by adding a new boundary to the original boundary of the target image, the boundary has corresponding image features. Therefore, after synthesis, the original boundary of the target image can be identified based on the positional correspondence between the added boundary and the original boundary of the target image.
[0081] In some embodiments, adding a target image boundary to the image edge corresponding to the target image to obtain an intermediate image includes: determining the image edge corresponding to the target image; adding corresponding boundary pixels along the image edge outside the image edge to form the target image boundary, thereby obtaining an intermediate image.
[0082] Boundary pixels are pixels that can be used to form boundaries. Boundary pixels can include pixels of one or more different colors.
[0083] Specifically, first, the edges corresponding to the target image are determined, and then the boundary pixels are obtained. For each determined image edge, corresponding boundary pixels are added along the outside of the image edge. The boundary pixels are arranged according to certain rules. After addition, these boundary pixels combine to form the target image boundary. Taking a two-dimensional image as an example, the terminal can determine the first few rows, last few rows, first few columns, and last few columns of pixels in the target image as the top edge, bottom edge, left edge, and right edge of the target image, respectively. Corresponding boundary pixels are added along the top edge, bottom edge, left edge, and right edge to form the target image boundary, thus obtaining the intermediate image.
[0084] In some embodiments, boundary pixels are color blocks formed by pixels of different colors. When adding boundary pixels, the terminal adds these color blocks, spaced apart, to the outside of the image edge, so that the distribution of multiple color blocks of different colors forms the boundary of the target image. Here, a color block refers to an image block composed of pixels of the same color. The size and shape of the color block can be preset. For example, a color block can be rectangular, with a width of 5 and a height of 1, meaning it is formed by arranging 5 pixels of the same color.
[0085] For example, such as Figure 4 The diagram shown illustrates the addition of a target image boundary to a target image in one embodiment. (Reference) Figure 4 Add 5-width color blocks of alternating pure black (0,0,0) and pure white (255,255,255) to the top, bottom, left, and right edges of the target image, respectively, for a total of 10 color blocks at each edge.
[0086] In this embodiment, since the pixels of the target image boundary are added along the image edge and outside the edge, the target image boundary can accurately define the target image, thereby accurately extracting an image consistent with the content of the target image from the synthesized image based on the boundary position of the target image.
[0087] In some embodiments, determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary includes: determining a target scanning direction, wherein the target scanning direction is the direction perpendicular to the edge direction corresponding to the image edge of the target image in the synthesized image; scanning the synthesized image according to the target scanning direction; and when a set of pixels that conforms to the boundary features of the target image boundary is scanned, determining the boundary position of the target image boundary in the synthesized image based on the location of the pixel set.
[0088] The scanning direction refers to the target direction used when scanning the composite image to determine the boundary position. The target scanning direction is the direction perpendicular to the edge direction corresponding to the image edge of the target image in the composite image. The edge direction corresponding to the image edge refers to the direction in which the line corresponding to the image edge extends.
[0089] Specifically, after determining the target scanning direction, the terminal scans the synthesized image according to the target scanning direction. When a set of pixels that conforms to the boundary features of the target image boundary is scanned, the position of the image boundary in the synthesized image is determined according to the location of the pixel set.
[0090] In some embodiments, when the terminal calls the image background addition function to synthesize the intermediate image and the background image, the position of the intermediate image in the synthesized image is fixed to a standard position. Taking a two-dimensional image as an example, the upper and lower edges of the intermediate image are horizontal, and the left and right edges are vertical. The scanning direction determined by the terminal can be horizontal or vertical. The left and right edges can be obtained by scanning in the horizontal direction, and the upper and lower edges can be obtained by scanning in the vertical direction. The horizontal scanning can be from left to right or from right to left, and the vertical scanning can be from top to bottom or from bottom to top.
[0091] In other embodiments, when the terminal calls the image background addition function to synthesize the intermediate image and the background image, the intermediate image can be rotated at any rotation angle and rotation direction in the synthesized image. When the terminal determines the target scanning direction, it first obtains the rotation angle and rotation direction corresponding to the intermediate image when synthesizing the intermediate image and the background image. Based on the rotation angle and rotation direction, it determines the edge direction corresponding to the image edge of the target image in the synthesized image as the reference edge direction, and takes the direction perpendicular to the reference edge direction as the target scanning direction.
[0092] Specifically, the terminal acquires a pre-set rotation angle and direction, and rotates the coordinate axes of each spatial dimension in the same way, selecting the same angle and direction. The resulting direction is determined as the edge direction corresponding to the image edge of the target image in the composite image, and this edge direction is used as the reference edge direction. Taking a two-dimensional image as an example, after rotating the horizontal x-axis and vertical y-axis in the same direction, the edge direction corresponding to the image edge of the target image in the composite image is determined. The terminal further uses the direction perpendicular to the reference edge direction as the target scanning direction.
[0093] In the above embodiments, the target scanning direction is first determined, and the synthesized image is scanned according to the target scanning direction. When a set of pixels that conforms to the boundary features of the target image boundary is scanned, the boundary position of the image boundary in the synthesized image is determined according to the position of the pixel set. Since the target scanning direction is the perpendicular direction to the edge direction corresponding to the image edge of the target image in the synthesized image, the boundary position of the target image boundary can be quickly determined from the synthesized image.
[0094] In some embodiments, scanning the composite image according to the target scanning direction, when a set of pixels that conforms to the boundary features of the target image boundary is scanned, determining the boundary position of the target image boundary in the composite image based on the location of the pixel set includes: scanning the composite image according to the target scanning direction and taking the pixel arrangement unit corresponding to the target scanning direction as a unit; when the pixel features of the current pixel arrangement unit scanned correspond to the boundary features of the target image boundary, determining the boundary position of the target image boundary in the composite image based on the location of the current pixel arrangement unit.
[0095] In this context, a pixel arrangement unit refers to the unit in which pixels are arranged in an image. A pixel arrangement unit includes pixel rows and pixel columns. The pixel features of a pixel arrangement unit refer to the information contained within that unit that distinguishes it from other pixel arrangement units.
[0096] Specifically, the terminal scans the composite image. During the scanning process, it scans one pixel arrangement unit at a time along the scanning direction. Each time a pixel arrangement unit is scanned, it is identified as the current pixel arrangement unit. The terminal then determines whether the pixel features of the current pixel arrangement unit correspond to the boundary features of the target image boundary. If they do, the terminal determines the boundary position of the image boundary in the composite image based on the position of the current pixel arrangement unit. If not, the terminal continues to scan the next pixel arrangement unit until all pixel arrangement units in the scanning direction have been scanned.
[0097] Taking a two-dimensional image as an example, assuming the scanning direction is from top to bottom, the terminal can start from the first row of pixels in the composite image and scan the pixels in the composite image row by row. After scanning each row of pixels, the pixel features of the pixels in that row are compared with the boundary features of the target image boundary to determine whether they correspond. If they do, the position of the target image boundary corresponding to the upper edge of the target image in the composite image is determined based on the position of the pixels in that row. If not, the next row is scanned until all pixel rows are scanned.
[0098] In the above embodiments, scanning the composite image in units of pixel arrangement can improve scanning efficiency.
[0099] In some embodiments, when the pixel features of the current pixel arrangement unit obtained by scanning correspond to the boundary features of the target image boundary, determining the boundary position of the target image boundary in the composite image based on the position of the current pixel arrangement unit includes: in the current pixel arrangement unit, counting the number of color block transformations between adjacent target color blocks; when the counted number of color block transformations is consistent with the number of color block transformations corresponding to the boundary features, determining that the pixel features of the current pixel arrangement unit obtained by scanning correspond to the boundary features of the target image boundary, and determining the boundary position of the target image boundary in the composite image based on the position of the current pixel arrangement unit.
[0100] In this embodiment, the boundary features of the target image boundary include multiple target color blocks arranged at intervals. Each color block is composed of multiple pixels of the same color. Different types of color blocks have different colors. The number of color block transformations corresponding to the boundary features is the standard transformation number, that is, the correct number of color block transformations when the target image boundary is included in the current pixel arrangement unit.
[0101] Specifically, within the current pixel arrangement unit, the terminal traverses pixels starting from the first pixel of that unit. When two target color patches of different colors are found to be adjacent, this is counted as one color patch transformation, and the number of color patch transformations corresponding to the current pixel arrangement unit is obtained. When the counted number of color patch transformations matches the number of color patch transformations corresponding to the boundary features, it is determined that the pixel features of the scanned current pixel arrangement unit correspond to the boundary features of the target image boundary. Based on the location of the current pixel arrangement unit, the boundary position of the target image boundary in the synthesized image is determined.
[0102] In some embodiments, counting the number of color block transformations between adjacent target color blocks in the current pixel arrangement unit includes: sequentially traversing pixels in the scanned current pixel arrangement unit; when a target pixel with the same color as any target color block is encountered, a starting color block is determined; continuing to traverse pixels; when it is detected that the color of adjacent pixels has changed to the color corresponding to the target color block, an accumulated color block is determined; and the number of starting pure color blocks and the number of accumulated pure color blocks are added together to obtain the number of color block transformations between adjacent target color blocks.
[0103] For example, suppose the boundary of the target image is as follows: Figure 4 As shown, the scanning process is as follows:
[0104] 1. Set a "color change count" p = 0. When scanning in the current pixel arrangement unit, the current color u is identified starting from the first pixel. When pure white (255,255,255) or pure black (0,0,0) is identified for the first time, the change count p is incremented by 1, and the current color u is assigned the value of (0,0,0) or (255,255,255).
[0105] 2. Then iterate through the colors in sequence. When a color that is different from the current color u is found (i.e., the current color u = (0,0,0) and the color (255,255,255) is found, or the current color u = (255,255,255) and the color (0,0,0) is found), the number of transformations p is incremented by 1, and the current color u is assigned the color that is different from the previous color.
[0106] 3. If the number of transformations during the period is p = L = 10, it means that the number of color block transformations obtained by statistics is consistent with the number of color block transformations corresponding to the boundary features. It is determined that the pixel features of the current pixel arrangement unit correspond to the boundary features of the target image boundary, and the traversal stops.
[0107] 4. If the number of transformations p for the last pixel has not reached the value L, then the pixel features of the pixel arrangement unit are considered not to correspond to the boundary features of the target image boundary, and the traversal continues.
[0108] In the above embodiments, the boundary position of the target image in the composite image is determined by counting the number of color block transformations between adjacent target color blocks. This method is simple, convenient, and easy to calculate, and can improve the efficiency and accuracy of determining the boundary position.
[0109] In some embodiments, obtaining the image comparison result between the verification image and the target image includes: comparing the size of the verification image with the size of the target image; when the size of the verification image and the size of the target image are inconsistent, obtaining a target adjustment ratio, and adjusting the verification image and the target image to be the same size based on the target adjustment ratio; comparing the verification image with the target image to obtain the image comparison result.
[0110] In this embodiment, since the terminal can adjust the proportion of the intermediate image according to the target adjustment ratio during the synthesis of the intermediate image and the background image, in order to make the image comparison result between the verification image and the target image more accurate, the terminal first needs to compare the size of the verification image with the size of the target image to determine whether the size of the intermediate image is consistent with the size of the background image. When the size of the verification image and the size of the target image are inconsistent, the target adjustment ratio is obtained, and the verification image and the target image are adjusted to be consistent in size based on the target adjustment ratio. Finally, the verification image with consistent size is compared with the target image to obtain the image comparison result.
[0111] When the terminal adjusts the verification image and the target image to the same size based on the target adjustment ratio, it can adjust both the verification image and the target image simultaneously, or it can adjust only one of the two images, depending on the obtained target adjustment ratio. For example, the terminal can use one of the verification image and the target image as a reference image, keeping the size of the reference image unchanged, calculate the ratio between the size of the other image and the size of the reference image as the target adjustment ratio, and adjust the other image according to the target adjustment ratio, thereby making the verification image and the target image the same size.
[0112] It is understandable that when the size of the verification image and the size of the target image are the same, the terminal can directly compare the verification image with the target image to obtain the image comparison result.
[0113] In the above embodiments, by comparing the size of the verification image with the size of the target image to determine whether the size of the verification image is consistent with the size of the target image, and performing the comparison step according to the determination result, it can be ensured that when the size of the verification image and the size of the target image are inconsistent, the accuracy of the image comparison result can be improved by adjusting the size.
[0114] In some embodiments, when the size of the verification image and the size of the target image are inconsistent, obtaining a target adjustment ratio and adjusting the verification image and the target image to be the same size based on the target adjustment ratio includes: when the size of the verification image and the size of the target image are inconsistent, determining the smaller size value and the larger size value of the image size of the verification image and the image size of the target image; taking the image corresponding to the larger size value as the target adjustment image, and taking the ratio of the smaller size value to the larger size value as the target adjustment ratio; adjusting the target adjustment image according to the target adjustment ratio to adjust the verification image and the target image to be the same size.
[0115] Specifically, since the target image is adjusted according to a certain ratio during the synthesis process, that is, the width and height of the target image are adjusted by the same amount, the terminal can compare the size of one spatial dimension of the target image with the size of the same spatial dimension of the verification image to determine the smaller and larger size values. The comparison results of other spatial dimensions will necessarily be the same as that spatial dimension. The terminal can take the image corresponding to the smaller size value of that spatial dimension as the target adjustment image, and take the ratio of the smaller size value to the larger size value as the target adjustment ratio. The target adjustment image is adjusted proportionally according to the target adjustment ratio to adjust the verification image and the target image to be the same size.
[0116] Taking two-dimensional images as an example, the terminal can compare the width of the verification image with the width of the target image, or compare the height of the verification image with the height of the target image. Assuming the width of the verification image is M and the width of the target image is N, and M is less than N, the target image is used as the target adjustment image, and M / N is used as the target adjustment ratio to adjust the target adjustment image proportionally.
[0117] In the above embodiments, since the smaller image is used as the standard for adjustment and the larger image is scaled down, the image clarity can be improved by reducing the scale, resulting in less distortion of the adjusted image.
[0118] In some embodiments, obtaining the image comparison result between the verification image and the target image includes: obtaining the verification pixel value corresponding to each verification pixel in the verification image; performing binarization processing on the verification image according to the verification pixel value and binarization processing rules to obtain a verification binary image; arranging the pixel values in the verification binary image according to the position sorting rules to obtain a verification value sequence; obtaining the target pixel value corresponding to each target pixel in the target image; performing binarization processing on the target image according to the target pixel value and binarization processing rules to obtain a target binary image; arranging the pixel values in the target binary image according to the position sorting rules to obtain a target value sequence; determining the sequence distance between the verification value sequence and the target value sequence; and determining that the image comparison result is dissimilar when the sequence distance is greater than a distance threshold.
[0119] In this context, the check pixel is a pixel in the check image, and the check pixel value is the corresponding pixel value. The target pixel is a pixel in the target image, and the target pixel value is the corresponding pixel value. The position sorting rule is a pre-defined pixel position arrangement order. The binarization processing rule is a pre-defined rule for binarizing the image. There may be one or more binarization processing rules.
[0120] Specifically, after obtaining the verification pixel values corresponding to each verification pixel in the verification image, the terminal can perform grayscale processing on the verification pixel values to obtain a grayscale image corresponding to the verification image. According to the binarization processing rules, the grayscale image is binarized to obtain a binary image corresponding to the verification image, i.e., the verification binary image. The pixel values in the verification binary image are arranged according to the position sorting rules to obtain the verification value sequence. For example, suppose the verification image has three rows of pixels. The pixel values of the first row are x1, x2, ..., xn from left to right; the pixel values of the second row are y1, y2, ..., yn from left to right; and the pixel values of the third row are z1, z2, ..., zn from left to right. The position sorting rule is that the pixels of the first row are arranged from left to right, then the pixels of the second row are arranged from left to right, and finally the pixels of the third row are arranged from left to right. The verification value sequence obtained according to this position sorting rule is x1, x2, ..., xn, y1, y2, ..., yn, z1, z2, ..., zn.
[0121] Binarization refers to the process of obtaining a binary image. A binary image contains only two pixel values: 0 and 1. The number of pixels in the binary image can be the same as or different from the number of pixels in the image before binarization. The terminal can use one or more methods for binarization. For example, after obtaining a grayscale image, the average pixel value can be calculated. Each pixel in the grayscale image is compared to the average pixel value; pixels with values greater than the average are set to 1, and pixels with values less than the average are set to 0. Alternatively, after obtaining a grayscale image, the difference between adjacent pixels can be calculated. If the value of the preceding pixel is greater than the value of the following pixel, the pixel value is "1"; otherwise, it is "0".
[0122] Furthermore, the terminal obtains the target pixel value corresponding to each target pixel in the target image, performs binarization processing on the verification image according to the target pixel value and the same binarization processing rule as the verification image, and obtains the verification binary image. Then, the pixel values in the target binary image are arranged according to the same position sorting rule as the verification image to obtain the target value sequence.
[0123] After obtaining the check value sequence and the target value sequence, the sequence distance between them is determined. This sequence distance characterizes the similarity between the two binary sequences; the smaller the distance, the higher the similarity, and vice versa. When the sequence distance is greater than a distance threshold, the image comparison result is determined to be dissimilar; conversely, when the sequence distance is less than the distance threshold, the image comparison result is determined to be similar. Specifically, the sequence distance can be the Hamming distance.
[0124] It is understandable that when the binarization processing rules include multiple different rules, the sequence distance is determined by the sequence distance between the check value sequence and the target value sequence based on the same binarization processing rule. Finally, the sequence distances corresponding to each binarization processing rule are counted to obtain the final sequence distance. The count can be a summation or an average.
[0125] In some embodiments, to reduce computational load, a smaller size, such as 8*8, can be set in the binarization processing rule. During the binarization process, the verification image or target image is first reduced to this size, and then the binary pixels are determined.
[0126] In the above embodiments, the comparison is performed by calculating the verification value sequence and the target value sequence and calculating the sequence distance. Since the calculation process is simple, the image comparison efficiency is high.
[0127] In some embodiments, obtaining the image comparison result between the verification image and the target image includes: when the sequence distance is less than a distance threshold, calculating the color channel pixel difference between the verification image and the target image at each pixel position; determining the pixel color similarity corresponding to the pixel position based on the color channel pixel difference; calculating the color similarity at the pixel position to obtain the image color similarity between the verification image and the target image; when the image color similarity is less than a similarity threshold, determining that the image comparison result is dissimilar.
[0128] When the sequence distance is less than a distance threshold, it can be preliminarily determined that the test image and the target image are similar. In this embodiment, to improve the accuracy of comparison, the color similarity between the test image and the target image can be further calculated. Specifically, for each pixel position, the terminal calculates the R (Red), G (Green), and B (Blue) pixel differences between the test image and the target image at that pixel position. The R (Red), G (Green), and B (Blue) pixel differences are summed to obtain the color channel pixel difference at that pixel position. The pixel color similarity corresponding to that pixel position is determined based on the color channel pixel difference. Pixel color similarity is negatively correlated with the color channel pixel difference; that is, the larger the color channel pixel difference, the smaller the pixel color similarity, and vice versa.
[0129] Finally, the color similarity of all pixel positions is calculated to obtain the image color similarity between the verification image and the target image. When the image color similarity is less than the similarity threshold, the image comparison result is determined to be dissimilar; when the image color similarity is greater than the similarity threshold, the image comparison result is determined to be similar. The calculation can be summation, averaging, or median, etc. The similarity threshold can be set as needed.
[0130] In some embodiments, such as Figure 5 As shown, an image processing method is provided, including the following steps:
[0131] Step 502: Obtain the background image and target image corresponding to the image background addition function.
[0132] Step 504: Add target image boundaries to the image edges corresponding to the target image to obtain the intermediate image.
[0133] Step 506: Use the image background addition function to composite the intermediate image and the background image to obtain the composite image.
[0134] Step 508: Obtain the first dimension size of each spatial dimension of the synthesized image in multiple spatial dimensions, and calculate the first dimension ratio between spatial dimensions based on the first dimension size.
[0135] Step 510: Obtain the second dimension size of the background image in each of the multiple spatial dimensions, and calculate the second dimension ratio between the spatial dimensions based on the second dimension size.
[0136] Here, "multiple spatial dimensions" refers to at least two spatial dimensions. Taking a two-dimensional image as an example, the spatial dimensions include two dimensions: one parallel to the X-axis and the other parallel to the Y-axis.
[0137] In some embodiments, both the composite image and the background image are two-dimensional images. The first dimension is the width and height of the composite image, and the first aspect ratio is the ratio between the width and height of the composite image. The second dimension is the width and height of the background image, and the second aspect ratio is the ratio between the width and height of the background image. Components at the same position in the first and second aspect ratios correspond to the same spatial dimension. For example, if the width of the composite image is a1 and the height is b1, and the width of the verification image is a2 and the height is b2, then the first aspect ratio is a1 / b1 and the second aspect ratio is a2 / b2, or the first aspect ratio is b1 / a1 and the second aspect ratio is b2 / a2.
[0138] Step 512: Determine whether the first size ratio corresponds to the second size ratio. If yes, proceed to step 516; otherwise, proceed to step 514.
[0139] In some embodiments, the correspondence between the first size ratio and the second size ratio means that the difference between the first size ratio and the second size ratio is 0.
[0140] Step 514: Determine that the verification result corresponding to the image background addition function is a verification error.
[0141] Step 516: Determine the boundary position of the target image in the synthesized image based on the boundary features of the target image boundary.
[0142] Step 518: Extract the image corresponding to the target image from the synthetic image based on the boundary location, and use it as the verification image.
[0143] Step 520: Obtain the image comparison result between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison result.
[0144] In some embodiments, after determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary, the terminal can determine the center point position of the verification image based on the boundary position. When the center position is the same as the preset center position, the terminal proceeds to step 518 above; otherwise, the verification result corresponding to the image background addition function is determined to be a verification error.
[0145] In some embodiments, after determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary, the terminal can determine the size of the verification image in each spatial dimension based on the boundary position, calculate the size ratio between the spatial dimensions corresponding to the verification image, and when the size ratio corresponds to the size ratio between the spatial dimensions corresponding to the target image, proceed to step 518 above; otherwise, determine that the verification result corresponding to the image background addition function is a verification error.
[0146] In some embodiments, after the terminal determines the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary, it can determine the size of the verification image in any spatial dimension based on the boundary position, calculate the ratio of the size to the size of the target image in the same spatial dimension, and when the ratio corresponds to the image adjustment ratio set during synthesis, proceed to step 518 above; otherwise, determine that the verification result corresponding to the image background addition function is a verification error.
[0147] In the above embodiments, since the process of determining whether the proportion and position correspond is simple, cases where the proportion and position do not correspond can be quickly eliminated. Only when the proportion and position correspond will the image comparison process be entered; otherwise, the verification result corresponding to the image background addition function can be directly determined as a verification error, thereby improving verification efficiency.
[0148] In some embodiments, the method further includes: setting the pixel values of the region corresponding to the boundary position in the synthesized image to mask pixel values to obtain a first masked image, and setting the pixel values of the region corresponding to the boundary position in the background image to mask pixel values to obtain a second masked image; comparing the first masked image and the second masked image to obtain a masking comparison result, and determining the verification result corresponding to the image background addition function based on the masking comparison result.
[0149] The masked pixel value is used to replace the pixel value at the original position. It can be any specified pixel value, for example, the masked pixel value can be 0. The region corresponding to the boundary position refers to the closed region surrounded by all boundaries.
[0150] Specifically, after obtaining the boundary position, the terminal replaces the pixels in the region corresponding to the boundary position in the synthesized image with the masked pixel value to obtain the first masked pixel. Then, it replaces the region in the background image corresponding to the boundary position with the same masked pixel value to obtain the second masked image. Under normal background addition functionality, the first and second masked images should correspond. The terminal can then compare the first and second masked images, and the comparison result is the masking comparison result. Based on the masking comparison result, the verification result corresponding to the background addition function is determined. The specific comparison method can be found in the description of the above embodiments, and will not be repeated here. The correspondence between the first and second masked images means that the first and second masked images are the same or similar.
[0151] In some embodiments, the terminal may determine the final verification result by combining the verification result obtained from the image comparison between the verification image and the target image, and the verification result obtained from the masking comparison between the first masking image and the second masking image. Specifically, the verification result is determined to be correct only when both verification results are correct; otherwise, it is determined to be incorrect.
[0152] In the above embodiments, by comparing the first masking image and the second masking image, a masking comparison result is obtained. Based on the masking comparison result, the verification result corresponding to the image background addition function is determined. Since the results are compared in multiple ways, the verification accuracy can be improved.
[0153] In some embodiments, the method further includes: obtaining a sliding window; the sliding window and the target image have the same size in the image region corresponding to the composite image; sliding the sliding window on the composite image in pixels as the sliding unit, and taking the image region in the sliding window as a candidate image block; obtaining the target comparison result between the candidate image block and the target image, and determining the verification result corresponding to the image background addition function based on the target comparison result.
[0154] Specifically, as the sliding window slides across the composite image, it moves one pixel at a time until all pixels in the composite image have been traversed. The image regions within the sliding window are then used as candidate image blocks, resulting in multiple candidate image blocks. When the image background addition function works correctly, one of these candidate image blocks will inevitably correspond to the target image. The terminal can then compare each candidate image block with the target image, and the comparison result is the target comparison result. Further, based on the target comparison result, the verification result corresponding to the image background addition function is determined. Specific comparison methods can be found in the description of the embodiments above, and will not be repeated here. The correspondence between a candidate image block and the target image means that the candidate image block is the same as or similar to the target image.
[0155] In some embodiments, the terminal may determine the final verification result by combining the verification result obtained from the image comparison between the verification image and the target image, and the verification result obtained from the target comparison between the candidate image block and the target image. Specifically, the verification result is determined to be correct only when both verification results are correct; otherwise, it is determined to be incorrect.
[0156] In the above embodiments, candidate image blocks are obtained by acquiring all regions in the synthesized image that are the same size as the target image through a sliding window. The candidate image blocks are compared with the image to obtain the target comparison result. The verification result corresponding to the image background addition function is determined based on the masking comparison result. Since the results are compared in multiple ways, the verification accuracy can be improved.
[0157] This application also provides an application scenario where the image processing method described above is applied. A video editing client is installed on the terminal. This client can automatically verify the background addition function to determine if it is functioning correctly. In this application scenario, the background addition function is used to add a background image (hereinafter referred to as the frame background) to a video. The frame backgrounds added to each frame of the video can be the same or different. The frame backgrounds corresponding to each video frame are arranged in the chronological order of the corresponding video frames to form the frame background video. When the frame backgrounds added to each frame of the video are the same, it is equivalent to adding a static background to the video; when the frame backgrounds added to each frame of the video are different, it is equivalent to adding a dynamic background to the video.
[0158] Specifically, the image processing method is applied in this application scenario as follows:
[0159] 1. Obtain the target video V t Its frame rate f = 30, and it is preprocessed to obtain video V. t The preprocessing operation is as follows: Add a 5-width "recognition edge" (i.e., the target image boundary) of alternating pure black (0,0,0) and pure white (255,255,255) blocks to the four sides of each frame of the video. Here, let the total number of pure black and pure white blocks on each side be L = 10. The video V... t Video V with added "recognition edges" t 'The results can be referenced' Figure 4 .
[0160] 2. Assume there are N different aspect ratio backgrounds. The i-th aspect ratio background is automatically and randomly selected, and the video V is automatically and randomly selected. t 'Shrink to m times the original size, and automatically convert the video V' tThe position is moved to the selected background frame, centered at (x0, y0), and the background frame ratio is automatically selected as a:b (a:b can be 9:16, 3:4, 1:1, 4:3, 16:9, etc.). It's worth noting that although the above process is random, the values of i, m, and (x0, y0) are known. Subsequent automated calculations are needed to determine if the addition is correct, i.e., whether the effect and function are normal. Background Frame and Video V t The synthesized video is called V. m The effect is as follows Figure 6 As shown.
[0161] 3. After obtaining the image background and video V t 'Synthesized video V' m Then, first determine the video V. m Does it match the expected aspect ratio of a:b? (Get video V) m The width is w m The height is h m According to the following formula (1):
[0162]
[0163] If equation (1) is satisfied, then the video V m The expected aspect ratio of the background is a:b; otherwise, it indicates an error in adding the background, the process will terminate, and an error will be thrown.
[0164] 4. From the synthesized video V m Take any frame from the video for automated calculation, and use the first recognized edge found from top to bottom in that frame as video V. t 'At the top boundary of the background, record row number x' up If the background is not found even after iterating to the last row, it indicates an error in adding the image background, the process terminates, and an error is thrown. Similarly, the row number x of the lower boundary can be obtained from bottom to top. down The column number y of the left boundary is obtained from left to right. left The column number y of the right boundary is obtained from right to left. right .
[0165] Taking the determination of the topmost "identification edge" as an example, we scan line by line from top to bottom, performing the following steps in each line. A line of pixels is actually an array containing (R, G, B) values:
[0166] 1) Set a "color transformation count" p = 0. The current color u is identified starting from the first pixel. When pure white (255,255,255) or pure black (0,0,0) is identified for the first time, the transformation count p is incremented by 1, and the current color u is assigned the value of (0,0,0) or (255,255,255).
[0167] 2) Then iterate through the colors in sequence. When a color that is different from the current color u is found (i.e., the current color u = (0,0,0) and the color (255,255,255) is found, or the current color u = (255,255,255) and the color (0,0,0) is found), the number of transformations p is incremented by 1, and the current color u is assigned the color that is different from the previous color.
[0168] 3) If the number of transformations during the period is p = L = 10, it means that the "identification edge" has been identified, and then stop.
[0169] 4) If the number of transformations p for the last pixel has not reached the value L, then this array is not considered a "recognition edge".
[0170] 5. Based on x obtained in step 3 up x down y left y right Based on the following formulas (2) and (3), we can automatically calculate whether the automatic movement of the video V_t' to the center position (x0, y0) is correct:
[0171]
[0172]
[0173] Here we take k x =0%, k y =0% (the specific value can be changed according to the actual scenario). If formulas (2) and (3) are satisfied, it means that the automation will video V t If the position of ' is moved to the center position (x0, y0) and it works correctly, then the process will terminate and an error will be thrown.
[0174] 6. Assume video V t The width is w t The height is h t The expected scaled-down video V t The proportion of the image in the background should remain unchanged, according to the following formula (4):
[0175]
[0176] If formula (4) holds true, then the scaled video Vt 'The proportion of the image within the background remains unchanged; otherwise, it indicates an error in adding the background, terminate the process, and throw an error.'
[0177] 7. From the steps above, we can see that the scaled video V t The proportion of the image in the background remains unchanged, according to the following formula (5):
[0178]
[0179] If formula (5) is satisfied, the scaling ratio is confirmed to be effective and the function is normal; otherwise, it indicates that the addition of the image frame background is abnormal, the process is terminated, and an error is thrown.
[0180] 8. Determine video V t Whether the image in the background is correct does not need to be calculated for every single frame; it can be calculated every t interval. s Extract one frame for subsequent content calculations. Assume a composite video V is extracted at a certain time t0. m The content, based on the x obtained from the above steps. up x down y left y right The rectangle is used to extract the content, such as... Figure 7 As shown, the video V corresponding to time t0 is then calculated using the following formula (6). t Take the Fth frame and then extract the video V. t The Fth frame, compared with video V m Compare the two frames to the F-th frame. Figure 1 If they match, proceed to the next step; if they do not match, it indicates an error in adding the background, the process is terminated, and an error is thrown.
[0181]
[0182] Assuming the two images to be compared are Figure A and Figure B, the specific comparison method is as follows:
[0183] 1) Assume that the width and height of Figure A are w and w respectively. A h A The width and height of Figure B are w and w respectively. B h B Definition formula (7):
[0184]
[0185] Where k w / h We take the value as 99%. If the formula (7) is satisfied, then we confirm that the aspect ratios of Figure A and Figure B are consistent and proceed to the next step. Otherwise, we consider that Figure A and Figure B are inconsistent.
[0186] 2) Define the following formulas (8) and (9):
[0187] w min =min(w A ,w B (8)
[0188] h min =min(h) A ,h B (9)
[0189] Based on formulas (8) and (9), the smaller values for width and height were obtained. Then, through scaling operations, the dimensions of both images were scaled down to (w). min h min The width and height of the image are the same as those of the image A and the image B, which are scaled down to the same pixel size. The scaled images are called image A' and image B'.
[0190] 3) Perform a coarse comparison, that is, find the perceptual hash algorithm binary sequence of Figure A' as pHash(A') (this sequence has 8*8=64 binary bits), the mean hash algorithm binary sequence of Figure A' as aHash(A') (this sequence has 8*8=64 binary bits), and the difference hash algorithm binary sequence of Figure A' as dHash(A') (this sequence has 8*9=72 binary bits). Similarly, the relevant binary sequences of Figure B' as pHash(B'), aHash(B'), and dHash(B') can be obtained. Then define formula (10):
[0191]
[0192] in k represents the Hamming distance between two binary sequences. h Take 1 (the value here can vary depending on the specific scenario). If the formula (10) is satisfied, we consider the two images to be consistent in rough comparison and proceed to the next step. Otherwise, we consider the two images to be inconsistent.
[0193] 4) Conduct a detailed comparison. Having passed step 3, it can be determined that the shapes (textures, etc.) of the two images are basically identical. The next step is to carefully determine whether the image similarity between the two images is consistent. Define the pixel values R, G, and B at coordinates (x, y) of image A' as follows: Similarly, the pixel values R, G, and B of image B' at coordinates (x, y) are respectively Define the following formula (11):
[0194]
[0195] That is, C (x,y)Let the color similarity between two pixels be (i.e., the pixel color similarity mentioned above). Perform a pixel traversal row by row and column by column on both images A' and B', and calculate the average color similarity using formula (12). Use the average color similarity as the image color similarity.
[0196]
[0197] After obtaining the image color similarity using equation (11), according to formula (13):
[0198]
[0199] Where k c If 99% is taken (the specific value can be changed according to the actual scenario), and the two images satisfy formula (13), then the color similarity of the two images is considered to be consistent. That is, combined with the fact that the shapes and colors of the two images are consistent in step 3, the two images are considered to be consistent. Figure 1 If they match, then the two figures are considered inconsistent.
[0200] 9. Given that the automatically added background is the i-th background with an aspect ratio of a:b, the terminal can obtain the background video without added effects from the server, which is called V. h (V h (It can be dynamic or static), similar to the previous steps, extract the video V through t0. h After a certain frame, it is based on the x obtained in step three. up x down y left y right The rectangle is set to all black (0,0,0) (that is, the pixel values of the area corresponding to the target boundary are set to masked pixel values). This frame is called P. h ,like Figure 8 As shown.
[0201] Then extract video V m The Fth frame will also be based on x obtained in step three. up x down y left y right The rectangle that is set to all black (0,0,0) is called P. m , will P h With P m By comparing using the same method as the steps described above, if the two... Figure 1 If they match, proceed to the next step; if they do not match, it indicates an error in adding the background, the process is terminated, and an error is thrown.
[0202] 10. If based on interval t s If each extracted frame is consistent in steps 8 and 9, then the background of the frame and the video V are confirmed to be consistent.t 'Synthesized video V' m The aspect ratio and content are normal; the video is V. t The scaling ratio m is normal, and the scaled video V is normal. t The proportions of the background are normal, video V t 'The position within the background of the image is normal, etc., and the automatic calculation has passed.'
[0203] It should be understood that, although Figure 2 , Figure 5 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figure 2 , Figure 5 At least some of the steps in the process may include multiple steps or multiple stages. These steps or stages are not necessarily completed at the same time, but may be executed at different times. The execution order of these steps or stages is not necessarily sequential, but may be executed in turn or alternately with other steps or at least some of the steps or stages in other steps.
[0204] In some embodiments, such as Figure 9 As shown, an image processing apparatus 900 is provided. This apparatus can be a software module, a hardware module, or a combination of both, integrated into a computer device. Specifically, the apparatus includes:
[0205] The acquisition module 902 is used to acquire the background image and target image corresponding to the image background addition function;
[0206] Add module 904 to add target image boundaries to the image edges corresponding to the target image to obtain an intermediate image;
[0207] Module 906 is invoked to call the image background addition function to composite the intermediate image and the background image to obtain a composite image;
[0208] The determination module 908 is used to determine the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary;
[0209] Extraction module 910 is used to extract an image corresponding to the target image from the synthetic image based on the boundary position, as a verification image;
[0210] The comparison module 912 is used to obtain the image comparison result between the verification image and the target image, and to determine the verification result corresponding to the image background addition function based on the image comparison result.
[0211] In some embodiments, the adding module is further configured to determine the image edge corresponding to the target image; along the image edge, add corresponding boundary pixels outside the image edge to form the target image boundary, thereby obtaining an intermediate image.
[0212] In some embodiments, the determining module is used to determine the target scanning direction, which is the direction perpendicular to the edge direction corresponding to the image edge of the target image in the synthesized image; the synthesized image is scanned according to the target scanning direction, and when a set of pixels that conforms to the boundary features of the target image boundary is scanned, the boundary position of the target image boundary in the synthesized image is determined according to the position of the pixel set.
[0213] In some embodiments, the determining module is further configured to obtain the rotation angle and rotation direction corresponding to the intermediate image when compositing the intermediate image and the background image; determine the edge direction corresponding to the image edge of the target image in the composite image based on the rotation angle and rotation direction, and use it as the reference edge direction; and use the direction perpendicular to the reference edge direction as the target scanning direction.
[0214] In some embodiments, the determining module is further configured to scan the composite image according to the target scanning direction and in units of pixel arrangement units corresponding to the target scanning direction; when the pixel features of the current pixel arrangement unit scanned correspond to the boundary features of the target image boundary, the boundary position of the target image boundary in the composite image is determined according to the position of the current pixel arrangement unit.
[0215] In some embodiments, the boundary features of the target image boundary include multiple target color blocks arranged at intervals; the determining module is further configured to count the number of color block transformations between adjacent target color blocks in the current pixel arrangement unit; when the counted number of color block transformations is consistent with the number of color block transformations corresponding to the boundary features, the pixel features of the scanned current pixel arrangement unit are determined to correspond to the boundary features of the target image boundary, and the boundary position of the target image boundary in the synthesized image is determined according to the position of the current pixel arrangement unit.
[0216] In some embodiments, the comparison module is further configured to compare the size of the verification image with the size of the target image; when the size of the verification image and the size of the target image are inconsistent, obtain the target adjustment ratio, adjust the verification image and the target image to be the same size based on the target adjustment ratio; compare the verification image with the target image to obtain the image comparison result.
[0217] In some embodiments, the comparison module is further configured to, when the size of the verification image is inconsistent with the size of the target image, determine the smaller size value and the larger size value of the image size of the verification image and the image size of the target image; take the image corresponding to the larger size value as the target adjustment image, take the ratio of the smaller size value to the larger size value as the target adjustment ratio; and adjust the target adjustment image proportionally according to the target adjustment ratio so that the verification image and the target image are adjusted to be the same size.
[0218] In some embodiments, the comparison module is further configured to: obtain the verification pixel value corresponding to each verification pixel in the verification image; perform binarization processing on the verification image according to the verification pixel value and binarization processing rules to obtain a verification binary image; arrange the pixel values in the verification binary image according to the position sorting rules to obtain a verification value sequence; obtain the target pixel value corresponding to each target pixel in the target image; perform binarization processing on the target image according to the target pixel value and binarization processing rules to obtain a target binary image; arrange the pixel values in the target binary image according to the position sorting rules to obtain a target value sequence; determine the sequence distance between the verification value sequence and the target value sequence; and determine that the image comparison result is dissimilar when the sequence distance is greater than a distance threshold.
[0219] In some embodiments, the comparison module is further configured to: calculate the color channel pixel difference between the verification image and the target image at each pixel position when the sequence distance is less than a distance threshold; determine the pixel color similarity corresponding to the pixel position based on the color channel pixel difference; calculate the color similarity of the pixel position to obtain the image color similarity between the verification image and the target image; and determine that the image comparison result is dissimilar when the image color similarity is less than a similarity threshold.
[0220] In some embodiments, the above apparatus further includes: a size comparison module, configured to acquire the first dimension size of the synthesized image in each of multiple spatial dimensions, and calculate a first size ratio between spatial dimensions based on the first dimension size; acquire the second dimension size of the background image in each of multiple spatial dimensions, and calculate a second size ratio between spatial dimensions based on the second dimension size; when the first size ratio corresponds to the second size ratio, proceed to the step of determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary; otherwise, determine that the verification result corresponding to the image background addition function is a verification error.
[0221] In some embodiments, the above apparatus further includes: a background comparison module sets the pixel values of the region corresponding to the boundary position in the synthesized image to mask pixel values to obtain a first masked image, and sets the pixel values of the region corresponding to the boundary position in the background image to mask pixel values to obtain a second masked image; the first masked image and the second masked image are compared to obtain a masking comparison result, and the verification result corresponding to the image background addition function is determined based on the masking comparison result.
[0222] In some embodiments, the above apparatus further includes: a sliding comparison module, configured to acquire a sliding window; the sliding window and the target image have the same size in the image region corresponding to the composite image; slide the sliding window on the composite image in pixels as the sliding unit, and take the image region within the sliding window as a candidate image block; acquire the target comparison result between the candidate image block and the target image, and determine the verification result corresponding to the image background addition function based on the target comparison result.
[0223] In some embodiments, the comparison module is further configured to output a function error message corresponding to the image background addition function when the image comparison result is dissimilar, and to start a function repair task corresponding to the image background addition function.
[0224] In the aforementioned image processing device, on the one hand, a composite image is obtained by calling the image background addition function, and an image corresponding to the target image is extracted from the composite image as a verification image. The image comparison result between the verification image and the target image is obtained, and the verification result corresponding to the image background addition function is determined based on the image comparison result. This realizes automated verification of the image background addition function and improves verification efficiency. On the other hand, since the target image boundary is added to the image edge corresponding to the target image before synthesis to obtain an intermediate image, when the image background addition function is called for synthesis, the intermediate image and the background image are synthesized to obtain a composite image. When extracting the image, the target image boundary is extracted based on the boundary position of the composite image, and the verification image can be accurately extracted. Therefore, when the image background addition function is verified based on the verification image, the verification accuracy can be improved.
[0225] For specific limitations regarding the image processing apparatus, please refer to the limitations on the image processing method above, which will not be repeated here. Each module in the aforementioned image processing apparatus can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in hardware or independently of the processor in the computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the operations corresponding to each module.
[0226] In some embodiments, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 10As shown, the computer device includes a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. When the computer program is executed by the processor, it implements an image processing method. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad located on the computer device's casing, or an external keyboard, touchpad, or mouse.
[0227] Those skilled in the art will understand that Figure 10 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0228] In some embodiments, a computer device is also provided, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps in the above method embodiments.
[0229] In some embodiments, a computer-readable storage medium is provided storing a computer program that, when executed by a processor, implements the steps in the above method embodiments.
[0230] In some embodiments, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and executes the computer instructions, causing the computer device to perform the steps in the above-described method embodiments.
[0231] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium, and when executed, it can include the processes of the embodiments of the methods described above. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, or optical storage, etc. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0232] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0233] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are relatively specific and detailed, they should not be construed as limiting the scope of the invention patent. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this patent application should be determined by the appended claims.
Claims
1. An image processing method, characterized in that, The method includes: Get the background image and target image corresponding to the image background addition function; Add a target image boundary to the image edge corresponding to the target image to obtain an intermediate image; The image background addition function is invoked to synthesize the intermediate image and the background image to obtain a composite image; The boundary position of the target image boundary in the synthesized image is determined based on the boundary features of the target image boundary; Based on the boundary position, an image corresponding to the target image is extracted from the synthetic image and used as a verification image; Obtain the image comparison result between the verification image and the target image, and determine the verification result corresponding to the image background addition function based on the image comparison result.
2. The method according to claim 1, characterized in that, Adding a target image boundary to the image edge corresponding to the target image to obtain an intermediate image includes: Determine the image edges corresponding to the target image; Along the image edge, corresponding boundary pixels are added outside the image edge to form the target image boundary, resulting in an intermediate image.
3. The method according to claim 1, characterized in that, Determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary includes: The target scanning direction is determined, wherein the target scanning direction is the direction perpendicular to the edge direction corresponding to the image edge of the target image in the synthesized image; The synthesized image is scanned according to the target scanning direction. When a set of pixels that conforms to the boundary features of the target image boundary is scanned, the boundary position of the target image boundary in the synthesized image is determined according to the position of the pixel set.
4. The method according to claim 3, characterized in that, The determination of the target scanning direction includes: When combining the intermediate image and the background image, obtain the rotation angle and rotation direction corresponding to the intermediate image; The edge direction corresponding to the image edge of the target image in the synthesized image is determined based on the rotation angle and rotation direction, and is used as the reference edge direction; The direction perpendicular to the direction of the reference edge is taken as the target scanning direction.
5. The method according to claim 3, characterized in that, The step of scanning the synthesized image according to the target scanning direction, and when a set of pixels that conforms to the boundary features of the target image boundary is scanned, determining the boundary position of the target image boundary in the synthesized image based on the location of the pixel set includes: The synthesized image is scanned according to the target scanning direction and in units of pixel arrangement units corresponding to the target scanning direction; When the pixel features of the current pixel arrangement unit scanned correspond to the boundary features of the target image boundary, the boundary position of the target image boundary in the synthesized image is determined according to the position of the current pixel arrangement unit.
6. The method according to claim 4, characterized in that, The boundary features of the target image boundary include multiple target color blocks arranged at intervals; when the pixel features of the scanned current pixel arrangement unit correspond to the boundary features of the target image boundary, determining the boundary position of the target image boundary in the synthesized image based on the position of the current pixel arrangement unit includes: In the current pixel arrangement unit, the number of color block transformations between adjacent target color blocks is counted; When the number of color block transformations obtained by statistics is consistent with the number of color block transformations corresponding to the boundary features, it is determined that the pixel features of the current pixel arrangement unit scanned correspond to the boundary features of the target image boundary, and the boundary position of the target image boundary in the synthesized image is determined according to the position of the current pixel arrangement unit.
7. The method according to claim 1, characterized in that, The step of obtaining the image comparison result between the verification image and the target image includes: The dimensions of the verification image are compared with the dimensions of the target image; When the size of the verification image and the size of the target image are inconsistent, a target adjustment ratio is obtained, and the verification image and the target image are adjusted to be the same size based on the target adjustment ratio; The verification image and the target image, which are of the same size, are compared to obtain the image comparison result.
8. The method according to claim 7, characterized in that, When the size of the verification image and the size of the target image are inconsistent, obtaining a target adjustment ratio and adjusting the verification image and the target image to be the same size based on the target adjustment ratio includes: When the size of the verification image is inconsistent with the size of the target image, determine the smaller size value and the larger size value between the image size of the verification image and the image size of the target image; The image corresponding to the larger size value is used as the target adjustment image, and the ratio of the smaller size value to the larger size value is used as the target adjustment ratio; The target image is proportionally adjusted according to the target adjustment ratio to make the verification image and the target image the same size.
9. The method according to claim 1, characterized in that, The step of obtaining the image comparison result between the verification image and the target image includes: Obtain the verification pixel value corresponding to each verification pixel in the verification image, perform binarization processing on the verification image according to the verification pixel value and binarization processing rules to obtain a verification binary image, and arrange the pixel values in the verification binary image according to the position sorting rules to obtain a verification value sequence; Obtain the target pixel value corresponding to each target pixel in the target image, perform binarization processing on the target image according to the target pixel value and the binarization processing rule to obtain a target binary image, and arrange the pixel values in the target binary image according to the position sorting rule to obtain a target value sequence; Determine the sequence distance between the check value sequence and the target value sequence; When the sequence distance is greater than the distance threshold, the image comparison result is determined to be dissimilar.
10. The method according to claim 9, characterized in that, The step of obtaining the image comparison result between the verification image and the target image includes: When the sequence distance is less than the distance threshold, the color channel pixel difference between the verification image and the target image at each pixel position is calculated; The pixel color similarity corresponding to the pixel position is determined based on the pixel difference of the color channel at the pixel position. The color similarity between the verification image and the target image is obtained by calculating the color similarity at the pixel locations. When the color similarity of the images is less than the similarity threshold, the image comparison result is determined to be dissimilar.
11. The method according to claim 1, characterized in that, The method further includes: Obtain the first dimension size of the synthesized image in each of multiple spatial dimensions, and calculate the first dimension ratio between the spatial dimensions based on the first dimension size; Obtain the second dimension size of the background image in each of multiple spatial dimensions, and calculate the second dimension ratio between the spatial dimensions based on the second dimension size; When the first size ratio corresponds to the second size ratio, the step of determining the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary is entered; otherwise, the verification result corresponding to the image background addition function is determined to be a verification error.
12. The method according to claim 1, characterized in that, The method further includes: The pixel values of the region corresponding to the boundary position in the synthesized image are set to the masked pixel values to obtain a first masked image, and the pixel values of the region corresponding to the boundary position in the background image are set to the masked pixel values to obtain a second masked image; The first masked image and the second masked image are compared to obtain a masking comparison result. Based on the masking comparison result, the verification result corresponding to the image background addition function is determined.
13. The method according to claim 1, characterized in that, The method further includes: Obtain a sliding window; the sliding window is the same size as the target image in the image region corresponding to the synthesized image; The sliding window is slid across the composite image in pixels, and the image region within the sliding window is used as a candidate image block. Obtain the target comparison result between the candidate image block and the target image, and determine the verification result corresponding to the image background addition function based on the target comparison result.
14. The method according to any one of claims 1 to 13, characterized in that, The verification result for determining the image background addition function based on the image comparison result includes: When the image comparison result is dissimilar, output the function error message corresponding to the image background addition function, and start the function repair task corresponding to the image background addition function.
15. An image processing apparatus, characterized in that, The device includes: The acquisition module is used to acquire the background image and target image corresponding to the image background addition function; An adding module is used to add target image boundaries to the image edges corresponding to the target image to obtain an intermediate image; The calling module is used to call the image background adding function to synthesize the intermediate image and the background image to obtain a composite image; The determining module is used to determine the boundary position of the target image boundary in the synthesized image based on the boundary features of the target image boundary; The extraction module is used to extract an image corresponding to the target image from the synthesized image based on the boundary position, as a verification image; The comparison module is used to obtain the image comparison result between the verification image and the target image, and to determine the verification result corresponding to the image background addition function based on the image comparison result.
16. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 14.
17. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 14.
Citation Information
Patent Citations
Image processing apparatus, image processing method, and storage medium
CN102609902A
Video image processing method and system
CN103024419A