Image processing method and electronic device
Through image processing methods, images, depth images and mask images are obtained, and preset templates and superpixel segmentation technology are used to solve the problem of inaccurate depth information in multi-portrait images, improve the effect of AR images, and avoid virtual image misalignment .
Patent Information
- Application Number
- CN202310983523.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-23
- Publication Date
- 2024-12-13
- Estimated Expiration
- 2043-03-23
AI Technical Summary
In augmented reality technology, due to inaccurate depth information during multi-portrait image processing, virtual images are misaligned, reducing the effect of AR images.
By acquiring images, depth images and mask images, determining pixel points using preset templates, and superpixel segmentation and depth information processing, a more accurate mask image is generated to avoid depth mean errors and improve the position accuracy of virtual images.
It improves the effect of AR images, avoids misalignment of virtual images, and enhances the fun and authenticity of the images.
Smart Images

Figure CN117173405B_ABST
Abstract
Description
[0001] This application is a divisional application of the Chinese patent application submitted to the State Intellectual Property Office on March 23, 2023, with application number 202310291200.6 and application name "Image Processing Method and Electronic Device". Technical Field
[0002] The present application relates to the field of data processing, and more specifically, to an image processing method and an electronic device. Background Art
[0003] Augmented Reality (AR) technology can present computer-generated virtual objects in real scenes to achieve the integration of virtual objects and real scenes. Generally, AR technology can be used to enhance the fun of shooting.
[0004] For example, the virtual image generated by AR technology is fused with the real portrait image obtained by actual photography to obtain an AR image with high interest. Alternatively, the virtual image generated by AR technology is fused with the real portrait video obtained by actual photography to obtain an AR video with high interest. For ease of understanding, the following is an example of generating an AR image. When fusing the virtual image with the real portrait, it is usually necessary to first determine the depth information of the portrait. When determining the depth information of the portrait, it is necessary to obtain a portrait semantic mask map, and determine the depth information of the portrait according to the mask in the portrait semantic mask map. However, in some possible cases, for example, there are multiple portraits in the image, and there are overlapping parts between the portraits. In this case, a mask in the obtained portrait semantic mask map includes multiple portraits, and the depth of the portrait in the mask is the average depth of the multiple portraits. In other words, the portrait depth obtained according to the portrait semantic mask map is inaccurate. In this case, the virtual image in the generated AR image is misplaced, which ultimately leads to a poor effect of the generated AR image.
[0005] Based on this, how to improve the effect of AR images in scenes with multiple people and virtual images has become an urgent problem to be solved. Summary of the invention
[0006] The present application provides an image processing method that can improve the effect of AR images in a scene where multiple people and virtual images are synthesized.
[0007] In a first aspect, an image processing method is provided, comprising:
[0008] Acquire a first image, a first depth image, and a first mask image, wherein the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image;
[0009] Determine a first pixel point in the first image using a first preset template, where the first pixel point is a pixel point in an image region of a first object, and the first preset template is associated with a first distance, where the first distance is a distance between the first object and the electronic device;
[0010] Performing superpixel segmentation on the first image to obtain multiple regions, wherein the multiple regions include a first region, and the first region includes a first pixel point;
[0011] Determine a first region set among the multiple regions based on the first depth information, where the first depth information is used to characterize the depth of the first region, a difference between the depth of each region in the first region set and the depth of the first region is less than a first threshold, and the first region set includes the first region;
[0012] Based on the first region set, a second mask image is obtained, where the second mask image is used to identify an image region of the first object in the first image;
[0013] An augmented reality (AR) image is obtained based on the second mask image and the first image.
[0014] The image processing method provided in the embodiment of the present application first obtains a first image, a first depth image and a first mask image, then uses a first preset template to determine a first pixel point in the first image, and simultaneously performs superpixel segmentation on the first image to obtain multiple regions, then determines a first region set among the multiple regions based on the first depth information, and then obtains a second mask image based on the first region set, and then obtains an augmented reality AR image based on the second mask image and the first image, wherein the first image includes an image region of a first object and an image region of a second object, the image region of the first object and the image region of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, the first mask image identifies the image region of the first object and the image region of the second object in the first image, the first pixel point is a pixel point in the image region of the first object, the first preset template is related to a first distance, and the first distance is a distance between the first object and the second object. The distance between electronic devices, multiple areas include a first area, the first area includes a first pixel point, the first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, the first area set includes the first area, and the second mask image is used to identify the image area of the first object in the first image. Since the first pixel point of the image area of the first object in the first image is first obtained through the first preset template, the first area set determined based on the depth of the first area where the first pixel point is located is the image area of the same object and does not include image areas of other objects. Therefore, the mask included in the second mask image obtained based on the first area set only indicates the image area of the first object alone, avoiding the situation where the depth of the first object is determined based on the depth average of at least two objects, improving the accuracy of the depth of the first object, avoiding the problem of misalignment of the virtual image in the generated AR image, and improving the effect of the generated AR image.
[0015] In combination with the first aspect, in an embodiment of the first aspect, if the first object and the second object are persons, the first preset template is a head outline template, and the first distance is inversely proportional to the area of the first preset template.
[0016] In combination with the first aspect, in an embodiment of the first aspect, the method further includes:
[0017] Obtaining the position and posture information of the electronic device;
[0018] Adjust the shape of the head contour template based on the pose information.
[0019] In an embodiment of the present application, the first preset template is adjusted according to the posture information of the electronic device to obtain an adjusted first preset template, so that the angle of the first preset template is close to the shooting angle of the first image, and the head contour of the adjusted first preset template and the portrait in the first image is more matched. Therefore, based on the adjusted first preset template, the first pixel point can be obtained more accurately, thereby improving the accuracy of the second mask image obtained based on the first pixel point, and improving the accuracy of the AR image obtained based on the second mask image and the first image.
[0020] In combination with the first aspect, in an embodiment of the first aspect, the method further includes:
[0021] Dividing each depth value in the first depth image into a plurality of depth intervals according to a preset interval range;
[0022] Determine a target depth interval having the largest number of pixels among the multiple depth intervals;
[0023] A first preset template is determined according to a depth range of the target depth interval.
[0024] In an embodiment of the present application, the first preset template is a head contour template related to the distance between the first object and the electronic device, that is, the first distance. The larger the first distance, the smaller the area of the head contour template, and the smaller the first distance, the larger the area of the head contour template. Therefore, directly selecting the corresponding first preset template based on the first distance can make the size of the first preset template more matched with the size of the first object, thereby improving the efficiency of determining the first pixel point based on the first preset template, and thereby improving the efficiency of determining the second mask image based on the first pixel point.
[0025] In combination with the first aspect, in an embodiment of the first aspect, the step of using the first preset template to determine the first pixel point in the first image includes:
[0026] Obtain an edge map corresponding to the first mask image, where the edge map is a binary map formed by the outline of the mask in the first mask image;
[0027] A convolution operation is performed on the first preset template and the edge map to obtain a first pixel point.
[0028] The edge image is a binary image formed by the contour of the mask in the first mask image. The first pixel point is a pixel point in the image area of the first object.
[0029] In combination with the first aspect, in an embodiment of the first aspect, the method further includes:
[0030] Obtaining a depth difference of the same mask mask in the first mask image;
[0031] If the depth difference is greater than a first preset threshold, it is determined that the first image includes the first object and the second object.
[0032] The image processing method provided in the embodiment of the present application obtains the depth difference of the same mask mask in the first mask image. If the depth difference is greater than the first preset threshold, it is determined that the first image includes the first object and the second object. This is equivalent to the process of determining whether the first image includes the first object and the second object at the same time. It is determined based on the depth difference of the same mask mask in the first mask image, which improves the intelligence of determining the existence of the first object and the second object in the first image.
[0033] In combination with the first aspect, in an embodiment of the first aspect, the method further includes:
[0034] Determine a second pixel point in the first image using a second preset template, where the second pixel point is a pixel point in an image region of a second object, and the second preset template is associated with a second distance, where the second distance is a distance between the second object and the electronic device;
[0035] The plurality of regions further include a second region, and the second region includes a second pixel point;
[0036] determining a second region set among the plurality of regions based on the second depth information, where the second depth information is used to characterize the depth of the second region, a difference between the depth of each region in the second region set and the depth of the second region is less than a second threshold, and the second region set includes the second region;
[0037] Based on the first region set, a second mask image is obtained, including:
[0038] A second mask image is obtained based on the first region set and the second region set.
[0039] The image processing method provided in the embodiment of the present application, after determining the first preset template according to the depth range of the target depth interval, further determines the second preset template of the second object, and then on the basis of using the first preset template to perform a convolution operation on the edge map, it can also use the second preset template to perform a convolution operation on the edge map to obtain a second pixel point in the image area of the second object, so that after super-pixel segmentation of the first image, the multiple areas obtained include the first area and the second area, and further, a mask of the first object is obtained based on the first area, and a mask of the second object is obtained based on the second area, so that the image areas of the first object and the second object are simultaneously identified in the second mask image, and then the AR image determined according to the second mask image and the first image, on the basis of generating the AR image based on the image area of the first object, can also simultaneously generate the AR image based on the image area of the second object, thereby further improving the display effect of the generated AR image.
[0040] In combination with the first aspect, in an embodiment of the first aspect, using a second preset template to determine a second pixel point in the first image includes:
[0041] Acquire an edge map corresponding to the first mask image, where the edge map is a binary map formed by the outline of the object in the first mask image;
[0042] A convolution operation is performed on the second preset template and the edge map to obtain a second pixel point.
[0043] In combination with the first aspect, in an embodiment of the first aspect, the first depth image is acquired by a camera device in the electronic device.
[0044] In the image processing method provided in the embodiment of the present application, the first depth image is acquired by a camera device (TOF) in the electronic device, which makes the method of acquiring the first depth image more convenient, thereby improving the efficiency of obtaining the AR image based on the first depth image, the first image and the first mask image.
[0045] In combination with the first aspect, in an embodiment of the first aspect, the first depth image is obtained by inputting the first image into a preset depth estimation model, and the depth estimation model is a neural network model.
[0046] In the image processing method provided in the embodiment of the present application, the first depth image is obtained by inputting the first image into a preset depth estimation model, wherein the preset depth estimation model is a neural network model. In this way, the electronic device can obtain the corresponding first depth image based on the first image and the preset depth estimation model even when TOF is not configured, thereby improving the convenience of obtaining the first depth image and reducing the cost of the electronic device.
[0047] In combination with the first aspect, in an embodiment of the first aspect, the first mask image is obtained by inputting the first image into a preset semantic segmentation model, and the semantic segmentation model is a neural network model.
[0048] In the image processing method provided in the embodiment of the present application, the first mask image is obtained by inputting the first image into a preset semantic segmentation model, wherein the preset semantic segmentation model is a neural network model, so that the electronic device can obtain the corresponding first mask image based on the first image and the preset semantic segmentation model, thereby improving the convenience and accuracy of obtaining the first mask image.
[0049] In a second aspect, an image processing device is provided, comprising a unit for executing any one of the methods in the first aspect. The device may be a server, a terminal device, or a chip in a terminal device. The device may include an input unit and a processing unit.
[0050] When the device is a terminal device, the processing unit may be a processor, and the input unit may be a communication interface; the terminal device may also include a memory, which is used to store computer program code. When the processor executes the computer program code stored in the memory, the terminal device executes any one of the methods in the first aspect.
[0051] When the device is a chip in a terminal device, the processing unit may be a processing unit inside the chip, and the input unit may be an output interface, a pin or a circuit, etc.; the chip may also include a memory, which may be a memory inside the chip (for example, a register, a cache, etc.) or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the methods in the first aspect.
[0052] In a possible implementation, a memory is used to store computer program codes; a processor executes the computer program codes stored in the memory, and when the computer program codes stored in the memory are executed, the processor is used to execute: acquiring a first image, a first depth image, and a first mask image, wherein the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image; using a first preset template to determine a first pixel in the first image point, the first pixel point is a pixel point in the image area of the first object, the first preset template is related to the first distance, and the first distance is the distance between the first object and the electronic device; superpixel segmentation is performed on the first image to obtain multiple areas, the multiple areas include the first area, and the first area includes the first pixel point; based on the first depth information, a first area set of the multiple areas is determined, the first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, and the first area set includes the first area; based on the first area set, a second mask image is obtained, and the second mask image is used to identify the image area of the first object in the first image; based on the second mask image and the first image, an augmented reality AR image is obtained.
[0053] According to a third aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program code. When the computer program code is executed by an image processing device, the image processing device executes any one of the image processing methods according to the first aspect.
[0054] In a fourth aspect, a computer program product is provided, the computer program product comprising: a computer program code, when the computer program code is executed by an image processing device, the image processing device executes any one of the device methods in the first aspect.
[0055] The image processing method and electronic device provided in the embodiments of the present application first acquire a first image, a first depth image, and a first mask image, then use a first preset template to determine a first pixel in the first image, and simultaneously perform superpixel segmentation on the first image to obtain multiple regions, then determine a first region set among the multiple regions based on the first depth information, and then obtain a second mask image based on the first region set, and then obtain an augmented reality AR image based on the second mask image and the first image, wherein the first image includes an image region of a first object and an image region of a second object, the image region of the first object and the image region of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, the first mask image identifies the image region of the first object and the image region of the second object in the first image, the first pixel is a pixel in the image region of the first object, the first preset template is related to the first distance, and the first distance is the first pair The distance between the image and the electronic device, the multiple areas include a first area, the first area includes a first pixel point, the first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, the first area set includes the first area, and the second mask image is used to identify the image area of the first object in the first image. Since the first pixel point of the image area of the first object in the first image is first obtained through the first preset template, the first area set determined based on the depth of the first area where the first pixel point is located is the image area of the same object and does not include image areas of other objects. Therefore, the mask included in the second mask image obtained based on the first area set only indicates the image area of the first object alone, avoiding the situation that the depth of the first object is determined based on the depth average of at least two objects, improving the accuracy of the depth of the first object, avoiding the problem of misalignment of the virtual image in the generated AR image, and improving the effect of the generated AR image. BRIEF DESCRIPTION OF THE DRAWINGS
[0056] Figure 1 It is a schematic diagram of an RGB image and a mask image;
[0057] Figure 2 This is a schematic diagram of a multi-person image generation AR image at this stage;
[0058] Figure 3 is a schematic diagram of a hardware system of an electronic device applicable to the present application;
[0059] Figure 4 is a schematic diagram of a software system for an electronic device applicable to the present application;
[0060] Figure 5 It is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0061] Figure 6 It is a flowchart of an image processing method provided in an embodiment of the present application;
[0062] Figure 7 is a schematic diagram of a process for obtaining a first depth image and a first mask image provided by an embodiment of the present application;
[0063] Figure 8 is a schematic diagram of a first mask image provided in an embodiment of the present application;
[0064] Fig. 9 is a schematic diagram of a head outline template provided in an embodiment of the present application;
[0065] Fig.10 is a schematic diagram of a first mask image and an edge map provided in an embodiment of the present application;
[0066] Fig.11 is a schematic diagram of performing convolution on an edge map using a first preset template provided in an embodiment of the present application;
[0067] Fig.12 The present application provides a schematic diagram of using first preset templates of different sizes to convolve an edge map;
[0068] Fig.13 is a schematic diagram of a first image for superpixel segmentation provided in an embodiment of the present application;
[0069] Fig.14 is a flowchart of another image processing method provided in an embodiment of the present application;
[0070] Fig.15 is a flowchart of another image processing method provided in an embodiment of the present application;
[0071] Fig.16 is a schematic diagram of an image processing device provided by the present application;
[0072] Fig.17 It is a schematic diagram of an electronic device for image processing provided by the present application. DETAILED DESCRIPTION
[0073] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0074] In the following, the terms "first", "second", and "third" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", and "third" may explicitly or implicitly include one or more of the features.
[0075] To facilitate understanding, some of the examples given are provided for reference to the description of concepts related to the embodiments of the present application.
[0076] 1. Depth map
[0077] A depth map is an image in which the distance from the image collector to each point in the image scene is taken as a pixel value.
[0078] 2. Mask
[0079] In the field of image processing, the area where the target object in the image is located is assigned a value, so that the area is assigned a different value from other areas in the image, so that the target object can be distinguished from other areas in the image, which is convenient for subsequent image rendering. Exemplarily, the area where the target image is located is assigned a value of 1, and other areas in the image are assigned a value of 0. The target object can refer to a person, an animal, a plant, a building, etc.
[0080] 3. Semantic Segmentation
[0081] Semantic segmentation is a method for separating the target object from other areas in an image. Unlike instance segmentation, semantic segmentation only distinguishes the target object from other areas. If there are multiple target objects, it cannot distinguish different objects.
[0082] For example, semantic segmentation can distinguish the human figure from other background areas in an image. Figure 1 As shown in (a) in the figure, the RGB image includes two people, namely portrait 1 and portrait 2. Through semantic segmentation, only the portrait and background areas can be distinguished, as shown in the following figure. Figure 1 The mask image shown in (b) in FIG. There is no obvious boundary between portrait 1 and portrait 2, so portrait 1 and portrait 2 cannot be distinguished.
[0083] It should be understood that semantic segmentation usually requires lower computing power, while instance segmentation requires higher computing power. Therefore, semantic segmentation is usually used when performing image processing in terminal devices with limited computing power such as mobile phones and tablets.
[0084] 4. Superpixel Segmentation
[0085] In the field of computer vision, superpixel segmentation refers to the process of subdividing a digital image into multiple image sub-regions (a collection of multiple pixels, also called superpixels). A superpixel is a small area composed of a series of pixels that are adjacent in position and have similar characteristics such as color, brightness, and texture. Most of these small areas retain effective information for further image segmentation and generally do not destroy the boundary information of objects in the image.
[0086] At present, when fusing a virtual image generated by AR technology with a real person, the depth of the virtual image in the image is usually determined based on the depth of the person, and then the virtual image is set at an appropriate depth so that the cartoon image and the person can be better integrated into the AR image. In one possible case, when an image includes multiple people, and there are overlapping areas between the multiple people. For example, Figure 2 As shown in (a) in the figure. The image includes two characters, character 1 and character 2, and there is an overlapping area between character 1 and character 2. The distance between character 1 and the camera is relatively close, and the distance between character 2 and the camera is relatively far, that is, the depth difference between character 1 and character 2 is relatively large. In the process of fusing the virtual image 3 into the image, it is usually necessary to first obtain the depth map of character 1 and character 2, and then obtain the average value of the depth between character 1 and character 2. In the process of setting the virtual image 3 as an AR image, it is necessary to refer to the above depth. Among them, in one possible case, the depth map obtained by the semantic segmentation method does not distinguish between character 1 and character 2, and the corresponding depth map is as follows Figure 2 As shown in (b) in the figure, characters are stuck together. As a result, the average depth between characters 1 and 2 is significantly different from the depths of characters 1 and 2, so virtual image 3 is easily misplaced, resulting in a poor effect of the final generated AR image. For example, the average depth of characters 1 and 2 is 2.55m, of which the real depth of character 1 is 2m and the real depth of character 2 is 3.1m. When the virtual image is placed at a depth of 2.6m, the virtual image will be misplaced, as shown in the figure below. Figure 2 In one possible case, the depth map is simply divided based on the edge of the person, as shown in (c). Figure 2 In this case, when the virtual image is set in the image, part of the character's torso will be blocked by the virtual image, resulting in a poor effect of the final generated AR image. Figure 2As shown in (e) in .
[0087] In view of this, an embodiment of the present application provides an image processing method, which first acquires a first image, a first depth image, and a first mask image, then uses a first preset template to determine a first pixel point in the first image, and simultaneously performs superpixel segmentation on the first image to obtain multiple regions, and then determines a first region set among the multiple regions based on the first depth information, and then obtains a second mask image based on the first region set, and then obtains an augmented reality AR image based on the second mask image and the first image, wherein the first image includes an image region of a first object and an image region of a second object, the image region of the first object and the image region of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, the first mask image identifies the image region of the first object and the image region of the second object in the first image, the first pixel point is a pixel point in the image region of the first object, the first preset template is related to a first distance, and the first distance is a first pair The distance between the image and the electronic device, the multiple areas include a first area, the first area includes a first pixel point, the first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, the first area set includes the first area, and the second mask image is used to identify the image area of the first object in the first image. Since the first pixel point of the image area of the first object in the first image is first obtained through the first preset template, the first area set determined based on the depth of the first area where the first pixel point is located is the image area of the same object and does not include image areas of other objects. Therefore, the mask included in the second mask image obtained based on the first area set only indicates the image area of the first object alone, avoiding the situation that the depth of the first object is determined based on the depth average of at least two objects, improving the accuracy of the depth of the first object, avoiding the problem of misalignment of the virtual image in the generated AR image, and improving the effect of the generated AR image.
[0088] The image processing method provided in the embodiment of the present application can be applied to electronic devices. Optionally, the electronic device includes a terminal device, which can also be called a terminal, a user equipment (UE), a mobile station (MS), a mobile terminal (MT), etc. The terminal device can be a mobile phone, a smart TV, a wearable device, a tablet computer (Pad), a computer with wireless transceiver function, a virtual reality (VR) terminal device, an augmented reality (AR) terminal device, a wireless terminal in industrial control, a wireless terminal in self-driving, a wireless terminal in remote medical surgery, a wireless terminal in smart grid, a wireless terminal in transportation safety, a wireless terminal in smart city, a wireless terminal in smart home, etc. The embodiment of the present application does not limit the specific technology and specific device form adopted by the terminal device.
[0089] For example, Figure 3 1 shows a schematic diagram of the structure of the electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0090] It is to be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.
[0091] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (AP), a modem processor, a graphics processor (GPU), an image signal processor (ISP), a controller, a memory, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.
[0092] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0093] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.
[0094] In some embodiments, the processor 110 may include one or more interfaces. The interface may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.
[0095] The I2C interface is a bidirectional synchronous serial bus, including a serial data line (SDA) and a serial clock line (SCL). In some embodiments, the processor 110 may include multiple groups of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces. For example: the processor 110 may be coupled to the touch sensor 180K through the I2C interface, so that the processor 110 communicates with the touch sensor 180K through the I2C bus interface, thereby realizing the touch function of the electronic device 100.
[0096] The UART interface is a universal serial data bus for asynchronous communication. The bus can be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, the UART interface is generally used to connect the processor 110 and the wireless communication module 160. For example, the processor 110 communicates with the Bluetooth module in the wireless communication module 160 through the UART interface to implement the Bluetooth function. In some embodiments, the audio module 170 can transmit an audio signal to the wireless communication module 160 through the UART interface to implement the function of playing music through a Bluetooth headset.
[0097] The MIPI interface can be used to connect the processor 110 with peripheral devices such as the display screen 194 and the camera 193. The MIPI interface includes a camera serial interface (CSI), a display serial interface (DSI), etc. In some embodiments, the processor 110 and the camera 193 communicate via the CSI interface to implement the shooting function of the electronic device 100. The processor 110 and the display screen 194 communicate via the DSI interface to implement the display function of the electronic device 100.
[0098] The GPIO interface can be configured by software. The GPIO interface can be configured as a control signal or as a data signal. In some embodiments, the GPIO interface can be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, etc. The GPIO interface can also be configured as an I2C interface, an I2S interface, a UART interface, a MIPI interface, etc.
[0099] It is understandable that the interface connection relationship between the modules illustrated in the embodiment of the present application is only a schematic illustration and does not constitute a structural limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
[0100] The electronic device 100 implements the display function through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, which connects the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or change display information.
[0101] The display screen 194 is used to display images, videos, etc. The display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode or an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), Miniled, MicroLed, Micro-oLed, a quantum dot light-emitting diode (QLED), etc. In some embodiments, the electronic device 100 may include 1 or N display screens 194, where N is a positive integer greater than 1.
[0102] The electronic device 100 can realize the shooting function through ISP, camera 193, video codec, GPU, display screen 194 and application processor.
[0103] ISP is used to process the data fed back by camera 193. For example, when taking a photo, the shutter is opened, and the light is transmitted to the camera photosensitive element through the lens. The light signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to ISP for processing and converts it into an image visible to the naked eye. ISP can also perform algorithm optimization on the noise, brightness, and skin color of the image. ISP can also optimize the exposure, color temperature and other parameters of the shooting scene. In some embodiments, ISP can be set in camera 193.
[0104] The camera 193 is used to capture still images or videos. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the optical signal into an electrical signal, and then passes the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. In some embodiments, the electronic device 100 may include 1 or N cameras 193, where N is a positive integer greater than 1.
[0105] The digital signal processor is used to process digital signals, and can process not only digital image signals but also other digital signals. For example, when the electronic device 100 is selecting a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0106] Video codecs are used to compress or decompress digital videos. The electronic device 100 may support one or more video codecs. Thus, the electronic device 100 may play or record videos in a variety of coding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.
[0107] NPU is a neural network (NN) computing processor. By drawing on the structure of biological neural networks, such as the transmission mode between neurons in the human brain, it can quickly process input information and can also continuously self-learn. Through NPU, applications such as intelligent cognition of electronic device 100 can be realized, such as image recognition, face recognition, voice recognition, text understanding, etc.
[0108] The electronic device 100 can implement audio functions such as music playing and recording through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the headphone jack 170D, and the application processor.
[0109] The audio module 170 is used to convert digital audio information into analog audio signal output, and is also used to convert analog audio input into digital audio signals. The audio module 170 can also be used to encode and decode audio signals. In some embodiments, the audio module 170 can be arranged in the processor 110, or some functional modules of the audio module 170 can be arranged in the processor 110.
[0110] The pressure sensor 180A is used to sense the pressure signal and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A can be set on the display screen 194. There are many types of pressure sensors 180A, such as resistive pressure sensors, inductive pressure sensors, capacitive pressure sensors, etc. The capacitive pressure sensor can be a parallel plate including at least two conductive materials. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The electronic device 100 determines the intensity of the pressure according to the change in capacitance. When a touch operation acts on the display screen 194, the electronic device 100 detects the touch operation intensity according to the pressure sensor 180A. The electronic device 100 can also calculate the touch position according to the detection signal of the pressure sensor 180A. In some embodiments, touch operations acting on the same touch position but with different touch operation intensities can correspond to different operation instructions. For example: when a touch operation with a touch operation intensity less than the first pressure threshold acts on the short message application icon, an instruction to view the short message is executed. When a touch operation with a touch operation intensity greater than or equal to the first pressure threshold acts on the short message application icon, an instruction to create a new short message is executed.
[0111] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., x, y, and z axes) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. Exemplarily, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate according to the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used for navigation and somatosensory game scenes. In one possible case, the angular velocity of the electronic device obtained by the gyro sensor 180B can be used to adjust the angle of the object in the image. For example, the vertical direction of the object in the image is adjusted to the direction of gravity based on the angular velocity of the electronic device obtained by the gyro sensor 180B.
[0112] The air pressure sensor 180C is used to measure air pressure. In some embodiments, the electronic device 100 calculates the altitude through the air pressure value measured by the air pressure sensor 180C to assist positioning and navigation.
[0113] The magnetic sensor 180D includes a Hall sensor. The electronic device 100 can use the magnetic sensor 180D to detect the opening and closing of the flip leather case. In some embodiments, when the electronic device 100 is a flip phone, the electronic device 100 can detect the opening and closing of the flip cover according to the magnetic sensor 180D. Then, according to the detected opening and closing state of the leather case or the opening and closing state of the flip cover, the flip cover can be automatically unlocked.
[0114] The acceleration sensor 180E can detect the magnitude of the acceleration of the electronic device 100 in various directions (generally three axes). When the electronic device 100 is stationary, the magnitude and direction of gravity can be detected. It can also be used to identify the posture of the electronic device, and is applied to applications such as horizontal and vertical screen switching and pedometers. In one possible case, the posture information of the electronic device obtained by the acceleration sensor 180E can be used to adjust the angle of the object in the image. For example, the vertical direction of the object in the image is adjusted to the direction of gravity based on the angular velocity of the electronic device obtained by the acceleration sensor 180E.
[0115] The distance sensor 180F is used to measure the distance. The electronic device 100 can measure the distance by infrared or laser. In some embodiments, when shooting a scene, the electronic device 100 can use the distance sensor 180F to measure the distance to achieve fast focusing.
[0116] The proximity light sensor 180G may include, for example, a light emitting diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The electronic device 100 emits infrared light outward through the light emitting diode. The electronic device 100 uses a photodiode to detect infrared reflected light from nearby objects. When sufficient reflected light is detected, it can be determined that there is an object near the electronic device 100. When insufficient reflected light is detected, the electronic device 100 can determine that there is no object near the electronic device 100. The electronic device 100 can use the proximity light sensor 180G to detect that the user holds the electronic device 100 close to the ear to talk, so as to automatically turn off the screen to save power. The proximity light sensor 180G can also be used in leather case mode and pocket mode to automatically unlock and lock the screen.
[0117] The ambient light sensor 180L is used to sense the ambient light brightness. The electronic device 100 can adaptively adjust the brightness of the display screen 194 according to the perceived ambient light brightness. The ambient light sensor 180L can also be used to automatically adjust the white balance when taking pictures. The ambient light sensor 180L can also cooperate with the proximity light sensor 180G to detect whether the electronic device 100 is in a pocket to prevent accidental touches.
[0118] The fingerprint sensor 180H is used to collect fingerprints. The electronic device 100 can use the collected fingerprint characteristics to implement fingerprint unlocking, access application locks, fingerprint photography, fingerprint call answering, etc.
[0119] The touch sensor 180K is also called a "touch panel". The touch sensor 180K can be set on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, also called a "touch screen". The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor can pass the detected touch operation to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100, which is different from the position of the display screen 194.
[0120] The key 190 includes a power key, a volume key, etc. The key 190 may be a mechanical key or a touch key. The electronic device 100 may receive key input and generate key signal input related to user settings and function control of the electronic device 100.
[0121] Motor 191 can generate vibration prompts. Motor 191 can be used for incoming call vibration prompts, and can also be used for touch vibration feedback. For example, touch operations acting on different applications (such as taking pictures, audio playback, etc.) can correspond to different vibration feedback effects. For touch operations acting on different areas of the display screen 194, motor 191 can also correspond to different vibration feedback effects. Different application scenarios (for example: time reminders, receiving messages, alarm clocks, games, etc.) can also correspond to different vibration feedback effects. The touch vibration feedback effect can also support customization.
[0122] It should be noted that any electronic device mentioned in the embodiments of the present application may include more or fewer modules in the electronic device 100.
[0123] The software system of the electronic device 100 may adopt a layered architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present application takes the Android system of the layered architecture as an example to exemplify the software structure of the electronic device 100.
[0124] Figure 4 It is a software structure block diagram of the electronic device 100 according to an embodiment of the present application.
[0125] The layered architecture of the electronic device 100 divides the software into several layers, each with a clear role and division of labor. The layers communicate with each other through software interfaces. In some embodiments, the software system can be divided into five layers, from top to bottom, namely, the application layer 210, the application framework layer 220, the hardware abstraction layer 230, the driver layer 240, and the hardware layer 250.
[0126] The application layer 210 may include camera and gallery applications, as well as calendar, call, map, navigation, WLAN, Bluetooth, music, video, short message, virtual reality (AR) and other applications.
[0127] The application framework layer 220 provides an application access interface and a programming framework for the application programs of the application layer 210 .
[0128] For example, the application framework layer 220 includes a camera access interface, which is used to provide camera shooting services through camera management and camera devices.
[0129] The camera management in the application framework layer 220 is used to manage the camera. The camera management can obtain the parameters of the camera, such as determining the working status of the camera.
[0130] The camera device in the application framework layer 220 is used to provide a data access interface between different camera devices and camera management.
[0131] The hardware abstraction layer 230 is used to abstract the hardware. For example, the hardware abstraction layer 230 may include a camera hardware abstraction layer and other hardware device abstraction layers; the camera hardware abstraction layer may include camera device 1, camera device 2, AR device, etc. It can be understood that camera device 1, camera device 2, AR device, etc. can be functional modules implemented by software or a combination of software and hardware. When the electronic device is turned on or the electronic device is running, a corresponding process will be created or a corresponding process will be started to implement the corresponding functions of camera device 1, camera device 2, and AR device. Specifically, the AR device is used to merge the virtual image and the actual image to generate an AR image, or to generate an AR video.
[0132] The camera hardware abstraction layer can be connected to the algorithm library, and the camera hardware abstraction layer can call the algorithm in the algorithm library. In the embodiment of the present application, the camera algorithm library includes an image processing algorithm. Among them, the image processing algorithm may include a depth estimation model and a semantic segmentation model.
[0133] The depth estimation model can process the RGB image to obtain the depth map corresponding to the RGB image.
[0134] The semantic segmentation model can process RGB images to obtain the mask map corresponding to the RGB image. Among them, the semantic segmentation model can only distinguish the objects and background in the RGB image, and cannot distinguish how many objects there are in the RGB image. For example, in the mask map obtained by the semantic segmentation model, the portrait is assigned a value of 1 and the background is assigned a value of 0, which is equivalent to assigning different portraits a value of 1. Therefore, the mask map obtained by the semantic segmentation model is prone to the situation where objects in the image are stuck together, such as Figure 1 As shown in (b) in .
[0135] It can be understood that, whether it is photo preview, video preview, or video recording, the electronic device 100 is continuously acquiring and displaying a video stream, and the video stream includes multiple frames of images. Therefore, in the embodiment of the present application, each image in the video stream is referred to as a frame image, and the nth image in the video stream is referred to as the nth frame image.
[0136] Of course, the camera algorithm library may also include other preset algorithms, such as a purple fringing removal algorithm, a saturation adjustment algorithm, etc., and the embodiments of the present application do not impose any limitation on this.
[0137] The driver layer 240 is used to provide drivers for different hardware devices. For example, the driver layer may include a camera driver, a digital signal processor driver, and a graphics processor driver.
[0138] The hardware layer 250 may include sensors, image signal processors, digital signal processors, graphics processors, and other hardware devices. The sensors may include sensor 1, sensor 2, etc., and may also include a depth sensor (time of flight, TOF) and a multi-spectral sensor.
[0139] Among them, the depth map can be directly acquired through TOF.
[0140] Exemplarily, after the user presses the photo control, an RGB image is acquired through sensor 1, and a depth map corresponding to the RGB image is acquired through TOF.
[0141] The following is an example of the workflow of the software system of the electronic device 100 , with reference to the generation process of an AR image in a photo-taking scenario.
[0142] When the user clicks on the AR APP control on the touch sensor 180K, the AR APP is awakened by the click operation and enters the photo preview mode. The AR APP calls the various camera devices of the camera hardware abstraction layer through the camera access interface and loads options for different AR effects. Exemplarily, the camera hardware abstraction layer determines that the current zoom factor is less than 0.6 zoom factors, so it can issue an instruction to call the wide-angle camera to the camera device driver. At the same time, the camera algorithm library starts to load the algorithms in the camera algorithm library.
[0143] When the sensor of the hardware layer is called, for example, after calling sensor 1 in the wide-angle camera to obtain the original image, the original image is subjected to preliminary processing such as registration, and then returned to the camera hardware abstraction layer through the camera device driver, and then processed using other preset algorithms in the loaded camera algorithm library to obtain RGB image, depth map and mask map, and then the RGB image, depth map and mask map are processed to obtain AR image.
[0144] When the sensor of the hardware layer is called, for example, after calling sensor 1 in the wide-angle camera to obtain the original image, the original image is subjected to preliminary processing such as registration, and then returned to the camera hardware abstraction layer through the camera device driver, and then processed using other preset algorithms in the loaded algorithm library to obtain RGB images and mask images. At the same time, after TOF obtains the depth map, it is returned to the camera hardware abstraction layer through the camera device driver. Then, using other preset algorithms in the loaded algorithm library, the RGB image, depth map, and mask map are processed to obtain an AR image.
[0145] The camera hardware abstraction layer sends the obtained AR image back to the AR APP through the camera access interface for preview display.
[0146] By repeating the above-mentioned AR image generation process, an AR video can be generated.
[0147] The application scenarios provided by the embodiments of the present application are described below with reference to the accompanying drawings.
[0148] Figure 5 Schematic diagram of an application scenario provided in an embodiment of the present application. Figure 5 As shown in (a) of FIG. 1 , a control 101 of the “AR” App is displayed on the display interface of the mobile phone. The user clicks the control 101 of the “AR” App, as shown in FIG. Figure 5 In response to the user's click operation, the display is as follows Figure 5 The first interface shown in (c) in FIG. The first interface includes an AR type option 102, a photo control 103, and a displayed AR image 104. The user can select different AR types from the AR type option 102, and then click the photo control 103 to generate the AR image 104. It should be noted that after clicking the photo control 103, the preview image displayed in the first interface is also an AR image. Among them, the captured image includes at least two objects, exemplarily, such as Figure 5 As shown in (c), the captured image includes two people, namely person 1 and person 2. The distance between person 1 and the camera is quite different from the distance between person 2 and the camera, and there is an overlapping area between person 1 and person 2. It should be understood that the object in the captured image may refer to a portrait, or may be an animal, a building, a plant, or other object, and the present application embodiment does not limit this.
[0149] The image processing method provided in the embodiment of the present application can also be applied to process a video to generate an AR video, wherein the video includes two objects. Continuing to use the example of two people included in the video, a frame of the captured video includes two people, namely person 1 and person 2. The distance between person 1 and the camera is significantly different from the distance between person 2 and the camera, and there is an overlapping area between person 1 and person 2.
[0150] It should be understood that the above is an example of an application scenario and does not limit the application scenario of the present application.
[0151] Combine the following Figures 6 to 15 The image processing method provided in the embodiment of the present application is described in detail.
[0152] Figure 6 A flowchart of an image processing method provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, the method includes:
[0153] S101 . Acquire a first image, and a first depth image and a first mask image corresponding to the first image.
[0154] Among them, the first image can refer to an RGB image obtained by acquiring the original image through sensor 1, performing preliminary processing such as registration on the original image, returning the original image to the camera hardware abstraction layer through the camera device driver, and then processing it using other preset algorithms in the loaded algorithm library.
[0155] Among them, obtaining the first depth image corresponding to the first image can be achieved by using the camera to capture the original image and simultaneously capturing the depth map at the same time as the first depth image through TOF; or the first image can be input into a depth estimation model to obtain the first depth image; the embodiment of the present application does not impose any restrictions on this.
[0156] For example, Figure 7 As shown in (a), after the sensor collects the original image, the original image is returned to the camera hardware abstraction layer, and then the algorithm in the algorithm library is loaded for processing to obtain the first image. The first image is then input into the depth estimation model to obtain the first depth image, and the first image is input into the semantic segmentation model to obtain the first mask image.
[0157] In the image processing method provided in the embodiment of the present application, the first depth image is obtained by inputting the first image into a preset depth estimation model, wherein the preset depth estimation model is a neural network model. In this way, the electronic device can obtain the corresponding first depth image based on the first image and the preset depth estimation model even when TOF is not configured, thereby improving the convenience of obtaining the first depth image and reducing the cost of the electronic device.
[0158] For example, Figure 7 As shown in (b), after the sensor collects the original image, it returns the original image to the camera hardware abstraction layer, and then loads the algorithm in the algorithm library for processing to obtain the first image. At the same time, TOF collects the first depth image at the same time as collecting the original image. The first image is input into the semantic segmentation model to obtain the first mask image.
[0159] In the image processing method provided in the embodiment of the present application, the first depth image is acquired by a camera device (TOF) in the electronic device, which makes the method of acquiring the first depth image more convenient, thereby improving the efficiency of obtaining the AR image based on the first depth image, the first image and the first mask image.
[0160] It should be understood that the first image, the first mask image and the first depth image are obtained by shooting the same scene, so there is a corresponding relationship between the first image, the first mask image and the first depth image. Exemplarily, the area where the portrait in the first image is located has a corresponding area in the first depth image, and also has a corresponding area in the first mask image. For the sake of ease of description, the depth of the object mentioned below refers to the depth value of the area corresponding to the object in the first depth image, the mask of the object refers to the mask of the area corresponding to the object in the first mask image, and the depth of the mask mentioned refers to the depth value of the area corresponding to the mask in the first mask image in the first depth image.
[0161] S102: Obtain a depth difference of the same mask in the first mask image.
[0162] If the depth difference is greater than the preset threshold 1, execute S103.
[0163] The depth difference of the same mask in the first mask image may refer to the depth extreme difference in the mask, or may refer to the depth standard deviation in the mask, which is not limited in the embodiment of the present application.
[0164] Exemplarily, the mask image may include multiple masks. Figure 8 As shown in (a) of FIG. 1 , mask 10 and mask 20 are included, respectively, wherein two characters in mask 10 are adhered, and there is one character in mask 20. Or, as Figure 8 As shown in (b) in FIG. 1 , mask 30 and mask 40 are included respectively, wherein mask 30 is a person, mask 40 is a person, and there is no person adhesion in the two masks.
[0165] For example, the mask image may include only one mask, such as Figure 8As shown in (c) of FIG. 5 , mask 50 is included, and mask 50 includes two characters, and the two characters are stuck together. Or, Figure 8 As shown in (d) in FIG. , mask 60 is included, and mask 60 includes a person, but there is no person adhesion.
[0166] Among them, the preset threshold 1 is equivalent to the first preset threshold.
[0167] Exemplarily, the preset threshold 1 is 0.5 m.
[0168] It should be understood that the portrait mask output by the semantic segmentation model can only distinguish the person from the background, but cannot distinguish different people. And because the human body is a whole, there will not be a situation where one part of the body is closer to the camera and the other part is farther away from the camera. In other words, when there is only one person in a mask, the depth value of the mask is not much different, and when there are at least two people in the mask, the depth value of the mask is greatly different.
[0169] For example, Figure 8 In the mask image shown in (a), the distances between the two characters in mask 10 and the camera are different, so the depth values in mask 10 are different and the difference is large. There is only one character in mask 20, and the overall distances between the characters and the camera are not much different, that is, the depth values in mask 20 are slightly different. Therefore, when the depth difference in mask 10 is greater than the preset threshold 1, it means that mask 10 includes at least two people. When the depth difference in mask 20 is less than the preset threshold 1, it means that there is only one character in mask 20.
[0170] For example, Figure 8 In the mask image (b) in FIG. 1 , there is only one person in mask 30, and the overall distances from the cameras are not much different, that is, the depth values in mask 30 are less different. Similarly, there is only one person in mask 40, and the overall distances from the cameras are not much different, that is, the depth values in mask 40 are less different. Therefore, when the depth difference in mask 40 is greater than the preset threshold 1, it means that mask 40 includes at least two people. When the depth difference in mask 40 is less than the preset threshold 1, it means that there is only one person in mask 40.
[0171] For example, Figure 8 In the mask image shown in (c), the distances between the two persons in mask 50 and the camera are different, so the depth values in mask 50 are different and the difference is large. Therefore, when the depth difference in mask 50 is greater than the preset threshold 1, it means that mask 50 includes at least two persons.
[0172] For example, Figure 8 In the mask image (d) shown in FIG. 6 , there is only one person in mask 60, and the overall distances from the cameras are not much different, that is, the depth values in mask 60 are less different. Therefore, if the depth difference in mask 60 is less than the preset threshold 1, it means that there is only one person in mask 60.
[0173] In summary, when the depth difference in the same mask is greater than the preset threshold 1, the mask includes at least two objects.
[0174] The image processing method provided in the embodiment of the present application obtains the depth difference of the same mask mask in the first mask image. If the depth difference is greater than the first preset threshold, it is determined that the first image includes the first object and the second object. This is equivalent to the process of determining whether the first image includes the first object and the second object at the same time. It is determined based on the depth difference of the same mask mask in the first mask image, which improves the intelligence of determining the existence of the first object and the second object in the first image.
[0175] For the convenience of description, the following description is made by taking a portrait as an example of an object in an image. It should be understood that the object in an image may also refer to an animal, a plant, a building, etc., and the present application embodiment does not limit this.
[0176] for Figure 8 The mask described in , where Figure 8 Mask 10 in (a) and Figure 8 The mask50 in (c) includes two objects, so we can Figure 8 The first depth map corresponding to the mask map shown in (a) in FIG. 1 , and Figure 8 The first depth map corresponding to the mask map shown in (c) executes step S103.
[0177] S103: Divide each depth value in the first depth image into a plurality of depth intervals according to a preset interval range.
[0178] Among them, the depth histogram of the interval corresponding to the mask in the first depth image can be calculated according to the preset interval range. For example, the preset interval range can be obtained by dividing according to the distance between the target object and the camera. Exemplarily, the preset interval range may include the distance between the target object and the camera is 0.5m to 1.5m, 1.5m to 2.5m, 2.5m to 3.5m. The obtained depth histogram can indicate the number of pixels within 0.5m to 1.5m from the camera, the number of pixels within 1.5m to 2.5m from the camera, and the number of pixels within 2.5m to 3.5m from the camera.
[0179] After the first depth image is divided into a plurality of depth intervals according to a preset interval range, the interval where the main depth in the first depth image is located is further obtained, for example, the interval where the depth with the number of pixels greater than 30% is located. For another example, the interval with the largest number of pixels can be directly determined as the interval where the main depth in the first depth image is located.
[0180] S104: Determine a target depth interval having the largest number of pixels among the multiple depth intervals.
[0181] S105: Determine a first preset template according to the depth range of the target depth interval.
[0182] The first preset template is related to the first distance, and the first distance is the distance between the first object and the electronic device.
[0183] Optionally, the first preset template is a head contour template, and the area of the first preset template is inversely proportional to the first distance.
[0184] Since the human head contour is quite different from other body parts, the human head contour can be used as a template to determine the number of people in the mask in the first mask image. The smaller the distance between the human body and the electronic device, the larger the human head contour in the image captured by the electronic device, and the larger the distance between the human body and the electronic device, the smaller the human head contour in the image captured by the electronic device. Therefore, the area of the head contour template is usually inversely proportional to the first distance.
[0185] Based on S104, after first determining the target depth interval with the largest number of pixels in the first depth image, it is equivalent to determining the area with the largest area in the first depth image, that is, the area where the main person in the image is located. In this case, the depth range of the target depth area is equal to the depth range of the portrait, so the head contour template corresponding to the depth range can be used as the first preset template.
[0186] For example, the target depth region with the largest number of pixels in the multiple depth intervals is the interval from 0.5m to 1.5m, and the preset head contour template includes 3 templates, such as Fig. 9 As shown, there are head outline templates with a first distance of 1m, a head outline template with a first distance of 2m, and a head outline template with a first distance of 3m. Based on the target depth area being in the range of 0.5m to 1.5m, the head outline template with a first distance of 1m is used as the first preset template. It can be seen that the smaller the first distance, the larger the area of the first preset template, and the larger the first distance, the smaller the area of the first preset template.
[0187] In an embodiment of the present application, the first preset template is a head contour template related to the distance between the first object and the electronic device, that is, the first distance. The larger the first distance, the smaller the area of the head contour template, and the smaller the first distance, the larger the area of the head contour template. Therefore, directly selecting the corresponding first preset template based on the first distance can make the size of the first preset template more matched with the size of the first object, thereby improving the efficiency of determining the first pixel point based on the first preset template, and thereby improving the efficiency of determining the second mask image based on the first pixel point.
[0188] Optionally, the candidate template may be rotated according to the shooting angle of the first image to obtain the first preset template.
[0189] S1051. Obtain position information of the electronic device.
[0190] The position information may refer to the angle between the electronic device and the direction of gravity. It should be understood that the change of the position of the electronic device will cause the shape of the captured image to change. The position information of the electronic device refers to the position information of the electronic device when acquiring the first image.
[0191] The electronic device can read the angular velocity of the electronic device around three axes (i.e., x, y and z axes) in the gyroscope sensor to determine the posture information of the electronic device, or read the acceleration in various directions in the acceleration sensor to determine the posture information. The embodiments of the present application are not limited to this.
[0192] S1052. Adjust the shape of the first preset template according to the posture information to obtain an adjusted first preset template.
[0193] It should be understood that when an electronic device acquires an image, the electronic device is usually not placed strictly along the direction of gravity, so the acquired image is distorted due to the shooting angle. The posture information can indicate the position and posture of the electronic device when acquiring the image, so the first preset template can be corrected based on the posture information, and the shape of the first preset template can be adjusted so that the angle corresponding to the first preset template is close to the shooting angle of the first image, thereby making the first preset template more compatible with the head contour of the portrait in the first image.
[0194] In the embodiment of the present application, the first preset template is adjusted according to the posture information of the electronic device to obtain the adjusted first preset template, so that the angle of the first preset template is close to the shooting angle of the first image, and the head contour of the portrait in the first image is more matched with the adjusted first preset template. Therefore, the first pixel point can be obtained more accurately based on the adjusted first preset template, thereby improving the accuracy of the second mask image obtained based on the first pixel point. The accuracy of the AR image obtained based on the second mask image and the first image is improved.
[0195] S106: Obtain an edge map corresponding to the first mask image.
[0196] The edge image is a binary image formed by the outline of the mask in the first mask image.
[0197] The edge image is a binary image formed by the contour of the mask in the first mask image.
[0198] Exemplarily, the first mask image includes a mask 10, such as Fig.10 As shown in (a) in FIG. 1 , the edge map is a binary map formed by the contour of mask 10 in the first mask image, such as Fig.10 As shown in (b) in .
[0199] S107: Perform a convolution operation on the first preset template and the edge map to obtain a first pixel point.
[0200] The first pixel is a pixel in the image area of the first object. For example, the first pixel may be a pixel in the central area of the head of the first object. The first pixel may be a pixel with the largest convolution value obtained by performing a convolution operation on the first preset template and the edge map.
[0201] Using the first preset template to perform a convolution operation on the edge map may refer to moving the first preset template from one side of the edge map to the other side to perform a convolution operation to obtain a convolution value.
[0202] For example, Fig.11As shown, the first preset template is convolved from the leftmost side of the edge map to the right.
[0203] For example, the following formula (1) may be used to perform a convolution operation.
[0204]
[0205] Among them, R(x,y) represents the convolution value, T(x ′ ,y ′ ) represents the pixel value of any point on the first preset template, I(x+x ′ ,y+y ′ ) represents the pixel value of any point on the edge map.
[0206] It should be understood that each pixel point on the edge map is convolved using the above formula (1) to obtain a convolution value, wherein the pixel point with the largest convolution value is the first pixel point.
[0207] It should be understood that a first pixel point of an object to be photographed can be determined by using a first preset template, and a first pixel point of the object to be photographed corresponding to the size can be obtained by performing convolution calculation on a head contour template of other sizes and a contour map.
[0208] For example, Fig.12 As shown in (a) of FIG. 1 , a convolution calculation is performed using a head contour template with a first distance of 1 m and an edge map to obtain a first pixel point in an image area of the object to be photographed with a distance of 1 m from the electronic device. Fig.12 As shown in (b), a head contour template with a first distance of 2m is used to perform convolution calculation with the same edge map, and the first pixel point obtained is the first pixel point in the image area of the object to be photographed with a distance of 2m from the electronic device.
[0209] S108: Perform superpixel segmentation on the first image to obtain multiple regions.
[0210] The multiple regions include a first region, and the first region refers to a region including a first pixel point.
[0211] Performing superpixel segmentation on the first image may refer to segmenting the first image according to brightness, color, etc. to obtain multiple regions, and the brightness and color of each region are similar. Among them, the region including the first pixel is the first region. It should be understood that superpixel segmentation usually divides the image into regions formed by a number of pixel points, that is, the first region includes a number of pixel points.
[0212] Exemplarily, superpixel segmentation of the first image may be performed as follows: Fig.13 As shown, the area where the first pixel point is located is the first area.
[0213] S109: Acquire first depth information.
[0214] The first depth information is used to represent the depth of the first area.
[0215] It should be understood that the first region refers to the region of the first pixel in the first image after the first image is segmented by superpixels. Since there is a corresponding relationship between the first image, the first depth image and the first mask image, the depth of the first region refers to the depth of the region corresponding to the first region in the first depth image. The first region includes a number of pixels, and the depth of the region corresponding to the first region in the first depth image refers to the average value of the depth values corresponding to the pixels in the corresponding region.
[0216] S110. Determine a first region set among multiple regions according to the first depth information.
[0217] The difference between the depth of each region in the first region set and the depth of the first region is less than a first threshold, and the first region set includes the first region.
[0218] After performing superpixel segmentation on the first image, multiple regions are obtained, and the depth information of each region in the multiple regions can be obtained, that is, the average depth value of the pixels in each region, and then the region whose depth difference with the first region is less than the first threshold is taken as the region in the first region set, and the first region is also a region in the first region set. This is equivalent to the region in the first region set being a region close to the depth of the first region, that is, the shooting distances corresponding to the regions in the first region set are close. It should be understood that the shooting distances of the same human body are usually close, that is, the depths of the various regions of the same person in the image are close. Therefore, the first region set is a set of image regions of the same person.
[0219] S111 . Generate a second mask image based on the first region set.
[0220] As described in S110 above, the difference between the depth of each area in the first area set and the depth of the first area is less than the first threshold, and the first area set includes the first area. The areas corresponding to the areas in the first area set in the first mask image are merged to obtain the second mask image. The mask of the first object in the second mask image is an independent mask, not a mask adhered to other objects to be photographed.
[0221] S112: Generate an AR image based on the second mask image and the first image.
[0222] Since the mask in the second mask image is an independent mask of the first object, enhanced image processing can be performed on the second mask image and the first image to obtain an AR image.
[0223] It should be understood that a video can be formed by continuously playing multiple frames of images, which is similar to generating an AR image based on the second mask image and the first image. Multiple frames of AR images can be generated by using multiple frames of the second mask image and their corresponding multiple frames of the first image, and then an AR video can be obtained based on the multiple frames of AR images. In other words, an AR video can also be generated based on the second mask image and the first image.
[0224] The image processing method provided in the embodiment of the present application first obtains a first image, a first depth image and a first mask image, then uses a first preset template to determine a first pixel point in the first image, and simultaneously performs superpixel segmentation on the first image to obtain multiple regions, then determines a first region set among the multiple regions based on the first depth information, and then obtains a second mask image based on the first region set, and then obtains an augmented reality AR image based on the second mask image and the first image, wherein the first image includes an image region of a first object and an image region of a second object, the image region of the first object and the image region of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, the first mask image identifies the image region of the first object and the image region of the second object in the first image, the first pixel point is a pixel point in the image region of the first object, the first preset template is related to the first distance, and the first distance is The distance between an object and an electronic device, multiple areas include a first area, the first area includes a first pixel point, first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, the first area set includes the first area, and the second mask image is used to identify the image area of the first object in the first image. Since the first pixel point of the image area of the first object in the first image is first obtained through the first preset template, the first area set determined based on the depth of the first area where the first pixel point is located is the image area of the same object and does not include the image areas of other objects. Therefore, the mask included in the second mask image obtained based on the first area set only indicates the image area of the first object alone, avoiding the situation where the depth of the first object is the average of the depths of the two objects, improving the accuracy of the depth of the first object, avoiding the problem of misalignment of the virtual image in the generated AR image, and improving the effect of the generated AR image.
[0225] In one possible case, after determining the first pixel in the first mask image, the second pixel can be further determined, that is, the pixel in the image area of the second object, and then the second area can be obtained based on the second pixel, wherein the second area refers to the area including the second pixel in the multiple areas obtained by superpixel segmentation of the first image, and then a second area set is determined based on the second area, the depth difference between the area in the second area set and the depth of the second area is less than a second threshold, and the second area set includes the second area. This is equivalent to determining a set of areas with a depth value close to the second pixel in the first mask image, that is, the area of the second object. The following is through Fig.14 The illustrated embodiment is described in detail.
[0226] Fig.14 A schematic diagram of a flow chart of an image processing method provided in another embodiment of the present application is shown in FIG. Fig.14 As shown, the method includes:
[0227] S201 . Acquire a first image, and a first depth image and a first mask image corresponding to the first image.
[0228] The implementation steps and principles of S201 are similar to those of S101 and will not be described in detail here.
[0229] S202 , obtaining a depth difference of the same mask in the first mask image, and if the depth difference is greater than a preset threshold 1, executing S203 .
[0230] Among them, the implementation steps and principles of S202 are similar to those of S102 and will not be repeated here.
[0231] S203: Divide each depth value in the first depth image into a plurality of depth intervals according to a preset interval range.
[0232] The implementation steps and principles of S203 are similar to those of S103 and will not be described in detail here.
[0233] S204: Determine a target depth interval having the largest number of pixels among the multiple depth intervals.
[0234] The implementation steps and principles of S204 are similar to those of S104 and will not be described in detail here.
[0235] S205: Determine a first preset template according to the depth range of the target depth interval.
[0236] The implementation steps and principles of S205 are similar to those of S105 and will not be described in detail here.
[0237] Optionally, the candidate template may be rotated according to the shooting angle of the first image to obtain the first preset template.
[0238] S2051. Obtain position information of the electronic device.
[0239] Among them, the implementation steps and principles of S2051 are similar to those of S1051 and will not be repeated here.
[0240] S2052. Adjust the shape of the first preset template according to the posture information to obtain an adjusted first preset template.
[0241] Among them, the implementation steps and principles of S2052 are similar to those of S1052 and will not be repeated here.
[0242] S206: Determine a second preset template.
[0243] The second preset template is related to the second distance, and the second distance refers to the distance between the second object and the electronic device.
[0244] The first preset template is a template corresponding to the depth range where the main depth in the mask is located. The second preset template may refer to a template corresponding to other depth ranges in the mask. Based on the depth difference of the same mask mask in the first mask image obtained in S202, the area corresponding to the target depth range is removed from the same mask in the first depth image, and the depth interval with the largest number of pixels (for ease of description, referred to as the second depth interval here) can be determined from other depth ranges, and the template corresponding to the second depth interval is used as the second preset template.
[0245] The image processing method provided in the embodiment of the present application, after determining the first preset template according to the depth range of the target depth interval, further determines the second preset template of the second object, and then on the basis of using the first preset template to perform a convolution operation on the edge map, it can also use the second preset template to perform a convolution operation on the edge map to obtain a second pixel point in the image area of the second object, so that after super-pixel segmentation of the first image, the multiple areas obtained include the first area and the second area, and further, a mask of the first object is obtained based on the first area, and a mask of the second object is obtained based on the second area, so that the image areas of the first object and the second object are simultaneously identified in the second mask image, and then the AR image determined according to the second mask image and the first image, on the basis of generating the AR image based on the image area of the first object, can also simultaneously generate the AR image based on the image area of the second object, thereby further improving the display effect of the generated AR image.
[0246] S207 , obtaining an edge map corresponding to the first mask image, where the edge map is a binary map formed by the outline of the mask in the first mask image.
[0247] The implementation steps and principles of S207 are similar to those of S106 and will not be described in detail here.
[0248] S208: Perform a convolution operation on the first preset template and the edge map to obtain a first pixel point.
[0249] The first pixel point is a pixel point of the image area of the first object. For example, the first pixel point may refer to a pixel point of the central area of the head of the first object. The first pixel point may be a pixel point with the maximum convolution value obtained by performing a convolution operation on the first preset template and the edge map.
[0250] Using the first preset template to perform a convolution operation on the edge map may refer to moving the first preset template from one side of the edge map to the other side to perform a convolution operation to obtain a convolution value.
[0251] S209: Perform a convolution operation on the second preset template and the edge map to obtain a second pixel point.
[0252] The second pixel is a pixel in the image area of the second object, for example, the second pixel may be a pixel in the central area of the head of the second object. The second pixel may be a pixel with the largest convolution value obtained by performing a convolution operation on the second preset template and the edge map.
[0253] The specific process of performing convolution calculation using the second preset template and the edge map to obtain the second pixel point may be similar to the specific process of performing convolution calculation using the first preset template and the edge map, which will not be repeated here.
[0254] Since the template used for convolution with the edge map is a preset template, that is, a template selected from multiple known templates. Therefore, in one possible case, other templates except the first preset template are sequentially used to perform convolution operations with the edge map, and the second pixel point of the second object is obtained according to the convolution result. The second pixel point refers to the pixel point in the image area of the second object. It can be understood that the template determined to perform convolution calculation with the edge map to obtain the second pixel point is the second preset template.
[0255] S210: Perform superpixel segmentation on the first image to obtain multiple regions.
[0256] The multiple regions include a first region and a second region, the first region refers to a region including a first pixel point, and the second region refers to a region including a second pixel point.
[0257] The implementation steps and principles of S210 are similar to those of S108 and will not be described in detail here.
[0258] S211. Acquire first depth information and second depth information.
[0259] The first depth information is used to indicate the depth of the first area, and the second depth information is used to indicate the depth of the second area.
[0260] It should be understood that the first region refers to the region of the first pixel in the first image after the first image is segmented by superpixels. Since there is a corresponding relationship between the first image, the first depth image and the first mask image, the depth of the first region refers to the depth of the region corresponding to the first region in the first depth image. The first region includes a number of pixels, and the depth of the region corresponding to the first region in the first depth image refers to the average value of the depth values corresponding to the pixels in the corresponding region.
[0261] It should be understood that the second region refers to the region of the second pixel in the first image after the first image is superpixel segmented. Since there is a corresponding relationship between the first image, the first depth image and the first mask image, the depth of the second region refers to the depth of the region corresponding to the second region in the first depth image. The second region includes a number of pixels, and the depth of the region corresponding to the second region in the first depth image refers to the average value of the depth values corresponding to each pixel in the corresponding region.
[0262] S212: Determine a first area set among multiple areas according to the first depth information.
[0263] The difference between the depth of each region in the first region set and the depth of the first region is less than a first threshold, and the first region set includes the first region.
[0264] After the first image is subjected to superpixel segmentation, multiple regions are obtained, and the depth information of each region in the multiple regions can be obtained, that is, the average depth value of the pixels in each region, and then the region whose depth difference with the first region is less than the first threshold is taken as the region in the first region set, and the first region is also a region in the first region set. This is equivalent to the region in the first region set being a region close to the depth of the first region, that is, the shooting distances corresponding to the regions in the first region set are close. It should be understood that the shooting distances of the same human body are usually close, that is, the depths of the various regions of the same person in the image are close. Therefore, the first region set is a set of image regions of the same person. Generally, the closer the distance from the camera, the larger the area occupied by the object to be photographed in the first image. Since the first preset template is determined based on the target depth interval with the largest number of pixels in multiple depth intervals. Therefore, the first pixel point determined by the first preset template is a pixel point in the object to be photographed (first object) that occupies a larger area in the first image. That is to say, the first object can refer to the object to be photographed that is closer to the camera in the same mask in the first mask image.
[0265] S213: Determine a second region set among the multiple regions according to the second depth information.
[0266] The difference between the depth of each region in the second region set and the depth of the second region is less than a first threshold, and the second region set includes the second region.
[0267] After performing superpixel segmentation on the first image, multiple regions are obtained, and the depth information of each region in the multiple regions can be obtained, that is, the average depth value of the pixels in each region, and then the region whose depth difference with the second region is less than the second threshold is used as the region in the second region set, and the second region is also a region in the second region set. Among them, the first threshold and the second threshold can be the same or different, and the embodiment of the present application is not limited to this. This is equivalent to the region in the second region set being the region close to the depth of the second region, that is, the shooting distance corresponding to the region in the second region set is close. It should be understood that the shooting distance of the same human body is usually close, that is, the depth of each region of the same person in the image is close. Therefore, the second region set is the image region set of the same person, that is, the image region set of the second object. Since the first object refers to the object to be photographed that is closer to the camera in the same mask in the first mask image, the second object refers to the object to be photographed that is farther from the camera in the same mask in the first mask image.
[0268] It should be understood that the same mask in the first mask image may include more objects to be photographed, for example, the same mask includes three objects to be photographed. In the case where multiple objects to be photographed are included in the same mask, a similar method can be used to determine the third pixel of the third object in the first image, and determine the third region and the third region set based on the third pixel. The third region refers to the image region including the third pixel in the first image, the depth difference between the depth of each region in the third region set and the depth of the third region is less than the third threshold, and the third region set includes the third region. The first threshold, the second threshold and the third threshold may be the same threshold or different thresholds, and the embodiment of the present application is not limited to this.
[0269] S214 . Generate a second mask image based on the first region set and the second region set.
[0270] From the description in S213 above, it can be seen that the difference between the depth of each area in the first area set and the depth of the first area is less than the first threshold, and the first area set includes the first area. The difference between the depth of each area in the second area set and the depth of the second area is less than the second threshold. The areas corresponding to the areas in the first area set in the first mask image are merged, and the areas in the second area set in the first mask image are merged to obtain the second mask image. The mask of the first object in the second mask image is an independent mask, and the mask of the second object is also an independent mask, and neither is a mask adhered to other objects to be photographed.
[0271] S215 : Generate an AR image based on the second mask image and the first image.
[0272] Since the mask in the second mask image is a mask independent of the first object and a mask independent of the second object, it is possible to perform enhanced image processing on the second mask image and the first image to obtain an AR image.
[0273] The image processing method provided in the embodiment of the present application, after determining the first preset template according to the depth range of the target depth interval, further determines the second preset template of the second object, and then on the basis of using the first preset template to perform a convolution operation on the edge map, it can also use the second preset template to perform a convolution operation on the edge map to obtain a second pixel point in the image area of the second object, so that after super-pixel segmentation of the first image, the multiple areas obtained include the first area and the second area, and further, a mask of the first object is obtained based on the first area, and a mask of the second object is obtained based on the second area, so that the image areas of the first object and the second object are simultaneously identified in the second mask image, and then the AR image determined according to the second mask image and the first image, on the basis of generating the AR image based on the image area of the first object, can also simultaneously generate the AR image based on the image area of the second object, thereby further improving the display effect of the generated AR image.
[0274] Fig.15 A schematic diagram of a flow chart of an image processing method provided in another embodiment of the present application is shown in FIG. Fig.15 As shown, the method includes:
[0275] S301 : Acquire a first image, a first depth image, and a first mask image.
[0276] Among them, the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image.
[0277] S302: Determine a first pixel point in a first image using a first preset template.
[0278] The first pixel point is a pixel point in an image area of the first object, the first preset template is related to the first distance, and the first distance is the distance between the first object and the electronic device.
[0279] S303: Perform superpixel segmentation on the first image to obtain multiple regions.
[0280] The multiple regions include a first region, and the first region includes a first pixel point;
[0281] S304: Determine a first region set among multiple regions based on the first depth information.
[0282] The first depth information is used to characterize the depth of the first region, a difference between the depth of each region in the first region set and the depth of the first region is less than a first threshold, and the first region set includes the first region;
[0283] S305 . Obtain a second mask image based on the first region set.
[0284] The second mask image is used to identify the image area of the first object in the first image;
[0285] The image processing method provided in the embodiment of the present application first obtains a first image, a first depth image and a first mask image, then uses a first preset template to determine a first pixel point in the first image, and simultaneously performs superpixel segmentation on the first image to obtain multiple regions, then determines a first region set among the multiple regions based on the first depth information, and then obtains a second mask image based on the first region set, and then obtains an augmented reality AR image based on the second mask image and the first image, wherein the first image includes an image region of a first object and an image region of a second object, the image region of the first object and the image region of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize the depth information of the first object and the second object, the first mask image identifies the image region of the first object and the image region of the second object in the first image, the first pixel point is a pixel point in the image region of the first object, the first preset template is related to a first distance, and the first distance is a distance between the first object and the second object. The distance between electronic devices, multiple areas include a first area, the first area includes a first pixel point, the first depth information is used to characterize the depth of the first area, the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, the first area set includes the first area, and the second mask image is used to identify the image area of the first object in the first image. Since the first pixel point of the image area of the first object in the first image is first obtained through the first preset template, the first area set determined based on the depth of the first area where the first pixel point is located is the image area of the same object and does not include image areas of other objects. Therefore, the mask included in the second mask image obtained based on the first area set only indicates the image area of the first object alone, avoiding the situation where the depth of the first object is determined based on the depth average of at least two objects, improving the accuracy of the depth of the first object, avoiding the problem of misalignment of the virtual image in the generated AR image, and improving the effect of the generated AR image.
[0286] It should be understood that, although each step in the flow chart in the above-described embodiment is shown in sequence according to the indication of the arrow, these steps are not necessarily performed in sequence according to the order indicated by the arrow. Unless there is clear explanation in this article, the execution of these steps does not have strict order restriction, and these steps can be performed in other orders. Moreover, at least a portion of the steps in the flow chart may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and the execution order of these sub-steps or stages is not necessarily performed in sequence, but can be performed in turn or alternately with at least a portion of other steps or sub-steps or stages of other steps.
[0287] It is understandable that in order to implement the above functions, the electronic device includes hardware and / or software modules corresponding to the execution of each function. In combination with the algorithm steps of each example described in the embodiments disclosed herein, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application in combination with the embodiments, but such implementation should not be considered to be beyond the scope of the present application.
[0288] The embodiment of the present application can divide the functional modules of the electronic device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one module. It should be noted that the division of modules in the embodiment of the present application is schematic and is only a logical function division. There may be other division methods in actual implementation. It should be noted that the names of the modules in the embodiment of the present application are schematic and are not limited to the names of the modules in actual implementation.
[0289] Fig.16 A schematic diagram of the structure of an image processing device provided in an embodiment of the present application.
[0290] It should be understood that the image processing apparatus 600 may execute Figures 6 to 15 The image processing method shown; the image processing device 600 includes: an acquisition unit 610 and a processing unit 620.
[0291] The acquisition unit 610 is used to acquire a first image, a first depth image, and a first mask image, wherein the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image;
[0292] The processing unit 620 is used to determine a first pixel point in the first image using a first preset template, where the first pixel point is a pixel point in an image area of a first object, and the first preset template is associated with a first distance, where the first distance is a distance between the first object and the electronic device;
[0293] The processing unit 620 is configured to perform superpixel segmentation on the first image to obtain a plurality of regions, wherein the plurality of regions include a first region, and the first region includes a first pixel point;
[0294] The processing unit 620 is configured to determine a first region set among the multiple regions based on the first depth information, where the first depth information is used to characterize the depth of the first region, where a difference between the depth of each region in the first region set and the depth of the first region is less than a first threshold, and the first region set includes the first region;
[0295] The processing unit 620 is used to obtain a second mask image based on the first region set, where the second mask image is used to identify an image region of the first object in the first image;
[0296] The processing unit 620 is configured to obtain an augmented reality (AR) image based on the second mask image and the first image.
[0297] In one embodiment, if the first object and the second object are persons, the first preset template is a head outline template, and the first distance is inversely proportional to the area of the first preset template.
[0298] In one embodiment, the acquisition unit 610 is further used to acquire the position and posture information of the electronic device;
[0299] The processing unit 620 is further configured to adjust the shape of the head contour template based on the posture information.
[0300] In one embodiment, the processing unit 620 is further configured to divide each depth value in the first depth image into a plurality of depth intervals according to a preset interval range; determine a target depth interval having the largest number of pixels among the plurality of depth intervals;
[0301] A first preset template is determined according to a depth range of the target depth interval.
[0302] In one embodiment, the processing unit 620 is used to obtain an edge map corresponding to the first mask image, where the edge map is a binary map formed by the contour of the mask in the first mask image;
[0303] A convolution operation is performed on the first preset template and the edge map to obtain a first pixel point.
[0304] In one embodiment, the processing unit 620 is configured to obtain a depth difference of the same mask mask in the first mask image; if the depth difference is greater than a first preset threshold, it is determined that the first image includes the first object and the second object.
[0305] In one embodiment, the processing unit 620 is used to use a second preset template to determine a second pixel point in the first image, where the second pixel point is a pixel point in the image area of the second object, and the second preset template is related to a second distance, which is the distance between the second object and the electronic device; the multiple areas also include a second area, and the second area includes the second pixel point; based on the second depth information, a second area set of the multiple areas is determined, and the second depth information is used to characterize the depth of the second area, the difference between the depth of each area in the second area set and the depth of the second area is less than a second threshold, and the second area set includes the second area; based on the first area set and the second area set, a second mask image is obtained.
[0306] In one embodiment, the processing unit 620 is used to obtain an edge map corresponding to the first mask image, where the edge map is a binary map formed by the contour of the object in the first mask image; and perform a convolution operation on the second preset template and the edge map to obtain a second pixel point.
[0307] In one embodiment, the first depth image is acquired by a camera device in the electronic device.
[0308] In one embodiment, the first depth image is obtained by inputting the first image into a preset depth estimation model, and the depth estimation model is a neural network model.
[0309] In one embodiment, the first mask image is obtained by inputting the first image into a preset semantic segmentation model, and the semantic segmentation model is a neural network model.
[0310] The image processing device provided in this embodiment is used to execute the image processing method of the above-mentioned embodiment. The technical principle and technical effect are similar and will not be described in detail here.
[0311] It should be noted that the above-mentioned image processing device 600 is embodied in the form of a functional unit. The term "unit" here can be implemented in the form of software and / or hardware, and is not specifically limited to this.
[0312] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two that implements the above functions. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (e.g., a shared processor, a dedicated processor, or a group processor, etc.) and a memory for executing one or more software or firmware programs, a combined logic circuit, and / or other suitable components that support the described functions.
[0313] Therefore, the units of each example described in the embodiments of the present application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present application.
[0314] Fig.17 A structural schematic diagram of an electronic device provided by the present application is shown. Fig.17 The dotted line in indicates that the unit or the module is optional. The electronic device 700 can be used to implement the image processing method described in the above method embodiment.
[0315] The electronic device 700 includes one or more processors 701, which can support the electronic device 700 to implement the image processing method in the method embodiment. The processor 701 can be a general-purpose processor or a special-purpose processor. For example, the processor 701 can be a central processing unit (CPU), a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, such as discrete gates, transistor logic devices or discrete hardware components.
[0316] The processor 701 may be used to control the electronic device 700, execute software programs, and process data of the software programs. The electronic device 700 may also include a communication unit 705 to implement input (reception) and output (transmission) of signals.
[0317] For example, the electronic device 700 may be a chip, the communication unit 705 may be an input and / or output circuit of the chip, or the communication unit 705 may be a communication interface of the chip, and the chip may be a component of a terminal device or other electronic devices.
[0318] For another example, the electronic device 700 may be a terminal device, and the communication unit 705 may be a transceiver of the terminal device, or the communication unit 705 may be a transceiver circuit of the terminal device.
[0319] The electronic device 700 may include one or more memories 702 on which a program 704 is stored. The program 704 can be executed by the processor 701 to generate instructions 703, so that the processor 701 executes the impedance matching method described in the above method embodiment according to the instructions 703.
[0320] Optionally, data may be stored in the memory 702. Optionally, the processor 701 may read data stored in the memory 702. The data may be stored at the same storage address as the program 704, or may be stored at a different storage address than the program 704.
[0321] The processor 701 and the memory 702 may be provided separately or integrated together; for example, integrated on a system on chip (SOC) of a terminal device.
[0322] Exemplarily, the memory 702 can be used to store the related program 704 of the image processing method provided in the embodiment of the present application, and the processor 701 can be used to call the related program 704 of the image processing method stored in the memory 702 when performing image processing, and execute the image processing method of the embodiment of the present application; including: acquiring a first image, a first depth image and a first mask image, wherein the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are the same category of objects to be photographed, the first depth image is used to characterize the depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image; using a first preset model The board determines a first pixel point in a first image, where the first pixel point is a pixel point in an image area of a first object, and a first preset template is related to a first distance, where the first distance is a distance between the first object and the electronic device; superpixel segmentation is performed on the first image to obtain multiple areas, where the multiple areas include a first area, and the first area includes the first pixel point; a first area set of the multiple areas is determined based on first depth information, where the first depth information is used to characterize the depth of the first area, where the difference between the depth of each area in the first area set and the depth of the first area is less than a first threshold, and the first area set includes the first area; based on the first area set, a second mask image is obtained, where the second mask image is used to identify the image area of the first object in the first image; based on the second mask image and the first image, an augmented reality AR image is obtained.
[0323] The present application also provides a computer program product, which, when executed by the processor 701, implements the image processing method described in any method embodiment of the present application.
[0324] The computer program product may be stored in the memory 702 , for example, a program 704 , which is converted into an executable target file that can be executed by the processor 701 after preprocessing, compiling, assembling, and linking.
[0325] The present application also provides a computer-readable storage medium on which a computer program is stored, and when the computer program is executed by a computer, the image processing method described in any method embodiment of the present application is implemented. The computer program can be a high-level language program or an executable target program.
[0326] The computer-readable storage medium is, for example, a memory 702. The memory 702 may be a volatile memory or a nonvolatile memory, or the memory 702 may include both a volatile memory and a nonvolatile memory. Among them, the nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).
[0327] In this application, "at least one" means one or more, and "more than one" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can be represented by: a, b, c, ab, ac, bc, or abc, where a, b, c can be single or multiple.
[0328] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0329] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0330] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0331] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely schematic; for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0332] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0333] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0334] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. An image processing method, characterized in that: include: Acquire a first image, a first depth image, and a first mask image, wherein the first image includes an image area of a first object and an image area of a second object, the image area of the first object and the image area of the second object partially overlap, the first object and the second object are objects to be photographed of the same category, the first depth image is used to characterize depth information of the first object and the second object, and the first mask image identifies the image area of the first object and the image area of the second object in the first image; A first preset template is used to determine a first area set in the first image, a difference between the depth of each area in the first area set and the depth of the target area is less than a first threshold, the first preset template is related to a first distance, the first distance is the distance between the first object and the electronic device, the target area is an area including a pixel point in the first object, the number of the target areas is 1, and the depth of the target area refers to an average value of depth values corresponding to each pixel point in the target area; Based on the first region set, obtaining a second mask image, where the second mask image is used to identify an image region of the first object in the first image; If the first object and the second object are persons, the first preset template is a head outline template, and the first distance is inversely proportional to the area of the first preset template.
2. The method according to claim 1, characterized in that A pixel point in the first object is a first pixel point, and the using a first preset template to determine a first area set in the first image includes: Using a first preset template to determine the first pixel point in the first image, Performing superpixel segmentation on the first image to obtain multiple regions, wherein the multiple regions include the target region, and the target region includes the first pixel point; The first region set among the multiple regions is determined based on first depth information, where the first depth information is used to characterize the depth of the target region, and the first region set includes the target region.
3. The method according to claim 1 or 2, characterized in that: Also includes: Acquiring position information of the electronic device; The shape of the head outline template is adjusted based on the posture information.
4. The method according to claim 1 or 2, characterized in that: Also includes: Dividing each depth value in the first depth image into a plurality of depth intervals according to a preset interval range; Determine a target depth interval having the largest number of pixels among the multiple depth intervals; The first preset template is determined according to the depth range of the target depth interval.
5. The method according to claim 2, characterized in that: The step of using a first preset template to determine a first pixel point in the first image includes: Acquire an edge map corresponding to the first mask image, where the edge map is a binary map formed by the outline of the mask in the first mask image; A convolution operation is performed on the first preset template and the edge map to obtain the first pixel point.
6. The method according to claim 1 or 2, characterized in that: The method further comprises: Obtaining a depth difference of the same mask mask in the first mask image; If the depth difference is greater than a first preset threshold, it is determined that the first image includes the first object and the second object.
7. The method according to claim 2, characterized in that Also includes: Determine a second pixel point in the first image using a second preset template, where the second pixel point is a pixel point in an image region of the second object, and the second preset template is associated with a second distance, where the second distance is a distance between the second object and the electronic device; The multiple regions further include a second target region, and the second target region includes the second pixel point; determining a second area set among the multiple areas based on second depth information, where the second depth information is used to characterize the depth of the second target area, a difference between the depth of each area in the second area set and the depth of the second target area is less than a second threshold, and the second area set includes the second target area; The obtaining a second mask image based on the first region set includes: The second mask image is obtained based on the first region set and the second region set.
8. The method according to claim 7, characterized in that The using a second preset template to determine a second pixel point in the first image includes: Acquire an edge map corresponding to the first mask image, where the edge map is a binary map formed by the outline of the object in the first mask image; A convolution operation is performed on the second preset template and the edge map to obtain the second pixel point.
9. The method according to claim 1 or 2, characterized in that: The first depth image is acquired by a camera device in the electronic device.
10. The method according to claim 1 or 2, characterized in that: The first depth image is obtained by inputting the first image into a preset depth estimation model, and the depth estimation model is a neural network model.
11. The method according to claim 1 or 2, characterized in that: The first mask image is obtained by inputting the first image into a preset semantic segmentation model, and the semantic segmentation model is a neural network model.
12. The method according to claim 1 or 2, characterized in that: The method further comprises: Based on the second mask image and the first image, an augmented reality AR image is obtained, or an AR video is obtained.
13. An image processing device, characterized in that: The device comprises a processor and a memory, wherein the memory is used to store a computer program, and the processor is used to call and run the computer program from the memory, so that the device executes the method according to any one of claims 1 to 12.
14. A chip, characterized in that: The method comprises a processor, and when the processor executes instructions, the processor performs the method according to any one of claims 1 to 12.
15. An electronic device, characterized in that: The electronic device comprises a processor, wherein the processor is coupled to a memory, reads instructions in the memory, and enables the electronic device to execute the method according to any one of claims 1 to 12 according to the instructions.
16. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor is caused to perform the method according to any one of claims 1 to 12.
