WO2023010661A1 - Image cropping method and related product - Google Patents

Image cropping method and related product Download PDF

Info

Publication number
WO2023010661A1
WO2023010661A1 PCT/CN2021/119420 CN2021119420W WO2023010661A1 WO 2023010661 A1 WO2023010661 A1 WO 2023010661A1 CN 2021119420 W CN2021119420 W CN 2021119420W WO 2023010661 A1 WO2023010661 A1 WO 2023010661A1
Authority
WO
WIPO (PCT)
Prior art keywords
boundary
face area
image
original image
cropping
Prior art date
Application number
PCT/CN2021/119420
Other languages
French (fr)
Chinese (zh)
Inventor
蒋彬
宋利伟
殷晨晖
周奥
杨天明
Original Assignee
展讯通信(上海)有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 展讯通信(上海)有限公司 filed Critical 展讯通信(上海)有限公司
Publication of WO2023010661A1 publication Critical patent/WO2023010661A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/12Edge-based segmentation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/80Geometric correction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20112Image segmentation details
    • G06T2207/20132Image cropping
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/30Subject of image; Context of image processing
    • G06T2207/30196Human being; Person
    • G06T2207/30201Face

Definitions

  • the present application relates to the technical field of image processing, in particular to an image cropping method and related products.
  • Lenses currently on the market can be roughly divided into two types: wide-angle lenses and non-wide-angle lenses. Images captured by products with non-wide-angle lenses, such as mobile phone lenses, have less distortion. The distortion of images taken by products with wide-angle lenses or ultra-wide-angle lenses is usually very large, and it is almost impossible to see without distortion correction. There are two main types of image distortion: radial distortion and tangential distortion. Radial distortion: The distortion at the center is the smallest, and the distortion increases with the increase of the radius. Radial distortion can be divided into pincushion distortion and barrel distortion. Tangential distortion is caused by the fact that the lens itself is not parallel to the camera sensor plane (imaging plane) or the image plane. This situation is mostly caused by the installation deviation of the lens pasted on the lens module.
  • the phenomenon of portrait distortion in the image can be corrected through different image processing techniques such as projection transformation. While correcting the phenomenon of portrait distortion in the image, the image content around the portrait will also be affected to a certain extent, such as the bending of straight lines. After correcting the phenomenon of portrait distortion in the image, it is generally necessary to further crop the corrected image to remove part of the image content in the corrected image that is affected by the correction process.
  • the distortion-corrected image is more natural after being cropped. At present, there is a problem of cropping too much or not cropping enough in the way of cropping and distortion correcting the processed image. How to avoid excessive cropping or insufficient cropping is a problem that needs to be studied by the target.
  • the embodiment of the present application discloses an image cropping method and related products.
  • an embodiment of the present application provides an image cropping method, the method comprising: acquiring first face area information; the first face area information characterizes the first face area in the original image; based on preset Scale factor and the first face area information to obtain second face area information; the second face area information represents the second face adjusted by the first face area according to the preset scale coefficient area: based on the boundary between the second human face area and the original image, crop the original image to obtain a first image.
  • the original image is cropped to obtain the first image; the area with severe distortion in the original image can be accurately cropped to avoid excessive cropping or insufficient cropping .
  • the cropping the original image based on the boundary between the second face area and the original image to obtain the first image includes: When the number of pixels whose boundary exceeds the first boundary of the original image is greater than a first threshold, use the first cropping boundary as a new first boundary of the original image to crop the original image to obtain the first image;
  • the first cropping boundary is parallel to the first boundary of the original image, and the number of pixels between the first cropping boundary and the first boundary of the original image is equal to the first boundary of the second human face area The difference between the number of pixels beyond the first boundary of the original image and the first threshold.
  • the number of pixels between the first cropping boundary and the first boundary of the original image refers to the number of pixels corresponding to the distance between the first cropping boundary and the first boundary of the original image.
  • the first boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
  • the original image is cropped using the first cropping boundary as a new first boundary of the original image to obtain the first image.
  • the first clipping boundary is determined by the difference between the number of pixels that the first boundary of the second human face region exceeds the first boundary of the original image and the first threshold, and the first cropping boundary takes into account the size of the first human face region and The distance between the first boundary of the first human face area and the first boundary of the original image can be used to crop the edge of the image in a reasonable proportion.
  • the cropping the original image based on the boundary between the second face area and the original image to obtain the first image includes: When the distance between the boundary and the second boundary of the original image is less than a second threshold and the second face area is located in the original image, the second cropping boundary is used as the new second boundary of the original image cropping the original image to obtain the first image; the second cropping boundary is a second boundary of the second face area.
  • the fact that the second face area is located in the original image means that the second face area is included in the original image.
  • the second boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
  • the area between the second boundary of the second human face area and the second boundary of the original image can be understood as an area with severe distortion, and other areas are areas with light distortion.
  • the original image is cropped using the second cropping boundary as a new second boundary of the original image to obtain the first image.
  • the new second boundary cropping the original image takes into account the size of the first human face area and the distance between the second boundary of the first human face area and the second boundary of the original image, which can be The edges of the image are cropped with reasonable proportions.
  • the first face area information includes: the vertex coordinates of the first face area and the length and width of the first face area;
  • obtaining the second face area information includes: taking the product of the length and width of the first face area and the preset proportional coefficient as the length of the second face area and width, and determine the vertex coordinates of the second face area according to the vertex coordinates, length and width of the first face area.
  • the second face region information can be acquired quickly and accurately.
  • the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area.
  • the first vertex is any one of an upper left vertex, a lower left vertex, an upper right vertex, and a lower right vertex.
  • the first vertex is any vertex on the third boundary of the second human face area, and the distance between the third boundary of the first human face area and the third boundary of the original image is greater than other boundaries of the first human face area The distance from the corresponding border of the original image.
  • the coordinates of the center point of the second face area are the same as the coordinates of the center point of the first face area.
  • the method further includes: Width, height and the ratio of width to height are scaled and interpolated to the first image to obtain a second image; the width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of the original image
  • the ratio of width to height is the same.
  • the first image is scaled and interpolated according to the width, height and ratio of width and height of the original image to obtain the second image; the width, height and width of the original image can be obtained from the cropped first image
  • the second image is the same with high proportions.
  • the method further includes: performing distortion correction processing on the input image to obtain the original image.
  • an embodiment of the present application provides an image processing device, including: an acquisition unit, configured to first face area information; the first face area information represents a first face area in an original image; the The acquisition unit is further configured to acquire second face area information based on a preset scale factor and the first face area information; the second face area information indicates that the first face area is in accordance with the preset The second human face area after the scale factor has been adjusted; an image cropping unit, configured to crop the original image based on the boundary between the second human face area and the original image to obtain the first image.
  • the image cropping unit is specifically configured to: when the number of pixels in which the first boundary of the second face area exceeds the first boundary of the original image is greater than a first threshold , using the first cropping boundary as the new first boundary of the original image to crop the original image to obtain the first image; the first cropping boundary is parallel to the first boundary of the original image, and the first The number of pixels between the cropping boundary and the first boundary of the original image is equal to the difference between the number of pixels where the first boundary of the second face area exceeds the first boundary of the original image and the first threshold .
  • the image cropping unit is specifically configured to make the distance between the second boundary of the first face area and the second boundary of the original image smaller than a second threshold and the In the case where the second human face area is located in the original image, the original image is cropped with the second crop boundary as the new second boundary of the original image to obtain the first image; the second crop boundary is the Describe the second boundary of the second face area.
  • the first face area information includes: the vertex coordinates of the first face area and the length and width of the first face area; Taking the product of the length and width of the first human face area and the preset proportional coefficient as the length and width of the second human face area, and according to the vertex coordinates, length and Width determines the vertex coordinates of the second face area.
  • the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area.
  • the coordinates of the center point of the second face area are the same as the coordinates of the center point of the first face area.
  • the device further includes: a processing unit configured to perform scaling and interpolation on the first image according to the width, height, and ratio of width to height of the original image to obtain a second image;
  • the width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of width to height of the original image.
  • the processing unit is further configured to perform distortion correction processing on the input image to obtain the original image.
  • an embodiment of the present application provides an image processing device, the image processing device includes: a processor and a memory, wherein the memory is used to store instructions, and the processor is used to execute the instructions stored in the memory, The processor is made to execute the method according to the above first aspect and any possible implementation manner.
  • an embodiment of the present application provides a chip, where the chip includes a data interface and a processor, where the processor is configured to execute the method in the first aspect or any possible implementation manner of the first aspect.
  • the embodiment of the present application provides a computer-readable storage medium, the computer storage medium stores a computer program, the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the above-mentioned first step.
  • the computer storage medium stores a computer program
  • the computer program includes program instructions
  • the processor executes the above-mentioned first step.
  • an embodiment of the present application provides a computer program product, the computer program product includes program instructions, and when the program instructions are executed by a processor, the processor executes the above-mentioned first aspect and any optional method of implementation.
  • FIG. 1 is a flow chart of an image cropping method provided in an embodiment of the present application
  • FIG. 2 is a schematic diagram of an example of a first face area and a second face area provided by an embodiment of the present application;
  • FIG. 3 is a schematic diagram of another example of a first human face area and a second human face area provided by an embodiment of the present application;
  • FIG. 4 is a schematic diagram of an example of cropping an original image provided in an embodiment of the present application.
  • FIG. 5 is a schematic diagram of another example of cropping an original image provided by an embodiment of the present application.
  • FIG. 6 is a flow chart of another image cropping method provided in the embodiment of the present application.
  • FIG. 7 is a flowchart of an image distortion correction processing method provided by an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of an image processing device provided by an embodiment of the present application.
  • FIG. 9 is a schematic structural diagram of a server provided by an embodiment of the present application.
  • FIG. 10 is a schematic structural diagram of a terminal device provided in an embodiment of the present application.
  • the present application provides an image cropping method that can accurately crop the edge region with severe distortion in the image, and can better solve the problem of excessive cropping or insufficient cropping of the distortion-corrected image.
  • the image cropping method provided in the embodiment of the present application can be applied to image distortion correction processing scenarios. The following briefly introduces the applicable scenarios of the image cropping method provided by the embodiment of the application.
  • Scenario 1 The user inputs the image to be processed (that is, the image to be processed by distortion correction) to an image processing device (for example, a desktop computer, a notebook computer, a personal computer, etc.); the image processing device performs distortion correction processing on the image to be processed, The image after distortion correction is obtained.
  • the image cropping method provided in this application may be used to crop the image after distortion correction processing.
  • Scenario 2 The user sends the image to be processed (that is, the image to be processed for distortion correction) to the image processing device through a terminal device (such as a desktop computer, a notebook computer, a personal computer, a mobile phone, etc.); the image processing device performs processing on the image to be processed Distortion correction processing to obtain a distortion-corrected image; the image processing device sends the distortion-corrected image to the terminal device.
  • a terminal device such as a desktop computer, a notebook computer, a personal computer, a mobile phone, etc.
  • the image processing device performs processing on the image to be processed Distortion correction processing to obtain a distortion-corrected image
  • the image processing device sends the distortion-corrected image to the terminal device.
  • the image cropping method provided in the present application may be used to crop the distortion-corrected image.
  • the edge region with severe distortion in the image can be cropped out more accurately.
  • FIG. 1 is a flow chart of an image cropping method provided by an embodiment of the present application. As shown in Figure 1, the method includes:
  • An image processing apparatus acquires first face region information.
  • the image processing device may be a terminal device capable of image processing such as a desktop computer, a notebook computer, or a personal computer, or may be a server, such as a cloud server.
  • the first face area information represents the first face area (a rectangular area) in the original image.
  • the original image is a distortion-corrected image.
  • the first face region information includes: vertex coordinates of the first face region and length and width of the first face region.
  • the information of the first human face area includes: the initial coordinates (x, y) of the first human face area, the width and height (w, h) of the first human face area, and the initial coordinates are the The coordinates of the lower left vertex of the face region.
  • the first human face area information includes: the initial coordinates (x, y) of the first human face area, the width and height (w, h) of the first human face area, and the initial coordinates are the The coordinates of the upper right vertex of the first face area.
  • the image processing device may perform face detection on the original image to obtain the first face area. In practical applications, the image processing device may perform face detection on the original image to obtain one (ie, the first face area) or more than one face area. In some embodiments, before performing step 101, the image processing device may perform distortion correction processing on the input image to obtain the original image.
  • the second face area information represents the second face area adjusted from the first face area according to a preset scale factor.
  • the above-mentioned first human face area information includes: the vertex coordinates of the above-mentioned first human face area and the length and width of the above-mentioned first human face area; the implementation of step 102 is as follows: The product of the length and width of the face area and the above-mentioned preset proportional coefficient is used as the length and width of the second face area, and the vertex coordinates, length and width of the first face area are used to determine the size of the second face area. Vertex coordinates. In some embodiments, the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area.
  • the first vertex is any one of an upper left vertex, a lower left vertex, an upper right vertex, and a lower right vertex.
  • the first vertex is any vertex on the third boundary of the second human face area, and the distance between the third boundary of the first human face area and the third boundary of the original image is greater than that of the first human face The distance between the other boundaries of the region and the corresponding boundaries of the original image.
  • the first vertex is the lower right vertex or lower left vertex of the first human face area, and the distance between the upper boundary of the first human face area and the upper boundary of the original image is the distance between the upper boundary of the first human face area and the original image.
  • Fig. 2 is a schematic diagram of an example of a first human face area and a second human face area provided by an embodiment of the present application.
  • the solid-line rectangular frame 201 represents the first human face area
  • the dotted-line rectangular frame 202 represents the second human face area.
  • the lower left vertex of the first human face area is the same as the lower left vertex of the second human face area.
  • FIG. 3 is a schematic diagram of another example of a first human face area and a second human face area provided by an embodiment of the present application.
  • the solid line rectangular frame 301 represents the first human face region
  • the dotted line rectangular frame 302 represents the second human face region
  • the range of the first human face area is adjusted through the preset proportional coefficient k, so as to achieve a reasonable range of the human face area (that is, the range of the second human face area).
  • the adjusted face area (corresponding to the second The size of the face area) should be a function of the combination of the size (width or height) of the current face area (corresponding to the first face area) and the preset proportional coefficient k.
  • the image processing device can determine whether the first human face region triggers the Crop the original image.
  • step 103 is as follows: when the number of pixels of the first border of the second human face area beyond the first border of the original image is greater than the first threshold, the first clipping border is used as the new border of the original image.
  • the above original image is cropped by the first boundary to obtain the above first image.
  • the first boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
  • the above-mentioned first clipping boundary is parallel to the above-mentioned first boundary of the original image.
  • the number of pixels between the first cropping boundary and the first boundary of the original image is equal to the difference between the number of pixels where the first boundary of the second human face region exceeds the first boundary of the original image and the first threshold.
  • the number of pixels of the first boundary of the second human face area beyond the first boundary of the original image is greater than the first threshold is the condition for triggering the first boundary of the original image, that is, determining the new first boundary of the original image and following the new The first boundary condition for clipping the original image. That is to say, if the number of pixels of the first boundary of the second face area beyond the first boundary of the original image is less than or equal to the first threshold, it is not necessary to determine a new first boundary of the original image.
  • FIG. 4 is a schematic diagram of an example of cropping an original image provided by an embodiment of the present application.
  • delta_u represents the difference between the upper boundary of the face area 1 (corresponding to the second face area) beyond the upper boundary of the original image (corresponding to the number of pixels)
  • crop_u_thr represents the upper boundary of the face area 1 How many pixels exceed the upper boundary of the original image is the threshold for cropping
  • c_u represents the number of pixels whose upper boundary of the face area 1 exceeds the upper boundary of the original image.
  • c_u delta_u-crop_u_thr
  • c_u represents the number of pixels to be cropped on the upper boundary.
  • delta_d represents the difference (corresponding to the number of pixels) that the lower boundary of the face area 2 (corresponding to the second face area) exceeds the lower boundary of the original image
  • crop_d_thr indicates that the lower boundary of the face area 2 exceeds the original image.
  • the number of pixels in the lower boundary of the image is the threshold for cropping
  • c_d indicates the number of pixels in which the lower boundary of the face area 2 exceeds the lower boundary of the original image.
  • delta_l represents the difference (corresponding to the number of pixels) that the left boundary of the face area 3 (corresponding to the second face area) exceeds the left boundary of the original image
  • crop_l_thr indicates that the left boundary of the face area 3 exceeds the original image.
  • the number of pixels on the left border of the image is the threshold for cropping, and c_l represents the number of pixels that the left border of the face area 3 exceeds the left border of the original image.
  • delta_r indicates the difference (corresponding to the number of pixels) that the right boundary of the face area 4 (corresponding to the second face area) exceeds the right boundary of the original image
  • crop_r_thr indicates that the right boundary of the face area 4 exceeds the original image
  • the number of pixels on the right border of the image is the threshold for cropping, and c_r represents the number of pixels that the right border of the face area 4 exceeds the right border of the original image.
  • step 103 is as follows: when the distance between the second boundary of the first human face area and the second boundary of the original image is less than a second threshold and the second human face area is located in the original image Next, use the second cropping boundary as a new second boundary of the original image to crop the above-mentioned original image to obtain the above-mentioned first image.
  • the above-mentioned second clipping boundary is the second boundary of the above-mentioned second human face area.
  • the aforementioned second human face area located in the aforementioned original image means that the aforementioned second human face area is included in the aforementioned original image.
  • the second boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
  • the distance between the second boundary of the first human face area and the second boundary of the above-mentioned original image is less than the second threshold and the above-mentioned second human face area is located in the above-mentioned original image is the condition for triggering the cropping of the second boundary of the original image, that is, determining The new second boundary of the original image and the condition of cropping the original image according to the new second boundary. It should be understood that if the distance between the second boundary of the first human face area and the second boundary of the above-mentioned original image is not less than the second threshold or part of the above-mentioned second human face area is not included in the above-mentioned original image, then it is not necessary to Determine the new second boundary of the original image.
  • FIG. 5 is a schematic diagram of another example of cropping an original image provided by an embodiment of the present application.
  • delta_2 represents the distance between the second boundary of the first face region and the second boundary of the original image
  • crop_2_thr represents the distance between the second boundary of the first face region and the second boundary of the original image
  • 501 represents the second clipping boundary. The closer the image is to the edge, the more serious the distortion will be.
  • the area between the second boundary of the second human face area and the second boundary of the original image can be understood as an area with severe distortion, and other areas are areas with light distortion.
  • the original image is cropped using the second cropping boundary as a new second boundary of the original image to obtain the first image.
  • the new second boundary cropping the original image takes into account the size of the first human face area and the distance between the second boundary of the first human face area and the second boundary of the original image, which can be The edges of the image are cropped with reasonable proportions.
  • the method flow in FIG. 1 only shows how to crop the original image according to the first face area. It should be understood that the image processing device may crop the original image according to other face regions in a similar manner. In practical applications, the image processing device may crop the original image one or more times, for example, once for two or more boundaries.
  • the original image is cropped to obtain the first image; the area with severe distortion in the original image can be accurately cropped to avoid excessive cropping or insufficient cropping .
  • FIG. 6 is a flow chart of another image cropping method provided by the embodiment of the present application.
  • the method flow in FIG. 6 is a possible implementation of the method flow in FIG. 1 .
  • the method includes:
  • the image processing apparatus acquires information about one or more face regions.
  • the one or more pieces of face area information acquired by the image processing device may include the above-mentioned first face area information.
  • the image processing device may perform face detection on the original image to obtain one or more face area information.
  • Each face area information may include the starting coordinates of a face area (a rectangular area) and the length and width of the face area.
  • the image processing device sets a preset proportional coefficient.
  • Step 602 is optional, but not necessary.
  • the preset proportional coefficient may be preset, and the user does not need to set the preset proportional coefficient, that is, the preset preset proportional coefficient is adopted.
  • the user can set the preset proportional coefficient according to actual needs.
  • the preset scale factor may be referred to as a face frame expansion factor.
  • the image processing device acquires one or more pieces of extended face area information according to a preset scale factor and one or more pieces of face area information.
  • the second face area information is an extended face area information
  • the first face area information is a face area information.
  • each extended face area information may include the starting coordinates of an extended face area (a rectangular area) and the length and width of the extended face area.
  • Step 102 in FIG. 1 describes a manner of acquiring the above-mentioned second face area information according to the preset scale factor and the above-mentioned first face area information. For the implementation manner of step 603, reference may be made to the implementation manner of step 102.
  • the image processing apparatus determines whether a condition for triggering cropping of an original image is met according to one or more pieces of extended face area information.
  • a possible implementation manner of step 604 may be to respectively judge whether the conditions for triggering the cropping of the boundary (edge) of the original image are met.
  • judging whether the condition for triggering the upper boundary of cropping the original image can be: determining whether the upper boundary of at least one extended human face area is determined in one or more extended human face areas indicated by one or more extended human face area information. The number of pixels whose boundary exceeds the upper boundary of the original image is greater than crop_u_thr; if so, the condition for triggering the cropping of the upper boundary of the original image is met.
  • judging whether the condition for triggering the lower boundary of cropping the original image can be: determining whether the lower boundary of at least one extended human face area in one or more extended human face areas indicated by one or more extended human face area information The number of pixels beyond the lower boundary of the original image is greater than crop_d_thr; if so, the condition for triggering the cropping of the lower boundary of the original image is met.
  • judging whether the condition for triggering the left boundary of the cropped original image can be: determining whether the left boundary of at least one extended human face region is indicated by one or more extended human face regions indicated by one or more extended human face region information The number of pixels beyond the left border of the original image is greater than crop_l_thr; if so, the condition for triggering the cropping of the left border of the original image is met.
  • judging whether the condition for triggering the cropping of the right boundary of the original image can be: determining whether the right boundary of at least one extended human face region is indicated by one or more extended human face regions indicated by one or more extended human face region information The number of pixels beyond the right boundary of the original image is greater than crop_r_thr; if so, the condition for triggering the cropping of the right boundary of the original image is met.
  • the image processing apparatus determines clipping coordinates corresponding to one or more boundaries to be clipped.
  • the one or more to-be-cropped boundaries may be boundaries that meet the conditions for triggering the cropping of the original image. For example, if the image processing device determines that the conditions for triggering the cropping of the upper boundary and the lower boundary of the original image are met, then the upper boundary and the lower boundary of the original image are boundaries to be cropped. In some embodiments, after the image processing device determines that the condition for triggering the cropping of the original image is met, the cropping coordinates corresponding to the boundaries to be cropped can be respectively determined.
  • a boundary to be cropped of the original image is the left boundary
  • a boundary to be cropped of the original image is the lower boundary
  • the image processing device crops the original image according to the clipping coordinates corresponding to one or more boundaries to be cropped, to obtain the first image.
  • the clipping coordinates corresponding to any boundary to be clipped may be understood as coordinates of a new boundary corresponding to the boundary to be clipped.
  • a boundary to be cropped of the original image is the left boundary
  • the cropping coordinates corresponding to the boundary to be cropped are the coordinates of the new left boundary.
  • the image processing device may crop the original image according to the cropping coordinates corresponding to each boundary to be cropped.
  • the image processing apparatus scales the first image to the same size as the original image.
  • the image processing device may perform scaling and interpolation on the cropped original image (corresponding to the first image) according to the width, height, and width-to-height ratio of the original image to obtain the second image;
  • the width, height, and ratio of width to height are the same as those of the above original image, respectively.
  • the edge of the image can be cropped in a reasonable proportion.
  • FIG. 7 is a flowchart of an image distortion correction processing method provided by an embodiment of the present application. As shown in Figure 7, the method includes:
  • the image processing apparatus acquires an input image.
  • step 702 is as follows: select the number of grid points in the horizontal direction and the number of grid points in the vertical direction; The pixel interval between adjacent grid points and the pixel interval between adjacent grid points in the vertical direction; according to the pixel interval between adjacent grid points in the horizontal direction and the pixel interval between adjacent grid points in the vertical direction , divide the input image into grid points; obtain the original coordinates of each grid point in the input image.
  • grid point coordinates refer to coordinates of grid points.
  • the portrait area information (corresponding to the portrait segmentation result) indicates the portrait area (one or more) obtained by subjecting the input image to the portrait segmentation process.
  • the face area information (corresponding to the face detection result) indicates the face area(s) obtained by performing face detection on the input image.
  • the image processing device may calculate the weighting factor in the portrait and face area in any manner, which is not limited in this embodiment of the present application.
  • the distortion correction process While correcting the distortion of the image, it will have certain side effects on the shape of the content in the image. For example, after the distortion correction process is performed on the human face, abnormal deformation will occur, and the original real shape of the original human face will be lost, which will have a great impact on the beauty of the human face.
  • the original distortion is relatively light, it has little influence on the deformation of the image content such as the face.
  • the image content such as the face has a strong deformation effect. Therefore, it is necessary to consider the position difference of the face in the image to correct the face deformation.
  • the sigmoid function distribution can be used.
  • the face distortion correction in the center of the image is weak.
  • the deformation correction is stronger at the edge of the image.
  • the image processing device may input the radial weight factor of the image in any manner, which is not limited in this embodiment of the present application.
  • the image processing device may use the image cropping method provided in this application to crop and scale the image obtained after point-by-point interpolation calculation of each pixel.
  • the distorted image can be effectively corrected, and the side effects on the shape of the image content can be minimized while correcting the distortion of the image.
  • FIG. 8 is a schematic structural diagram of an image processing device provided by an embodiment of the present application. As shown in Figure 8, the image processing device includes:
  • the acquisition unit 801 is used for the first face area information;
  • the first face area information represents the first face area in the original image, and the original image is a distortion-corrected image;
  • the acquisition unit 801 is further configured to acquire second face area information based on the preset scale factor and the first face area information; the second face area information represents that the first face area is adjusted according to the preset scale coefficient The second face area of ;
  • An image cropping unit 802 configured to crop the original image based on the boundary between the second face area and the original image to obtain a first image.
  • the image cropping unit 802 is specifically configured to, when the number of pixels beyond the first boundary of the above-mentioned second human face area beyond the first boundary of the above-mentioned original image is greater than the first threshold, the first A cropping boundary is used as the new first boundary of the original image to crop the above-mentioned original image to obtain the above-mentioned first image; the above-mentioned first cropping boundary is parallel to the first boundary of the above-mentioned original image, and the above-mentioned first cropping boundary is parallel to the first boundary of the above-mentioned original image
  • the number of pixels between the boundaries is equal to the difference between the number of pixels where the first boundary of the second human face area exceeds the first boundary of the original image and the first threshold.
  • the image cropping unit 802 is specifically configured to make the distance between the second boundary of the first human face area and the second boundary of the original image smaller than a second threshold and the second human face
  • the above-mentioned original image is cropped with the second clipping boundary as the new second boundary of the above-mentioned original image to obtain the above-mentioned first image
  • the above-mentioned second clipping boundary is the second boundary of the above-mentioned second human face area .
  • the above-mentioned first face area information includes: the vertex coordinates of the above-mentioned first face area and the length and width of the above-mentioned first face area; The product of the length and width of the human face area and the above-mentioned preset proportional coefficient is used as the length and width of the second human face area, and the above-mentioned second human face area is determined according to the vertex coordinates, length and width of the first human face area vertex coordinates.
  • the above-mentioned apparatus further includes: a processing unit 803, configured to perform scaling and interpolation on the above-mentioned first image according to the width, height, and ratio of width to height of the above-mentioned original image to obtain a second image;
  • the width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of width to height of the original image.
  • the above-mentioned processing unit 803 is further configured to perform distortion correction processing on the input image to obtain the above-mentioned original image.
  • FIG. 9 is a schematic structural diagram of a server provided by an embodiment of the present application.
  • the server 900 may have relatively large differences due to different configurations or performances, and may include one or more CPU922 (for example, one or more processors) and Storage 932, one or more storage media 930 (such as one or more mass storage devices) for storing application programs 942 or data 944 .
  • the memory 932 and the storage medium 930 may be temporary storage or persistent storage.
  • the program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server.
  • the central processing unit 922 may be configured to communicate with the storage medium 930 , and execute a series of instruction operations in the storage medium 930 on the server 900 .
  • the server 900 can execute the image cropping method provided in this application.
  • the server 900 can also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input and output interfaces 958, and/or, one or more operating systems 941, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
  • operating systems 941 such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
  • the steps performed by the image processing apparatus in the above embodiments may be based on the server structure shown in FIG. 9 .
  • the central processing unit 922 can realize the functions of the acquiring unit 801, the image cropping unit 802, and the processing unit 803 in FIG. 8 .
  • FIG. 10 is a schematic structural diagram of a terminal device provided in an embodiment of the present application.
  • the terminal device 100 includes a processor 1001, a memory 1002, a communication interface 1003, and an input and output device 1004; the processor 1001, the memory 1002, and the communication interface 1003 are connected to each other through a bus.
  • the terminal device in FIG. 10 may be the image processing apparatus in the foregoing embodiments.
  • Memory 1002 includes, but is not limited to, random access memory (random access memory, RAM), read-only memory (read-only memory, ROM), erasable programmable read-only memory (erasable programmable read only memory, EPROM), or portable Read-only memory (compact disc read-only memory, CDROM), the memory 1002 is used for related instructions and data.
  • the communication interface 1003 is used to receive and send data.
  • the input and output devices 1004 may include input devices such as keyboards, mice, and touch screens, and output devices such as monitors and screens. The user can input the image to be processed through the input device.
  • the processor 1001 may be one or more central processing units (central processing unit, CPU). In the case where the processor 1001 is a CPU, the CPU may be a single-core CPU or a multi-core CPU. The steps performed by the image processing apparatus in the foregoing embodiments may be based on the structure of the terminal device shown in FIG. 10 . Specifically, the processor 1001 may implement the functions of the acquiring unit 801, the image cropping unit 802, and the processing unit 803 in FIG. 8 .
  • CPU central processing unit
  • a computer-readable storage medium stores a computer program, and when the above-mentioned computer program is executed by a processor, the image cropping method provided in the above-mentioned embodiment is implemented.
  • An embodiment of the present application provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the image cropping method provided in the foregoing embodiments.

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Image Processing (AREA)

Abstract

An image cropping method and a related product. The image cropping method comprises: acquiring first face area information, the first face area information representing a first face area in an original image; acquiring second face area information on the basis of a preset proportion coefficient and the first face area information, the second face area information representing a second face area obtained after the first face area is adjusted according to the preset proportion coefficient; and cropping the original image on the basis of the boundaries of the second face area and the original image to obtain a first image. By means of the method, an area having serious distortion in an original image can be cropped accurately, thereby avoiding excessive cropping or insufficient cropping.

Description

图像裁剪方法及相关产品Image cropping method and related products
[根据细则91更正 15.10.2021] 
本申请要求于2021年8月04日提交中国专利局、申请号为202110890240.3、申请名称为“图像裁剪方法及相关产品”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
[Corrected 15.10.2021 under Rule 91]
This application claims the priority of the Chinese patent application with the application number 202110890240.3 and the application title "Image Cropping Method and Related Products" filed with the China Patent Office on August 04, 2021, the entire contents of which are incorporated by reference in this application.
技术领域technical field
本申请涉及图像处理技术领域,尤其涉及一种图像裁剪方法及相关产品。The present application relates to the technical field of image processing, in particular to an image cropping method and related products.
背景技术Background technique
目前市场上的镜头大概可以分为两种:广角镜头和非广角镜头。采用非广角镜头的产品拍摄的图像的畸变量较小,如手机镜头。采用广角镜头或超广角镜头的产品拍摄的图像的畸变量通常都是非常大,如果不经过畸变校正,几乎是不能看的。图像的畸变主要有两种:径向畸变和切向畸变。径向畸变:正中心位置的畸变最小,随着半径的增大,畸变增大。径向畸变可以分为枕形畸变和桶形畸变。切向畸变是由于透镜本身与相机传感器平面(成像平面)或图像平面不平行而产生的,这种情况多是由于透镜被粘贴到镜头模组上的安装偏差导致。Lenses currently on the market can be roughly divided into two types: wide-angle lenses and non-wide-angle lenses. Images captured by products with non-wide-angle lenses, such as mobile phone lenses, have less distortion. The distortion of images taken by products with wide-angle lenses or ultra-wide-angle lenses is usually very large, and it is almost impossible to see without distortion correction. There are two main types of image distortion: radial distortion and tangential distortion. Radial distortion: The distortion at the center is the smallest, and the distortion increases with the increase of the radius. Radial distortion can be divided into pincushion distortion and barrel distortion. Tangential distortion is caused by the fact that the lens itself is not parallel to the camera sensor plane (imaging plane) or the image plane. This situation is mostly caused by the installation deviation of the lens pasted on the lens module.
在实际应用中,通常需要对图像中人像畸变的现象进行矫正处理(可称为畸变矫正处理)。目前可以通过不同的投影变换等图像处理技术对图像中人像畸变的现象进行矫正处理。对图像中人像畸变的现象进行矫正处理的同时,人像周边的图像内容同样会受到一定程度的影响,例如直线的弯曲等现象。对图像中人像畸变的现象进行矫正处理之后,通常需要进一步对矫正处理后的图像做裁剪以去除矫正处理后的图像中受矫正处理影响的部分图像内容。畸变矫正处理后的图像经过裁剪之后更加自然。目前,采用的裁剪畸变矫正处理后的图像的方式存在裁剪过多或裁剪不足的问题。如何避免裁剪过多或者裁剪不足是目标需要研究的问题。In practical applications, it is usually necessary to correct the phenomenon of portrait distortion in the image (which may be referred to as distortion correction processing). At present, the phenomenon of portrait distortion in the image can be corrected through different image processing techniques such as projection transformation. While correcting the phenomenon of portrait distortion in the image, the image content around the portrait will also be affected to a certain extent, such as the bending of straight lines. After correcting the phenomenon of portrait distortion in the image, it is generally necessary to further crop the corrected image to remove part of the image content in the corrected image that is affected by the correction process. The distortion-corrected image is more natural after being cropped. At present, there is a problem of cropping too much or not cropping enough in the way of cropping and distortion correcting the processed image. How to avoid excessive cropping or insufficient cropping is a problem that needs to be studied by the target.
发明内容Contents of the invention
本申请实施例公开了一种图像裁剪方法及相关产品。The embodiment of the present application discloses an image cropping method and related products.
第一方面,本申请实施例提供一种图像裁剪方法,所述方法包括:获取第一人脸区域信息;所述第一人脸区域信息表征原始图像中的第一人脸区域;基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息;所述第二人脸区域信息表征所述第一人脸区域按照所述预设比例系数调整后的第二人脸区域;基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像。In the first aspect, an embodiment of the present application provides an image cropping method, the method comprising: acquiring first face area information; the first face area information characterizes the first face area in the original image; based on preset Scale factor and the first face area information to obtain second face area information; the second face area information represents the second face adjusted by the first face area according to the preset scale coefficient area: based on the boundary between the second human face area and the original image, crop the original image to obtain a first image.
本申请实施例中,基于第二人脸区域和原始图像的边界,裁剪原始图像,得到第一图像;可以准确地将该原始图像中畸变较严重的区域裁剪掉,避免裁剪过多或者裁剪不足。In the embodiment of the present application, based on the boundary between the second face area and the original image, the original image is cropped to obtain the first image; the area with severe distortion in the original image can be accurately cropped to avoid excessive cropping or insufficient cropping .
在一种可能的实现方式中,所述基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像包括:在所述第二人脸区域的第一边界超出所述原始图像的 第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为所述原始图像新的第一边界裁剪所述原始图像,得到所述第一图像;所述第一裁剪边界与所述原始图像的第一边界平行,所述第一裁剪边界与所述原始图像的第一边界之间的像素个数等于所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数与所述第一阈值之差。所述第一裁剪边界与所述原始图像的第一边界之间的像素个数是指所述第一裁剪边界与所述原始图像的第一边界之间的距离所对应的像素个数。第一边界为左边界、右边界、上边界以及下边界中的任一种。In a possible implementation manner, the cropping the original image based on the boundary between the second face area and the original image to obtain the first image includes: When the number of pixels whose boundary exceeds the first boundary of the original image is greater than a first threshold, use the first cropping boundary as a new first boundary of the original image to crop the original image to obtain the first image; The first cropping boundary is parallel to the first boundary of the original image, and the number of pixels between the first cropping boundary and the first boundary of the original image is equal to the first boundary of the second human face area The difference between the number of pixels beyond the first boundary of the original image and the first threshold. The number of pixels between the first cropping boundary and the first boundary of the original image refers to the number of pixels corresponding to the distance between the first cropping boundary and the first boundary of the original image. The first boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
在该实现方式中,以第一裁剪边界作为原始图像新的第一边界裁剪原始图像,得到第一图像。第一裁剪边界是由第二人脸区域的第一边界超出原始图像的第一边界的像素个数与第一阈值之差决定,该第一裁剪边界综合考虑了第一人脸区域的大小以及第一人脸区域的第一边界与原始图像的第一边界之间的距离,可以对图像的边缘进行合理比例的裁剪。In this implementation manner, the original image is cropped using the first cropping boundary as a new first boundary of the original image to obtain the first image. The first clipping boundary is determined by the difference between the number of pixels that the first boundary of the second human face region exceeds the first boundary of the original image and the first threshold, and the first cropping boundary takes into account the size of the first human face region and The distance between the first boundary of the first human face area and the first boundary of the original image can be used to crop the edge of the image in a reasonable proportion.
在一种可能的实现方式中,所述基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像包括:在所述第一人脸区域的第二边界与所述原始图像的第二边界之间的距离小于第二阈值且所述第二人脸区域位于所述原始图像的情况下,以第二裁剪边界作为所述原始图像新的第二边界裁剪所述原始图像,得到所述第一图像;所述第二裁剪边界为所述第二人脸区域的第二边界。所述第二人脸区域位于所述原始图像是指所述第二人脸区域包含于所述原始图像。第二边界为左边界、右边界、上边界以及下边界中的任一种。In a possible implementation manner, the cropping the original image based on the boundary between the second face area and the original image to obtain the first image includes: When the distance between the boundary and the second boundary of the original image is less than a second threshold and the second face area is located in the original image, the second cropping boundary is used as the new second boundary of the original image cropping the original image to obtain the first image; the second cropping boundary is a second boundary of the second face area. The fact that the second face area is located in the original image means that the second face area is included in the original image. The second boundary is any one of left boundary, right boundary, upper boundary and lower boundary.
图像越靠近边缘的区域畸变越严重。在原始图像中,第二人脸区域的第二边界与该原始图像的第二边界之间的区域可理解为畸变较严重的区域,其他区域为畸变较轻的区域。The closer the image is to the edge, the more serious the distortion will be. In the original image, the area between the second boundary of the second human face area and the second boundary of the original image can be understood as an area with severe distortion, and other areas are areas with light distortion.
在该实现方式中,以第二裁剪边界作为原始图像新的第二边界裁剪原始图像,得到第一图像。以第二裁剪边界作为原始图像新的第二边界裁剪原始图像综合考虑了第一人脸区域的大小以及第一人脸区域的第二边界与原始图像的第二边界之间的距离,可以对图像的边缘进行合理比例的裁剪。In this implementation manner, the original image is cropped using the second cropping boundary as a new second boundary of the original image to obtain the first image. Taking the second cropping boundary as the original image, the new second boundary cropping the original image takes into account the size of the first human face area and the distance between the second boundary of the first human face area and the second boundary of the original image, which can be The edges of the image are cropped with reasonable proportions.
在一种可能的实现方式中,所述第一人脸区域信息包括:所述第一人脸区域的顶点坐标以及所述第一人脸区域的长和宽;所述基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息包括:将所述第一人脸区域的长和宽分别与所述预设比例系数的乘积作为所述第二人脸区域的长和宽,以及根据所述第一人脸区域的顶点坐标、长以及宽确定所述第二人脸区域的顶点坐标。In a possible implementation manner, the first face area information includes: the vertex coordinates of the first face area and the length and width of the first face area; For the first face area information, obtaining the second face area information includes: taking the product of the length and width of the first face area and the preset proportional coefficient as the length of the second face area and width, and determine the vertex coordinates of the second face area according to the vertex coordinates, length and width of the first face area.
在该实现方式中,可以快速、准确地获取第二人脸区域信息。In this implementation manner, the second face region information can be acquired quickly and accurately.
在一种可能的实现方式中,所述第二人脸区域的第一顶点的坐标与所述第一人脸区域的第一顶点的坐标相同。第一顶点为左上顶点、左下顶点、右上顶点、右下顶点中的任一种。所述第一顶点为第二人脸区域的第三边界上的任一顶点,第一人脸区域的第三边界与原始图像的第三边界之间的距离大于第一人脸区域的其他边界与原始图像的相应边界之间的距离。In a possible implementation manner, the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area. The first vertex is any one of an upper left vertex, a lower left vertex, an upper right vertex, and a lower right vertex. The first vertex is any vertex on the third boundary of the second human face area, and the distance between the third boundary of the first human face area and the third boundary of the original image is greater than other boundaries of the first human face area The distance from the corresponding border of the original image.
在一种可能的实现方式中,所述第二人脸区域的中心点的坐标与所述第一人脸区域的中心点的坐标相同。In a possible implementation manner, the coordinates of the center point of the second face area are the same as the coordinates of the center point of the first face area.
在一种可能的实现方式中,在基于所述第二人脸区域和所述原始图像的边界,裁剪所 述原始图像,得到第一图像之后,所述方法还包括:根据所述原始图像的宽、高以及宽与高的比例对所述第一图像进行缩放插值,得到第二图像;所述第二图像的宽、高以及宽与高的比例分别与所述原始图像的宽、高以及宽与高的比例相同。In a possible implementation manner, after the original image is cropped based on the boundary of the second human face area and the original image to obtain the first image, the method further includes: Width, height and the ratio of width to height are scaled and interpolated to the first image to obtain a second image; the width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of the original image The ratio of width to height is the same.
在该实现方式中,根据原始图像的宽、高以及宽与高的比例对第一图像进行缩放插值,得到第二图像;能够由裁剪后的第一图像得到与原始图像的宽、高以及宽与高的比例均相同的第二图像。In this implementation, the first image is scaled and interpolated according to the width, height and ratio of width and height of the original image to obtain the second image; the width, height and width of the original image can be obtained from the cropped first image The second image is the same with high proportions.
在一种可能的实现方式中,所述方法还包括:对输入图像做畸变矫正处理,得到所述原始图像。In a possible implementation manner, the method further includes: performing distortion correction processing on the input image to obtain the original image.
第二方面,本申请实施例提供一种图像处理装置,包括:获取单元,用于第一人脸区域信息;所述第一人脸区域信息表征原始图像中的第一人脸区域;所述获取单元,还用于基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息;所述第二人脸区域信息表征所述第一人脸区域按照所述预设比例系数调整后的第二人脸区域;图像裁剪单元,用于基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像。In a second aspect, an embodiment of the present application provides an image processing device, including: an acquisition unit, configured to first face area information; the first face area information represents a first face area in an original image; the The acquisition unit is further configured to acquire second face area information based on a preset scale factor and the first face area information; the second face area information indicates that the first face area is in accordance with the preset The second human face area after the scale factor has been adjusted; an image cropping unit, configured to crop the original image based on the boundary between the second human face area and the original image to obtain the first image.
在一种可能的实现方式中,所述图像裁剪单元,具体用于在所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为所述原始图像新的第一边界裁剪所述原始图像,得到所述第一图像;所述第一裁剪边界与所述原始图像的第一边界平行,所述第一裁剪边界与所述原始图像的第一边界之间的像素个数等于所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数与所述第一阈值之差。In a possible implementation manner, the image cropping unit is specifically configured to: when the number of pixels in which the first boundary of the second face area exceeds the first boundary of the original image is greater than a first threshold , using the first cropping boundary as the new first boundary of the original image to crop the original image to obtain the first image; the first cropping boundary is parallel to the first boundary of the original image, and the first The number of pixels between the cropping boundary and the first boundary of the original image is equal to the difference between the number of pixels where the first boundary of the second face area exceeds the first boundary of the original image and the first threshold .
在一种可能的实现方式中,所述图像裁剪单元,具体用于在所述第一人脸区域的第二边界与所述原始图像的第二边界之间的距离小于第二阈值且所述第二人脸区域位于所述原始图像的情况下,以第二裁剪边界作为所述原始图像新的第二边界裁剪所述原始图像,得到所述第一图像;所述第二裁剪边界为所述第二人脸区域的第二边界。In a possible implementation manner, the image cropping unit is specifically configured to make the distance between the second boundary of the first face area and the second boundary of the original image smaller than a second threshold and the In the case where the second human face area is located in the original image, the original image is cropped with the second crop boundary as the new second boundary of the original image to obtain the first image; the second crop boundary is the Describe the second boundary of the second face area.
在一种可能的实现方式中,所述第一人脸区域信息包括:所述第一人脸区域的顶点坐标以及所述第一人脸区域的长和宽;所述获取单元,具体用于将所述第一人脸区域的长和宽分别与所述预设比例系数的乘积作为所述第二人脸区域的长和宽,以及根据所述第一人脸区域的顶点坐标、长以及宽确定所述第二人脸区域的顶点坐标。In a possible implementation manner, the first face area information includes: the vertex coordinates of the first face area and the length and width of the first face area; Taking the product of the length and width of the first human face area and the preset proportional coefficient as the length and width of the second human face area, and according to the vertex coordinates, length and Width determines the vertex coordinates of the second face area.
在一种可能的实现方式中,所述第二人脸区域的第一顶点的坐标与所述第一人脸区域的第一顶点的坐标相同。In a possible implementation manner, the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area.
在一种可能的实现方式中,所述第二人脸区域的中心点的坐标与所述第一人脸区域的中心点的坐标相同。In a possible implementation manner, the coordinates of the center point of the second face area are the same as the coordinates of the center point of the first face area.
在一种可能的实现方式中,所述装置还包括:处理单元,用于根据所述原始图像的宽、高以及宽与高的比例对所述第一图像进行缩放插值,得到第二图像;所述第二图像的宽、高以及宽与高的比例分别与所述原始图像的宽、高以及宽与高的比例相同。In a possible implementation manner, the device further includes: a processing unit configured to perform scaling and interpolation on the first image according to the width, height, and ratio of width to height of the original image to obtain a second image; The width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of width to height of the original image.
在一种可能的实现方式中,所述处理单元,还用于对输入图像做畸变矫正处理,得到所述原始图像。In a possible implementation manner, the processing unit is further configured to perform distortion correction processing on the input image to obtain the original image.
关于第二方面或各种可选的实施方式所带来的技术效果,可参考对于第一方面或相应的实现方式的技术效果的介绍。Regarding the technical effects brought about by the second aspect or various optional implementation manners, reference may be made to the introduction to the technical effects of the first aspect or corresponding implementation manners.
第三方面,本申请实施例提供了一种图像处理装置,该图像处理装置包括:处理器和存储器,其中,所述存储器用于存储指令,所述处理器用于执行所述存储器存储的指令,使得所述处理器执行如上述第一方面以及任一种可能的实现方式的方法。In a third aspect, an embodiment of the present application provides an image processing device, the image processing device includes: a processor and a memory, wherein the memory is used to store instructions, and the processor is used to execute the instructions stored in the memory, The processor is made to execute the method according to the above first aspect and any possible implementation manner.
第四方面,本申请实施例提供了一种芯片,该芯片包括数据接口和处理器,其中,所述处理器用于执行第一方面或第一方面的任意可能的实现方式中的方法。In a fourth aspect, an embodiment of the present application provides a chip, where the chip includes a data interface and a processor, where the processor is configured to execute the method in the first aspect or any possible implementation manner of the first aspect.
第五方面,本申请实施例提供了一种计算机可读存储介质,该计算机存储介质存储有计算机程序,该计算机程序包括程序指令,该程序指令当被处理器执行时使该处理器执行上述第一方面以及上述第一方面任一种可选的实现方式的方法。In the fifth aspect, the embodiment of the present application provides a computer-readable storage medium, the computer storage medium stores a computer program, the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the above-mentioned first step. One aspect and any optional implementation method of the first aspect above.
第六方面,本申请实施例提供了一种计算机程序产品,该计算机程序产品包括程序指令,所述程序指令当被处理器执行时使所述处理器执行上述第一方面以及任一种可选的实现方式的方法。In a sixth aspect, an embodiment of the present application provides a computer program product, the computer program product includes program instructions, and when the program instructions are executed by a processor, the processor executes the above-mentioned first aspect and any optional method of implementation.
附图说明Description of drawings
为了更清楚地说明本申请实施例或背景技术中的技术方案,下面将对本申请实施例或背景技术中所需要使用的附图进行说明。In order to more clearly illustrate the technical solutions in the embodiment of the present application or the background art, the following will describe the drawings that need to be used in the embodiment of the present application or the background art.
图1为本申请实施例提供的一种图像裁剪方法流程图;FIG. 1 is a flow chart of an image cropping method provided in an embodiment of the present application;
图2为本申请实施例提供的一种第一人脸区域和第二人脸区域的示例的示意图;FIG. 2 is a schematic diagram of an example of a first face area and a second face area provided by an embodiment of the present application;
图3为本申请实施例提供的另一种第一人脸区域和第二人脸区域的示例的示意图;FIG. 3 is a schematic diagram of another example of a first human face area and a second human face area provided by an embodiment of the present application;
图4为本申请实施例提供的一种裁剪原始图像的示例的示意图;FIG. 4 is a schematic diagram of an example of cropping an original image provided in an embodiment of the present application;
图5为本申请实施例提供的另一种裁剪原始图像的示例的示意图;FIG. 5 is a schematic diagram of another example of cropping an original image provided by an embodiment of the present application;
图6为本申请实施例提供的另一种图像裁剪方法流程图;FIG. 6 is a flow chart of another image cropping method provided in the embodiment of the present application;
图7为本申请实施例提供的一种图像畸变矫正处理方法流程图;FIG. 7 is a flowchart of an image distortion correction processing method provided by an embodiment of the present application;
图8为本申请实施例提供的一种图像处理装置的结构示意图;FIG. 8 is a schematic structural diagram of an image processing device provided by an embodiment of the present application;
图9是本申请实施例提供的一种服务器的结构示意图;FIG. 9 is a schematic structural diagram of a server provided by an embodiment of the present application;
图10为本申请实施例提供的一种终端设备的结构示意图。FIG. 10 is a schematic structural diagram of a terminal device provided in an embodiment of the present application.
具体实施方式Detailed ways
本申请的说明书、权利要求书及附图中的术语“第一”和“第二”等仅用于区别不同对象,而不是用于描述特定顺序。此外,术语“包括”和“具有”以及它们的任何变形,意图在于覆盖不排他的包含。例如包含了一系列步骤或单元的过程、方法、系统、产品或设备等,没有限定于已列出的步骤或单元,而是可选地还包括没有列出的步骤或单元等,或可选地还包括对于这些过程、方法、产品或设备等固有的其它步骤或单元。The terms "first" and "second" in the specification, claims and drawings of the present application are only used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally It also includes other steps or units inherent to these processes, methods, products, or devices.
本申请以下实施例中所使用的术语只是为了描述特定实施例的目的,而并非旨在作为对本申请的限制。如在本申请的说明书和所附权利要求书中所使用的那样,单数表达形式“一个”、“一种”、“上述”、“上述”、“该”和“这一”旨在也包括复数表达形式,除非其上下文中明确地有相反指示。还应当理解,本申请中使用的术语“和/或”是指并包含一个或多个所列出项目的任何或所有可能组合。例如,“A和/或B”可以表示:只存在A,只存 在B以及同时存在A和B三种情况,其中A,B可以是单数或者复数。本申请中使用的术语“多个”是指两个或两个以上。The terms used in the following embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. As used in the specification and appended claims of this application, the singular expressions "a", "an", "above", "aforementioned", "the" and "this" are intended to include Plural expressions, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in this application refers to and includes any and all possible combinations of one or more of the listed items. For example, "A and/or B" can mean: there are only A, only B, and both A and B, where A and B can be singular or plural. The term "plurality" as used in this application means two or more.
为解决对畸变矫正处理后的图像裁剪过多或裁剪不足的问题。本申请提供了一种可以较准确地将图像中畸变较严重的边缘区域裁剪掉的图像裁剪方法,能够较好地解决对畸变矫正处理后的图像裁剪过多或裁剪不足的问题。本申请实施例提供的图像裁剪方法可应用于图像畸变矫正处理场景。下面分别对申请实施例提供的图像裁剪方法适用的场景进行简单的介绍。In order to solve the problem of excessive cropping or insufficient cropping of the image processed by distortion correction. The present application provides an image cropping method that can accurately crop the edge region with severe distortion in the image, and can better solve the problem of excessive cropping or insufficient cropping of the distortion-corrected image. The image cropping method provided in the embodiment of the present application can be applied to image distortion correction processing scenarios. The following briefly introduces the applicable scenarios of the image cropping method provided by the embodiment of the application.
场景1:用户将待处理图像(即待做畸变矫正处理的图像)输入至图像处理装置(例如,台式电脑、笔记本电脑、个人计算机等);图像处理装置对该待处理图像做畸变矫正处理,得到畸变矫正处理后的图像。在场景1中,图像处理装置在对待处理图像做畸变矫正处理之后,可采用本申请提供的图像裁剪方法对畸变矫正处理后的图像做裁剪。Scenario 1: The user inputs the image to be processed (that is, the image to be processed by distortion correction) to an image processing device (for example, a desktop computer, a notebook computer, a personal computer, etc.); the image processing device performs distortion correction processing on the image to be processed, The image after distortion correction is obtained. In scenario 1, after the image processing device performs distortion correction processing on the image to be processed, the image cropping method provided in this application may be used to crop the image after distortion correction processing.
场景2:用户通过终端设备(例如台式电脑、笔记本电脑、个人计算机、手机等)将待处理图像(即待做畸变矫正处理的图像)发送给图像处理装置;图像处理装置对该待处理图像做畸变矫正处理,得到畸变矫正处理后的图像;图像处理装置将畸变矫正处理后的图像发送给终端设备。在场景2中,图像处理装置在对待处理图像做畸变矫正处理之后,可采用本申请提供的图像裁剪方法对畸变矫正处理后的图像做裁剪。Scenario 2: The user sends the image to be processed (that is, the image to be processed for distortion correction) to the image processing device through a terminal device (such as a desktop computer, a notebook computer, a personal computer, a mobile phone, etc.); the image processing device performs processing on the image to be processed Distortion correction processing to obtain a distortion-corrected image; the image processing device sends the distortion-corrected image to the terminal device. In scenario 2, after the image processing device performs distortion correction processing on the image to be processed, the image cropping method provided in the present application may be used to crop the distortion-corrected image.
在上述场景中,通过实施本申请实施例提供的图像裁剪方法,可以较准确地将图像中畸变较严重的边缘区域裁剪掉。In the above scenario, by implementing the image cropping method provided in the embodiment of the present application, the edge region with severe distortion in the image can be cropped out more accurately.
下面结合附图来介绍本申请实施例提供的图像裁剪方法。The image cropping method provided by the embodiment of the present application will be described below with reference to the accompanying drawings.
图1为本申请实施例提供的一种图像裁剪方法流程图。如图1所示,该方法包括:FIG. 1 is a flow chart of an image cropping method provided by an embodiment of the present application. As shown in Figure 1, the method includes:
101、图像处理装置获取第一人脸区域信息。101. An image processing apparatus acquires first face region information.
图像处理装置可以是台式电脑、笔记本电脑、个人计算机等具备图像处理能力的终端设备,也可以是服务器,例如云服务器。The image processing device may be a terminal device capable of image processing such as a desktop computer, a notebook computer, or a personal computer, or may be a server, such as a cloud server.
第一人脸区域信息表征原始图像中的第一人脸区域(一个矩形区域)。在一些实施例中,原始图像为畸变矫正处理后的图像。在一个可能的实现方式中,第一人脸区域信息包括:第一人脸区域的顶点坐标以及第一人脸区域的长和宽。例如,第一人脸区域信息包括:第一人脸区域的起始坐标(x,y),该第一人脸区域的宽和高(w,h),该起始坐标为该第一人脸区域的左下顶点的坐标。又例如,例如,第一人脸区域信息包括:第一人脸区域的起始坐标(x,y),该第一人脸区域的宽和高(w,h),该起始坐标为该第一人脸区域的右上顶点的坐标。The first face area information represents the first face area (a rectangular area) in the original image. In some embodiments, the original image is a distortion-corrected image. In a possible implementation manner, the first face region information includes: vertex coordinates of the first face region and length and width of the first face region. For example, the information of the first human face area includes: the initial coordinates (x, y) of the first human face area, the width and height (w, h) of the first human face area, and the initial coordinates are the The coordinates of the lower left vertex of the face region. For another example, for example, the first human face area information includes: the initial coordinates (x, y) of the first human face area, the width and height (w, h) of the first human face area, and the initial coordinates are the The coordinates of the upper right vertex of the first face area.
在一些实施例中,图像处理装置在执行步骤101之前,可对原始图像进行人脸检测,得到第一人脸区域。在实际应用中,图像处理装置可对原始图像进行人脸检测得到一个(即第一人脸区域)或一个以上人脸区域。在一些实施例中,图像处理装置在执行步骤101之前,可对输入图像做畸变矫正处理得到原始图像。In some embodiments, before performing step 101, the image processing device may perform face detection on the original image to obtain the first face area. In practical applications, the image processing device may perform face detection on the original image to obtain one (ie, the first face area) or more than one face area. In some embodiments, before performing step 101, the image processing device may perform distortion correction processing on the input image to obtain the original image.
102、基于预设比例系数和第一人脸区域信息,获取第二人脸区域信息。102. Acquire second face area information based on a preset scale factor and first face area information.
第二人脸区域信息表征第一人脸区域按照预设比例系数调整后的第二人脸区域。The second face area information represents the second face area adjusted from the first face area according to a preset scale factor.
在一个可能的实现方式中,上述第一人脸区域信息包括:上述第一人脸区域的顶点坐标以及上述第一人脸区域的长和宽;步骤102的实现方式如下:将上述第一人脸区域的长 和宽分别与上述预设比例系数的乘积作为上述第二人脸区域的长和宽,以及根据上述第一人脸区域的顶点坐标、长以及宽确定上述第二人脸区域的顶点坐标。在一些实施例中,第二人脸区域的第一顶点的坐标与第一人脸区域的第一顶点的坐标相同。第一顶点为左上顶点、左下顶点、右上顶点、右下顶点中的任一种。在一些实施例中,第一顶点为第二人脸区域的第三边界上的任一顶点,第一人脸区域的第三边界与原始图像的第三边界之间的距离大于第一人脸区域的其他边界与原始图像的相应边界之间的距离。例如,第一顶点为第一人脸区域的右下顶点或左下顶点,第一人脸区域的上边界与原始图像的上边界之间的距离是第一人脸区域的上边界与原始图像的上边界之间的距离、第一人脸区域的下边界与原始图像的下边界之间的距离、第一人脸区域的左边界与原始图像的左边界之间的距离以及第一人脸区域的右边界与原始图像的右边界之间的距离中最大的。图2为本申请实施例提供的一种第一人脸区域和第二人脸区域的示例的示意图。图2中,实线矩形框201表示第一人脸区域,虚线矩形框202表示第二人脸区域,该第一人脸区域的左下顶点和该第二人脸区域的左下顶点相同。在一些实施例中,上述第二人脸区域的中心点的坐标与上述第一人脸区域的中心点的坐标相同。图3为本申请实施例提供的另一种第一人脸区域和第二人脸区域的示例的示意图。图3中,实线矩形框301表示第一人脸区域,虚线矩形框302表示第二人脸区域,该第一人脸区域的中心点的坐标和该第二人脸区域的中心点的坐标相同。In a possible implementation, the above-mentioned first human face area information includes: the vertex coordinates of the above-mentioned first human face area and the length and width of the above-mentioned first human face area; the implementation of step 102 is as follows: The product of the length and width of the face area and the above-mentioned preset proportional coefficient is used as the length and width of the second face area, and the vertex coordinates, length and width of the first face area are used to determine the size of the second face area. Vertex coordinates. In some embodiments, the coordinates of the first vertex of the second face area are the same as the coordinates of the first vertex of the first face area. The first vertex is any one of an upper left vertex, a lower left vertex, an upper right vertex, and a lower right vertex. In some embodiments, the first vertex is any vertex on the third boundary of the second human face area, and the distance between the third boundary of the first human face area and the third boundary of the original image is greater than that of the first human face The distance between the other boundaries of the region and the corresponding boundaries of the original image. For example, the first vertex is the lower right vertex or lower left vertex of the first human face area, and the distance between the upper boundary of the first human face area and the upper boundary of the original image is the distance between the upper boundary of the first human face area and the original image. The distance between the upper border, the distance between the lower border of the first face area and the lower border of the original image, the distance between the left border of the first face area and the left border of the original image, and the distance between the first face area The largest of the distances between the right border of and the right border of the original image. Fig. 2 is a schematic diagram of an example of a first human face area and a second human face area provided by an embodiment of the present application. In FIG. 2 , the solid-line rectangular frame 201 represents the first human face area, and the dotted-line rectangular frame 202 represents the second human face area. The lower left vertex of the first human face area is the same as the lower left vertex of the second human face area. In some embodiments, the coordinates of the center point of the second human face area are the same as the coordinates of the center point of the first human face area. FIG. 3 is a schematic diagram of another example of a first human face area and a second human face area provided by an embodiment of the present application. In Fig. 3, the solid line rectangular frame 301 represents the first human face region, the dotted line rectangular frame 302 represents the second human face region, the coordinates of the center point of the first human face region and the coordinates of the center point of the second human face region same.
在该实现方式中,通过预设比例系数k,调整第一人脸区域的范围,从而达到一个合理的人脸区域范围(即第二人脸区域的范围)。鉴于人脸距离镜头远近存在尺度的变换(距离镜头较近的人脸区域所占像素较多,距离镜头较远的人脸所占像素较少),调整后的人脸区域(对应于第二人脸区域)的尺寸应当为当前该人脸区域(对应于第一人脸区域)的尺寸(宽度或高度)与该预设比例系数k组合的函数。In this implementation manner, the range of the first human face area is adjusted through the preset proportional coefficient k, so as to achieve a reasonable range of the human face area (that is, the range of the second human face area). In view of the scale transformation of the distance between the face and the camera (the face area closer to the camera occupies more pixels, and the face farther away from the camera occupies less pixels), the adjusted face area (corresponding to the second The size of the face area) should be a function of the combination of the size (width or height) of the current face area (corresponding to the first face area) and the preset proportional coefficient k.
103、基于第二人脸区域和原始图像的边界,裁剪原始图像,得到第一图像。103. Based on the boundary between the second face area and the original image, crop the original image to obtain the first image.
在一些实施例中,图像处理装置可通过对比第二人脸区域和原始图像之间的位置关系以及对比两者之间对应边界之间的距离和预设阈值,判定第一人脸区域是否触发裁剪原始图像。In some embodiments, the image processing device can determine whether the first human face region triggers the Crop the original image.
步骤103一种可能的实现方式如下:在第二人脸区域的第一边界超出原始图像的第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为上述原始图像新的第一边界裁剪上述原始图像,得到上述第一图像。第一边界为左边界、右边界、上边界以及下边界中的任一种。上述第一裁剪边界与上述原始图像的第一边界平行。上述第一裁剪边界与上述原始图像的第一边界之间的像素个数等于上述第二人脸区域的第一边界超出上述原始图像的第一边界的像素个数与上述第一阈值之差。上述第二人脸区域的第一边界超出上述原始图像的第一边界的像素个数大于第一阈值是触发裁剪原始图像的第一边界的条件,即确定原始图像新的第一边界并按照新的第一边界裁剪原始图像的条件。也就是说,若第二人脸区域的第一边界超出上述原始图像的第一边界的像素个数小于或等于第一阈值,不需要确定原始图像新的第一边界。A possible implementation of step 103 is as follows: when the number of pixels of the first border of the second human face area beyond the first border of the original image is greater than the first threshold, the first clipping border is used as the new border of the original image. The above original image is cropped by the first boundary to obtain the above first image. The first boundary is any one of left boundary, right boundary, upper boundary and lower boundary. The above-mentioned first clipping boundary is parallel to the above-mentioned first boundary of the original image. The number of pixels between the first cropping boundary and the first boundary of the original image is equal to the difference between the number of pixels where the first boundary of the second human face region exceeds the first boundary of the original image and the first threshold. The number of pixels of the first boundary of the second human face area beyond the first boundary of the original image is greater than the first threshold is the condition for triggering the first boundary of the original image, that is, determining the new first boundary of the original image and following the new The first boundary condition for clipping the original image. That is to say, if the number of pixels of the first boundary of the second face area beyond the first boundary of the original image is less than or equal to the first threshold, it is not necessary to determine a new first boundary of the original image.
图4为本申请实施例提供的一种裁剪原始图像的示例的示意图。如图4所示,delta_u表示人脸区域1(对应于第二人脸区域)的上边界超出原始图像的上边界的差值(对应于像素个数),crop_u_thr表示人脸区域1的上边界超出原始图像的上边界多少像素即进行裁 剪的阈值,c_u表示人脸区域1的上边界超出原始图像的上边界的像素个数。c_u=delta_u-crop_u_thr,c_u表示上边界所需裁剪的像素个数。同理,delta_d表示人脸区域2(对应于第二人脸区域)的下边界超出原始图像的下边界的差值(对应于像素个数),crop_d_thr表示人脸区域2的下边界超出该原始图像的下边界多少像素即进行裁剪的阈值,c_d表示人脸区域2的下边界超出原始图像的下边界的像素个数。同理,delta_l表示人脸区域3(对应于第二人脸区域)的左边界超出原始图像的左边界的差值(对应于像素个数),crop_l_thr表示人脸区域3的左边界超出该原始图像的左边界多少像素即进行裁剪的阈值,c_l表示人脸区域3的左边界超出原始图像的左边界的像素个数。同理,delta_r表示人脸区域4(对应于第二人脸区域)的右边界超出原始图像的右边界的差值(对应于像素个数),crop_r_thr表示人脸区域4的右边界超出该原始图像的右边界多少像素即进行裁剪的阈值,c_r表示人脸区域4的右边界超出原始图像的右边界的像素个数。FIG. 4 is a schematic diagram of an example of cropping an original image provided by an embodiment of the present application. As shown in Figure 4, delta_u represents the difference between the upper boundary of the face area 1 (corresponding to the second face area) beyond the upper boundary of the original image (corresponding to the number of pixels), crop_u_thr represents the upper boundary of the face area 1 How many pixels exceed the upper boundary of the original image is the threshold for cropping, and c_u represents the number of pixels whose upper boundary of the face area 1 exceeds the upper boundary of the original image. c_u=delta_u-crop_u_thr, c_u represents the number of pixels to be cropped on the upper boundary. Similarly, delta_d represents the difference (corresponding to the number of pixels) that the lower boundary of the face area 2 (corresponding to the second face area) exceeds the lower boundary of the original image, and crop_d_thr indicates that the lower boundary of the face area 2 exceeds the original image. The number of pixels in the lower boundary of the image is the threshold for cropping, and c_d indicates the number of pixels in which the lower boundary of the face area 2 exceeds the lower boundary of the original image. Similarly, delta_l represents the difference (corresponding to the number of pixels) that the left boundary of the face area 3 (corresponding to the second face area) exceeds the left boundary of the original image, and crop_l_thr indicates that the left boundary of the face area 3 exceeds the original image. The number of pixels on the left border of the image is the threshold for cropping, and c_l represents the number of pixels that the left border of the face area 3 exceeds the left border of the original image. Similarly, delta_r indicates the difference (corresponding to the number of pixels) that the right boundary of the face area 4 (corresponding to the second face area) exceeds the right boundary of the original image, and crop_r_thr indicates that the right boundary of the face area 4 exceeds the original image The number of pixels on the right border of the image is the threshold for cropping, and c_r represents the number of pixels that the right border of the face area 4 exceeds the right border of the original image.
步骤103一种可能的实现方式如下:在上述第一人脸区域的第二边界与上述原始图像的第二边界之间的距离小于第二阈值且上述第二人脸区域位于上述原始图像的情况下,以第二裁剪边界作为上述原始图像新的第二边界裁剪上述原始图像,得到上述第一图像。上述第二裁剪边界为上述第二人脸区域的第二边界。上述第二人脸区域位于上述原始图像是指上述第二人脸区域包含于上述原始图像。第二边界为左边界、右边界、上边界以及下边界中的任一种。第一人脸区域的第二边界与上述原始图像的第二边界之间的距离小于第二阈值且上述第二人脸区域位于上述原始图像是触发裁剪原始图像的第二边界的条件,即确定原始图像新的第二边界并按照新的第二边界裁剪原始图像的条件。应理解,若第一人脸区域的第二边界与上述原始图像的第二边界之间的距离不小于第二阈值或者上述第二人脸区域的部分区域未包含于上述原始图像,则不需要确定原始图像新的第二边界。A possible implementation of step 103 is as follows: when the distance between the second boundary of the first human face area and the second boundary of the original image is less than a second threshold and the second human face area is located in the original image Next, use the second cropping boundary as a new second boundary of the original image to crop the above-mentioned original image to obtain the above-mentioned first image. The above-mentioned second clipping boundary is the second boundary of the above-mentioned second human face area. The aforementioned second human face area located in the aforementioned original image means that the aforementioned second human face area is included in the aforementioned original image. The second boundary is any one of left boundary, right boundary, upper boundary and lower boundary. The distance between the second boundary of the first human face area and the second boundary of the above-mentioned original image is less than the second threshold and the above-mentioned second human face area is located in the above-mentioned original image is the condition for triggering the cropping of the second boundary of the original image, that is, determining The new second boundary of the original image and the condition of cropping the original image according to the new second boundary. It should be understood that if the distance between the second boundary of the first human face area and the second boundary of the above-mentioned original image is not less than the second threshold or part of the above-mentioned second human face area is not included in the above-mentioned original image, then it is not necessary to Determine the new second boundary of the original image.
图5为本申请实施例提供的另一种裁剪原始图像的示例的示意图。如图5所示,delta_2表示第一人脸区域的第二边界与原始图像的第二边界之间的距离,crop_2_thr表示第一人脸区域的第二边界与该原始图像的第二边界之间的像素个数少于多少即进行裁剪的阈值,501表示第二裁剪边界。图像越靠近边缘的区域畸变越严重。在原始图像中,第二人脸区域的第二边界与该原始图像的第二边界之间的区域可理解为畸变较严重的区域,其他区域为畸变较轻的区域。在该实现方式中,以第二裁剪边界作为原始图像新的第二边界裁剪原始图像,得到第一图像。以第二裁剪边界作为原始图像新的第二边界裁剪原始图像综合考虑了第一人脸区域的大小以及第一人脸区域的第二边界与原始图像的第二边界之间的距离,可以对图像的边缘进行合理比例的裁剪。FIG. 5 is a schematic diagram of another example of cropping an original image provided by an embodiment of the present application. As shown in Figure 5, delta_2 represents the distance between the second boundary of the first face region and the second boundary of the original image, crop_2_thr represents the distance between the second boundary of the first face region and the second boundary of the original image The number of pixels of is less than the threshold for clipping, and 501 represents the second clipping boundary. The closer the image is to the edge, the more serious the distortion will be. In the original image, the area between the second boundary of the second human face area and the second boundary of the original image can be understood as an area with severe distortion, and other areas are areas with light distortion. In this implementation manner, the original image is cropped using the second cropping boundary as a new second boundary of the original image to obtain the first image. Taking the second cropping boundary as the original image, the new second boundary cropping the original image takes into account the size of the first human face area and the distance between the second boundary of the first human face area and the second boundary of the original image, which can be The edges of the image are cropped with reasonable proportions.
图1的方法流程仅示出了根据第一人脸区域裁剪原始图像的方式。应理解,图像处理装置可采用类似的方式根据其他人脸区域对原始图像做裁剪。在实际应用中,图像处理装置可裁剪原始图像的一次或多次,例如针对两个或两个以上边界均裁剪一次。The method flow in FIG. 1 only shows how to crop the original image according to the first face area. It should be understood that the image processing device may crop the original image according to other face regions in a similar manner. In practical applications, the image processing device may crop the original image one or more times, for example, once for two or more boundaries.
本申请实施例中,基于第二人脸区域和原始图像的边界,裁剪原始图像,得到第一图像;可以准确地将该原始图像中畸变较严重的区域裁剪掉,避免裁剪过多或者裁剪不足。In the embodiment of the present application, based on the boundary between the second face area and the original image, the original image is cropped to obtain the first image; the area with severe distortion in the original image can be accurately cropped to avoid excessive cropping or insufficient cropping .
图6为本申请实施例提供的另一种图像裁剪方法流程图。图6中的方法流程是图1中的方法流程的一种可能的实现方式。如图6所示,该方法包括:FIG. 6 is a flow chart of another image cropping method provided by the embodiment of the present application. The method flow in FIG. 6 is a possible implementation of the method flow in FIG. 1 . As shown in Figure 6, the method includes:
601、图像处理装置获取一个或多个人脸区域信息。601. The image processing apparatus acquires information about one or more face regions.
图像处理装置获取的一个或多个人脸区域信息可包括上述第一人脸区域信息。在一些实施例中,图像处理装置可对原始图像做人脸检测,得到一个或多个人脸区域信息。每个人脸区域信息可包括一个人脸区域(一个矩形区域)的起始坐标以及该人脸区域的长和宽。The one or more pieces of face area information acquired by the image processing device may include the above-mentioned first face area information. In some embodiments, the image processing device may perform face detection on the original image to obtain one or more face area information. Each face area information may include the starting coordinates of a face area (a rectangular area) and the length and width of the face area.
602、图像处理装置设置预设比例系数。602. The image processing device sets a preset proportional coefficient.
步骤602是可选的,而非必要的。在一些实施例中,预设比例系数可以是预先设置的,用户不必设置预设比例系数,即采用预先设置的预设比例系数。在一些实施例中,用户可根据实际需求自行设置预设比例系数。预设比例系数可称为人脸框扩展系数。Step 602 is optional, but not necessary. In some embodiments, the preset proportional coefficient may be preset, and the user does not need to set the preset proportional coefficient, that is, the preset preset proportional coefficient is adopted. In some embodiments, the user can set the preset proportional coefficient according to actual needs. The preset scale factor may be referred to as a face frame expansion factor.
603、图像处理装置根据预设比例系数和一个或多个人脸区域信息,获取一个或多个扩展人脸区域信息。603. The image processing device acquires one or more pieces of extended face area information according to a preset scale factor and one or more pieces of face area information.
上述第二人脸区域信息为一个扩展人脸区域信息,上述第一人脸区域信息为一个人脸区域信息。例如,每个扩展人脸区域信息可包括一个扩展人脸区域(一个矩形区域)的起始坐标以及该扩展人脸区域的长和宽。图1中的步骤102描述了根据预设比例系数和上述第一人脸区域信息,获取上述第二人脸区域信息的方式。步骤603的实现方式可参阅步骤102的实现方式。The second face area information is an extended face area information, and the first face area information is a face area information. For example, each extended face area information may include the starting coordinates of an extended face area (a rectangular area) and the length and width of the extended face area. Step 102 in FIG. 1 describes a manner of acquiring the above-mentioned second face area information according to the preset scale factor and the above-mentioned first face area information. For the implementation manner of step 603, reference may be made to the implementation manner of step 102.
604、图像处理装置根据一个或多个扩展人脸区域信息,确定是否满足触发裁剪原始图像的条件。604. The image processing apparatus determines whether a condition for triggering cropping of an original image is met according to one or more pieces of extended face area information.
步骤604可能的实现方式可以是分别判断是否满足触发裁剪原始图像的边界(边缘)的条件。参阅图4,判断是否满足触发裁剪原始图像的上边界的条件可以是:确定一个或多个扩展人脸区域信息指示的一个或多个扩展人脸区域中,是否至少一个扩展人脸区域的上边界超出原始图像的上边界的像素个数大于crop_u_thr;若是,则满足触发裁剪原始图像的上边界的条件。同理,判断是否满足触发裁剪原始图像的下边界的条件可以是:确定一个或多个扩展人脸区域信息指示的一个或多个扩展人脸区域中,是否至少一个扩展人脸区域的下边界超出原始图像的下边界的像素个数大于crop_d_thr;若是,则满足触发裁剪原始图像的下边界的条件。同理,判断是否满足触发裁剪原始图像的左边界的条件可以是:确定一个或多个扩展人脸区域信息指示的一个或多个扩展人脸区域中,是否至少一个扩展人脸区域的左边界超出原始图像的左边界的像素个数大于crop_l_thr;若是,则满足触发裁剪原始图像的左边界的条件。同理,判断是否满足触发裁剪原始图像的右边界的条件可以是:确定一个或多个扩展人脸区域信息指示的一个或多个扩展人脸区域中,是否至少一个扩展人脸区域的右边界超出原始图像的右边界的像素个数大于crop_r_thr;若是,则满足触发裁剪原始图像的右边界的条件。A possible implementation manner of step 604 may be to respectively judge whether the conditions for triggering the cropping of the boundary (edge) of the original image are met. Referring to Fig. 4, judging whether the condition for triggering the upper boundary of cropping the original image can be: determining whether the upper boundary of at least one extended human face area is determined in one or more extended human face areas indicated by one or more extended human face area information. The number of pixels whose boundary exceeds the upper boundary of the original image is greater than crop_u_thr; if so, the condition for triggering the cropping of the upper boundary of the original image is met. In the same way, judging whether the condition for triggering the lower boundary of cropping the original image can be: determining whether the lower boundary of at least one extended human face area in one or more extended human face areas indicated by one or more extended human face area information The number of pixels beyond the lower boundary of the original image is greater than crop_d_thr; if so, the condition for triggering the cropping of the lower boundary of the original image is met. Similarly, judging whether the condition for triggering the left boundary of the cropped original image can be: determining whether the left boundary of at least one extended human face region is indicated by one or more extended human face regions indicated by one or more extended human face region information The number of pixels beyond the left border of the original image is greater than crop_l_thr; if so, the condition for triggering the cropping of the left border of the original image is met. Similarly, judging whether the condition for triggering the cropping of the right boundary of the original image can be: determining whether the right boundary of at least one extended human face region is indicated by one or more extended human face regions indicated by one or more extended human face region information The number of pixels beyond the right boundary of the original image is greater than crop_r_thr; if so, the condition for triggering the cropping of the right boundary of the original image is met.
605、图像处理装置确定一个或多个待裁剪边界对应的裁剪坐标。605. The image processing apparatus determines clipping coordinates corresponding to one or more boundaries to be clipped.
一个或多个待裁剪边界可以是满足触发裁剪原始图像的条件的边界。举例来说,图像处理装置确定满足触发裁剪原始图像的上边界、下边界的条件,则原始图像的上边界、下边界为待裁剪边界。在一些实施例中,图像处理装置在确定满足触发裁剪原始图像的条件之后,可分别确定各待裁剪边界对应的裁剪坐标。图像处理装置确定一个待裁剪边界对应的裁剪坐标可以是:确定该待裁剪边界对应的像素裁剪个数,例如c_u=delta_u-crop_u_thr;将与该待裁剪边界平行且与该待裁剪边界距离该像素裁剪个数的直线上的坐标作为该待裁剪边界对应的裁剪坐标(对应于第一裁剪边界)。应理解,图像处理装置可采用类似的方式 确定任意待裁剪边界对应的裁剪坐标。举例来说,原始图像的一个待裁剪边界为左边界,该待裁剪边界对应的像素裁剪个数为c_l=delta_l-crop_l_thr,将与该待裁剪边界平行且与该待裁剪边界距离c_l(例如10个像素)的直线上的坐标作为该待裁剪边界对应的裁剪坐标。又举例来说,原始图像的一个待裁剪边界为下边界,该待裁剪边界对应的像素裁剪个数为c_d=delta_d-crop_d_thr,将与该待裁剪边界平行且与该待裁剪边界距离c_d(例如10个像素)的直线上的坐标作为该待裁剪边界对应的裁剪坐标。The one or more to-be-cropped boundaries may be boundaries that meet the conditions for triggering the cropping of the original image. For example, if the image processing device determines that the conditions for triggering the cropping of the upper boundary and the lower boundary of the original image are met, then the upper boundary and the lower boundary of the original image are boundaries to be cropped. In some embodiments, after the image processing device determines that the condition for triggering the cropping of the original image is met, the cropping coordinates corresponding to the boundaries to be cropped can be respectively determined. Determining the cropping coordinates corresponding to a boundary to be cropped by the image processing device may be: determining the number of pixel crops corresponding to the boundary to be cropped, for example c_u=delta_u-crop_u_thr; parallel to the boundary to be cropped and distanced from the boundary to be cropped by the pixel The coordinates on the straight line of the number of clippings are used as the clipping coordinates corresponding to the boundary to be clipped (corresponding to the first clipping boundary). It should be understood that the image processing device can determine the clipping coordinates corresponding to any boundary to be clipped in a similar manner. For example, a boundary to be cropped of the original image is the left boundary, and the number of pixels to be cropped corresponding to the boundary to be cropped is c_l=delta_l-crop_l_thr, which will be parallel to the boundary to be cropped and at a distance c_l (for example, 10 pixels) on the straight line as the clipping coordinates corresponding to the border to be cropped. For another example, a boundary to be cropped of the original image is the lower boundary, and the number of pixels to be cropped corresponding to the boundary to be cropped is c_d=delta_d-crop_d_thr, which will be parallel to the boundary to be cropped and at a distance c_d from the boundary to be cropped (for example 10 pixels) on a straight line as the clipping coordinates corresponding to the boundary to be clipped.
606、图像处理装置根据一个或多个待裁剪边界对应的裁剪坐标,裁剪原始图像,得到第一图像。606. The image processing device crops the original image according to the clipping coordinates corresponding to one or more boundaries to be cropped, to obtain the first image.
任意待裁剪边界对应的裁剪坐标可理解为该任意待裁剪边界对应的新边界的坐标。举例来说,原始图像的一个待裁剪边界为左边界,待裁剪边界对应的裁剪坐标即为新的左边界的坐标。在一些实施例中,图像处理装置可按照每个待裁剪边界对应的裁剪坐标,裁剪原始图像。The clipping coordinates corresponding to any boundary to be clipped may be understood as coordinates of a new boundary corresponding to the boundary to be clipped. For example, a boundary to be cropped of the original image is the left boundary, and the cropping coordinates corresponding to the boundary to be cropped are the coordinates of the new left boundary. In some embodiments, the image processing device may crop the original image according to the cropping coordinates corresponding to each boundary to be cropped.
607、图像处理装置将第一图像缩放至与原始图像的尺寸相同。607. The image processing apparatus scales the first image to the same size as the original image.
在一些实施例中,图像处理装置可根据原始图像的宽、高以及宽与高的比例对裁剪后的原始图像(对应于第一图像)进行缩放插值,得到第二图像;上述第二图像的宽、高以及宽与高的比例分别与上述原始图像的宽、高以及宽与高的比例相同。In some embodiments, the image processing device may perform scaling and interpolation on the cropped original image (corresponding to the first image) according to the width, height, and width-to-height ratio of the original image to obtain the second image; The width, height, and ratio of width to height are the same as those of the above original image, respectively.
本申请实施例中,综合考虑了各人脸区域的大小以及各人脸区域的边界与原始图像的各边界之间的距离,可以对图像的边缘进行合理比例的裁剪。In the embodiment of the present application, considering the size of each face area and the distance between the boundaries of each face area and each boundary of the original image, the edge of the image can be cropped in a reasonable proportion.
图7为本申请实施例提供的一种图像畸变矫正处理方法流程图。如图7所示,该方法包括:FIG. 7 is a flowchart of an image distortion correction processing method provided by an embodiment of the present application. As shown in Figure 7, the method includes:
701、图像处理装置获取输入图像。701. The image processing apparatus acquires an input image.
702、对输入图像进行网格点划分,并获取输入图像中的各网格点的原始坐标。702. Divide the input image into grid points, and acquire the original coordinates of each grid point in the input image.
步骤702一种可能的实现方式如下:选取横方向网格点的数目以及竖方向网格点的数目;根据选取的横方向网格点的数目以及竖方向网格点的数目,分别计算横方向相邻网格点之间的像素间隔以及竖方向相邻网格点之间的像素间隔;按照横方向相邻网格点之间的像素间隔以及竖方向相邻网格点之间的像素间隔,对输入图像做网格点划分;获取输入图像中各网格点的原始坐标。A possible implementation of step 702 is as follows: select the number of grid points in the horizontal direction and the number of grid points in the vertical direction; The pixel interval between adjacent grid points and the pixel interval between adjacent grid points in the vertical direction; according to the pixel interval between adjacent grid points in the horizontal direction and the pixel interval between adjacent grid points in the vertical direction , divide the input image into grid points; obtain the original coordinates of each grid point in the input image.
703、对输入图像进行球面投影变换,并采集输入图像经过球面投影后的网格点坐标。703. Perform spherical projection transformation on the input image, and collect grid point coordinates of the input image after spherical projection.
本申请中,网格点坐标是指网格点的坐标。In this application, grid point coordinates refer to coordinates of grid points.
704、对输入图像进行人像分割处理,并获取人像分割处理后的人像区域信息。704. Perform portrait segmentation processing on the input image, and acquire portrait region information after the portrait segmentation processing.
人像区域信息(对应于人像分割结果)指示对输入图像进行人像分割处理得到的人像区域(一个或多个)。The portrait area information (corresponding to the portrait segmentation result) indicates the portrait area (one or more) obtained by subjecting the input image to the portrait segmentation process.
705、对输入图像进行人脸检测,获取人脸区域信息。705. Perform face detection on the input image to acquire face region information.
人脸区域信息(对应于人脸检测结果)指示对输入图像进行人脸检测得到的人脸区域(一个或多个)。The face area information (corresponding to the face detection result) indicates the face area(s) obtained by performing face detection on the input image.
706、对人像区域和人脸区域进行交集处理,获得输入图像中的人像人脸区域。706. Perform intersection processing on the portrait area and the face area to obtain the portrait and face area in the input image.
707、采集原始坐标落在人像人脸区域内的网格点经过球面投影后的坐标信息。707. Collect coordinate information of grid points whose original coordinates fall within the area of the face of the portrait after spherical projection.
708、计算人像人脸区域内的权重因子。708. Calculate weight factors in the face area of the portrait.
图像处理装置可采用任意方式计算人像人脸区域内的权重因子,本申请实施例不作限定。The image processing device may calculate the weighting factor in the portrait and face area in any manner, which is not limited in this embodiment of the present application.
709、计算输入图像的径向权重因子。709. Calculate the radial weight factor of the input image.
对图像进行畸变矫正的同时会对图像中的内容的形状产生一定的副作用。比如人脸在做畸变矫正处理后会发生异常的形变,失去了原有人脸原有的真实形态,对人脸的美感有很大的影响。在图像的中间部分由于原有畸变较轻,所以对图像内容例如人脸的形变有较小的影响。在广角镜头拍摄照片的边缘位置,由于畸变矫正较强,所以图像内容例如人脸有较强的形变影响。因此需要考虑人脸在图像中的位置差异进行人脸形变的矫正。计算人脸形变矫正强度,可采用sigmoid函数分布。位于图像中心区域人脸形变矫正较弱。位于图像边缘位置形变矫正较强。图像处理装置可采用任意方式输入图像的径向权重因子,本申请实施例不作限定。While correcting the distortion of the image, it will have certain side effects on the shape of the content in the image. For example, after the distortion correction process is performed on the human face, abnormal deformation will occur, and the original real shape of the original human face will be lost, which will have a great impact on the beauty of the human face. In the middle part of the image, since the original distortion is relatively light, it has little influence on the deformation of the image content such as the face. At the edge of the photo taken by the wide-angle lens, due to the strong distortion correction, the image content such as the face has a strong deformation effect. Therefore, it is necessary to consider the position difference of the face in the image to correct the face deformation. To calculate the face deformation correction strength, the sigmoid function distribution can be used. The face distortion correction in the center of the image is weak. The deformation correction is stronger at the edge of the image. The image processing device may input the radial weight factor of the image in any manner, which is not limited in this embodiment of the present application.
710、根据人像人脸区域内的权重因子和输入图像的径向权重因子,计算优化网格点的系数矩阵。710. Calculate a coefficient matrix of optimized grid points according to the weight factors in the portrait and face area and the radial weight factors of the input image.
711、求解利用系数矩阵构建的线性方程,得到优化后的网格点的坐标信息。711. Solve the linear equation constructed by using the coefficient matrix to obtain the coordinate information of the optimized grid points.
712、根据优化后的网格点的坐标信息对输入图像中每个像素进行逐点插值计算。712. Perform point-by-point interpolation calculation for each pixel in the input image according to the coordinate information of the optimized grid points.
713、对每个像素逐点插值计算后对所得图像进行裁剪和缩放。713. Crop and scale the obtained image after point-by-point interpolation calculation for each pixel.
图像处理装置可采用本申请提供的图像裁剪方法对对每个像素逐点插值计算后对所得图像进行裁剪和缩放。The image processing device may use the image cropping method provided in this application to crop and scale the image obtained after point-by-point interpolation calculation of each pixel.
本申请实施例中,可以有效矫正畸变的图像,并尽量减少对图像做畸变矫正的同时对图像内容的形状产生的副作用In the embodiment of the present application, the distorted image can be effectively corrected, and the side effects on the shape of the image content can be minimized while correcting the distortion of the image.
图8为本申请实施例提供的一种图像处理装置的结构示意图。如图8所示,图像处理装置包括:FIG. 8 is a schematic structural diagram of an image processing device provided by an embodiment of the present application. As shown in Figure 8, the image processing device includes:
获取单元801,用于第一人脸区域信息;上述第一人脸区域信息表征原始图像中的第一人脸区域,上述原始图像为畸变矫正处理后的图像;The acquisition unit 801 is used for the first face area information; the first face area information represents the first face area in the original image, and the original image is a distortion-corrected image;
获取单元801,还用于基于预设比例系数和第一人脸区域信息,获取第二人脸区域信息;上述第二人脸区域信息表征上述第一人脸区域按照上述预设比例系数调整后的第二人脸区域;The acquisition unit 801 is further configured to acquire second face area information based on the preset scale factor and the first face area information; the second face area information represents that the first face area is adjusted according to the preset scale coefficient The second face area of ;
图像裁剪单元802,用于基于上述第二人脸区域和上述原始图像的边界,裁剪上述原始图像,得到第一图像。An image cropping unit 802, configured to crop the original image based on the boundary between the second face area and the original image to obtain a first image.
在一种可能的实现方式中,图像裁剪单元802,具体用于在上述第二人脸区域的第一边界超出上述原始图像的第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为上述原始图像新的第一边界裁剪上述原始图像,得到上述第一图像;上述第一裁剪边界与上述原始图像的第一边界平行,上述第一裁剪边界与上述原始图像的第一边界之间的像素个数等于上述第二人脸区域的第一边界超出上述原始图像的第一边界的像素个数与上述第一阈值之差。In a possible implementation manner, the image cropping unit 802 is specifically configured to, when the number of pixels beyond the first boundary of the above-mentioned second human face area beyond the first boundary of the above-mentioned original image is greater than the first threshold, the first A cropping boundary is used as the new first boundary of the original image to crop the above-mentioned original image to obtain the above-mentioned first image; the above-mentioned first cropping boundary is parallel to the first boundary of the above-mentioned original image, and the above-mentioned first cropping boundary is parallel to the first boundary of the above-mentioned original image The number of pixels between the boundaries is equal to the difference between the number of pixels where the first boundary of the second human face area exceeds the first boundary of the original image and the first threshold.
在一种可能的实现方式中,图像裁剪单元802,具体用于在上述第一人脸区域的第二边界与上述原始图像的第二边界之间的距离小于第二阈值且上述第二人脸区域位于上述原始图像的情况下,以第二裁剪边界作为上述原始图像新的第二边界裁剪上述原始图像,得 到上述第一图像;上述第二裁剪边界为上述第二人脸区域的第二边界。In a possible implementation manner, the image cropping unit 802 is specifically configured to make the distance between the second boundary of the first human face area and the second boundary of the original image smaller than a second threshold and the second human face In the case that the area is located in the above-mentioned original image, the above-mentioned original image is cropped with the second clipping boundary as the new second boundary of the above-mentioned original image to obtain the above-mentioned first image; the above-mentioned second clipping boundary is the second boundary of the above-mentioned second human face area .
在一种可能的实现方式中,上述第一人脸区域信息包括:上述第一人脸区域的顶点坐标以及上述第一人脸区域的长和宽;获取单元801,具体用于将上述第一人脸区域的长和宽分别与上述预设比例系数的乘积作为上述第二人脸区域的长和宽,以及根据上述第一人脸区域的顶点坐标、长以及宽确定上述第二人脸区域的顶点坐标。In a possible implementation manner, the above-mentioned first face area information includes: the vertex coordinates of the above-mentioned first face area and the length and width of the above-mentioned first face area; The product of the length and width of the human face area and the above-mentioned preset proportional coefficient is used as the length and width of the second human face area, and the above-mentioned second human face area is determined according to the vertex coordinates, length and width of the first human face area vertex coordinates.
在一种可能的实现方式中,上述装置还包括:处理单元803,用于根据上述原始图像的宽、高以及宽与高的比例对上述第一图像进行缩放插值,得到第二图像;上述第二图像的宽、高以及宽与高的比例分别与上述原始图像的宽、高以及宽与高的比例相同。In a possible implementation manner, the above-mentioned apparatus further includes: a processing unit 803, configured to perform scaling and interpolation on the above-mentioned first image according to the width, height, and ratio of width to height of the above-mentioned original image to obtain a second image; The width, height and ratio of width to height of the second image are respectively the same as the width, height and ratio of width to height of the original image.
在一种可能的实现方式中,上述处理单元803,还用于对输入图像做畸变矫正处理,得到上述原始图像。In a possible implementation manner, the above-mentioned processing unit 803 is further configured to perform distortion correction processing on the input image to obtain the above-mentioned original image.
图9是本申请实施例提供的一种服务器的结构示意图,该服务器900可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上CPU922(例如,一个或一个以上处理器)和存储器932,一个或一个以上存储应用程序942或数据944的存储介质930(例如一个或一个以上海量存储设备)。其中,存储器932和存储介质930可以是短暂存储或持久存储。存储在存储介质930的程序可以包括一个或一个以上模块(图示没标出),每个模块可以包括对服务器中的一系列指令操作。更进一步地,中央处理器922可以设置为与存储介质930通信,在服务器900上执行存储介质930中的一系列指令操作。服务器900可以执行本申请提供的图像裁剪方法。FIG. 9 is a schematic structural diagram of a server provided by an embodiment of the present application. The server 900 may have relatively large differences due to different configurations or performances, and may include one or more CPU922 (for example, one or more processors) and Storage 932, one or more storage media 930 (such as one or more mass storage devices) for storing application programs 942 or data 944 . Wherein, the memory 932 and the storage medium 930 may be temporary storage or persistent storage. The program stored in the storage medium 930 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations on the server. Furthermore, the central processing unit 922 may be configured to communicate with the storage medium 930 , and execute a series of instruction operations in the storage medium 930 on the server 900 . The server 900 can execute the image cropping method provided in this application.
服务器900还可以包括一个或一个以上电源926,一个或一个以上有线或无线网络接口950,一个或一个以上输入输出接口958,和/或,一个或一个以上操作系统941,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The server 900 can also include one or more power supplies 926, one or more wired or wireless network interfaces 950, one or more input and output interfaces 958, and/or, one or more operating systems 941, such as Windows Server™, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
上述实施例中由图像处理装置所执行的步骤可以基于该图9所示的服务器结构。例如,中央处理器922可实现图8中的获取单元801、图像裁剪单元802、处理单元803的功能。The steps performed by the image processing apparatus in the above embodiments may be based on the server structure shown in FIG. 9 . For example, the central processing unit 922 can realize the functions of the acquiring unit 801, the image cropping unit 802, and the processing unit 803 in FIG. 8 .
图10为本申请实施例提供的一种终端设备的结构示意图。如图10所示,该终端设备100包括处理器1001、存储器1002、通信接口1003以及输入输出设备1004;该处理器1001、存储器1002和通信接口1003通过总线相互连接。图10中的终端设备可以为前述实施例中的图像处理装置。FIG. 10 is a schematic structural diagram of a terminal device provided in an embodiment of the present application. As shown in FIG. 10, the terminal device 100 includes a processor 1001, a memory 1002, a communication interface 1003, and an input and output device 1004; the processor 1001, the memory 1002, and the communication interface 1003 are connected to each other through a bus. The terminal device in FIG. 10 may be the image processing apparatus in the foregoing embodiments.
存储器1002包括但不限于是随机存储记忆体(random access memory,RAM)、只读存储器(read-only memory,ROM)、可擦除可编程只读存储器(erasable programmableread only memory,EPROM)、或便携式只读存储器(compact disc read-only memory,CDROM),该存储器1002用于相关指令及数据。通信接口1003用于接收和发送数据。输入输出设备1004可包括键盘、鼠标、触摸屏等输入设备,以及显示器、屏幕等输出设备。用户可通过输入设备输入待处理图像。Memory 1002 includes, but is not limited to, random access memory (random access memory, RAM), read-only memory (read-only memory, ROM), erasable programmable read-only memory (erasable programmable read only memory, EPROM), or portable Read-only memory (compact disc read-only memory, CDROM), the memory 1002 is used for related instructions and data. The communication interface 1003 is used to receive and send data. The input and output devices 1004 may include input devices such as keyboards, mice, and touch screens, and output devices such as monitors and screens. The user can input the image to be processed through the input device.
处理器1001可以是一个或多个中央处理器(central processing unit,CPU),在处理器1001是一个CPU的情况下,该CPU可以是单核CPU,也可以是多核CPU。上述实施例中由图像处理装置所执行的步骤可以基于该图10所示的终端设备的结构。具体的,处理器1001可实现图8中的获取单元801、图像裁剪单元802、处理单元803的功能。The processor 1001 may be one or more central processing units (central processing unit, CPU). In the case where the processor 1001 is a CPU, the CPU may be a single-core CPU or a multi-core CPU. The steps performed by the image processing apparatus in the foregoing embodiments may be based on the structure of the terminal device shown in FIG. 10 . Specifically, the processor 1001 may implement the functions of the acquiring unit 801, the image cropping unit 802, and the processing unit 803 in FIG. 8 .
在本申请的实施例中提供一种计算机可读存储介质,上述计算机可读存储介质存储有 计算机程序,上述计算机程序被处理器执行时实现前述实施例所提供的图像裁剪方法。In an embodiment of the present application, a computer-readable storage medium is provided, the above-mentioned computer-readable storage medium stores a computer program, and when the above-mentioned computer program is executed by a processor, the image cropping method provided in the above-mentioned embodiment is implemented.
本申请实施例提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行前述实施例所提供的图像裁剪方法。An embodiment of the present application provides a computer program product containing instructions, which when run on a computer, causes the computer to execute the image cropping method provided in the foregoing embodiments.
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改或替换,这些修改或替换都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以权利要求的保护范围为准。The above is only a specific embodiment of the application, but the scope of protection of the application is not limited thereto. Any person familiar with the technical field can easily think of various equivalents within the scope of the technology disclosed in the application. Modifications or replacements, these modifications or replacements shall be covered within the scope of protection of this application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims (12)

  1. 一种图像裁剪方法,其特征在于,所述方法包括:An image cropping method, characterized in that the method comprises:
    获取第一人脸区域信息;所述第一人脸区域信息表征原始图像中的第一人脸区域;Obtaining the first face area information; the first face area information characterizes the first face area in the original image;
    基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息;所述第二人脸区域信息表征所述第一人脸区域按照所述预设比例系数调整后的第二人脸区域;Based on the preset proportional coefficient and the first human face region information, the second human face region information is obtained; the second human face region information represents the first human face region adjusted according to the preset proportional coefficient. Two face area;
    基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像。Based on the boundary between the second face area and the original image, crop the original image to obtain a first image.
  2. 根据权利要求1所述的方法,其特征在于,所述基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像包括:The method according to claim 1, wherein the cutting the original image based on the boundary of the second human face area and the original image to obtain the first image comprises:
    在所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为所述原始图像新的第一边界裁剪所述原始图像,得到所述第一图像;所述第一裁剪边界与所述原始图像的第一边界平行,所述第一裁剪边界与所述原始图像的第一边界之间的像素个数等于所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数与所述第一阈值之差。When the number of pixels of the first boundary of the second human face area beyond the first boundary of the original image is greater than the first threshold, the first cropping boundary is used as the new first boundary of the original image to crop the first boundary. The original image is obtained to obtain the first image; the first cropping boundary is parallel to the first boundary of the original image, and the number of pixels between the first cropping boundary and the first boundary of the original image is equal to A difference between the number of pixels that the first boundary of the second face area exceeds the first boundary of the original image and the first threshold.
  3. 根据权利要求1所述的方法,其特征在于,所述基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像包括:The method according to claim 1, wherein the cutting the original image based on the boundary of the second human face area and the original image to obtain the first image comprises:
    在所述第一人脸区域的第二边界与所述原始图像的第二边界之间的距离小于第二阈值且所述第二人脸区域位于所述原始图像的情况下,以第二裁剪边界作为所述原始图像新的第二边界裁剪所述原始图像,得到所述第一图像;所述第二裁剪边界为所述第二人脸区域的第二边界。When the distance between the second boundary of the first human face area and the second boundary of the original image is less than a second threshold and the second human face area is located in the original image, the second cropping The boundary is used as a new second boundary of the original image to crop the original image to obtain the first image; the second cropping boundary is a second boundary of the second face area.
  4. 根据权利要求1至3任一项所述的方法,其特征在于,所述第一人脸区域信息包括:所述第一人脸区域的顶点坐标以及所述第一人脸区域的长和宽;所述基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息包括:The method according to any one of claims 1 to 3, wherein the first face area information includes: the vertex coordinates of the first face area and the length and width of the first face area ; The acquisition of the second face area information based on the preset scale coefficient and the first face area information includes:
    将所述第一人脸区域的长和宽分别与所述预设比例系数的乘积作为所述第二人脸区域的长和宽,以及根据所述第一人脸区域的顶点坐标、长以及宽确定所述第二人脸区域的顶点坐标。Taking the product of the length and width of the first human face area and the preset proportional coefficient as the length and width of the second human face area, and according to the vertex coordinates, length and Width determines the vertex coordinates of the second face area.
  5. 根据权利要求1至4任一项所述的方法,其特征在于,在基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图像,得到第一图像之后,所述方法还包括:The method according to any one of claims 1 to 4, characterized in that, after cutting the original image based on the boundary of the second human face area and the original image to obtain the first image, the method Also includes:
    根据所述原始图像的宽、高以及宽与高的比例对所述第一图像进行缩放插值,得到第二图像;所述第二图像的宽、高以及宽与高的比例分别与所述原始图像的宽、高以及宽与高的比例相同。Scale and interpolate the first image according to the width, height and ratio of width to height of the original image to obtain a second image; the width, height and ratio of width to height of the second image are respectively the same as the original The image has the same width, height, and width-to-height ratio.
  6. 一种图像处理装置,其特征在于,包括:An image processing device, characterized in that it comprises:
    获取单元,用于第一人脸区域信息;所述第一人脸区域信息表征原始图像中的第一人脸区域;The acquisition unit is used for the first face area information; the first face area information represents the first face area in the original image;
    所述获取单元,还用于基于预设比例系数和所述第一人脸区域信息,获取第二人脸区域信息;所述第二人脸区域信息表征所述第一人脸区域按照所述预设比例系数调整后的第二人脸区域;The acquisition unit is further configured to acquire second face area information based on a preset scale factor and the first face area information; the second face area information represents the first face area according to the The second face area adjusted by the preset scale factor;
    图像裁剪单元,用于基于所述第二人脸区域和所述原始图像的边界,裁剪所述原始图 像,得到第一图像。An image cropping unit, configured to crop the original image based on the boundary of the second human face area and the original image to obtain a first image.
  7. 根据权利要求6所述的装置,其特征在于,The device according to claim 6, characterized in that,
    所述图像裁剪单元,具体用于在所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数大于第一阈值的情况下,以第一裁剪边界作为所述原始图像新的第一边界裁剪所述原始图像,得到所述第一图像;所述第一裁剪边界与所述原始图像的第一边界平行,所述第一裁剪边界与所述原始图像的第一边界之间的像素个数等于所述第二人脸区域的第一边界超出所述原始图像的第一边界的像素个数与所述第一阈值之差。The image cropping unit is specifically configured to use the first cropping boundary as the first boundary when the number of pixels beyond the first boundary of the original image is greater than a first threshold. The new first boundary of the original image crops the original image to obtain the first image; the first cropping boundary is parallel to the first boundary of the original image, and the first cropping boundary is parallel to the first boundary of the original image The number of pixels between a boundary is equal to the difference between the number of pixels where the first boundary of the second face area exceeds the first boundary of the original image and the first threshold.
  8. 根据权利要求6所述的装置,其特征在于,The device according to claim 6, characterized in that,
    所述图像裁剪单元,具体用于在所述第一人脸区域的第二边界与所述原始图像的第二边界之间的距离小于第二阈值且所述第二人脸区域位于所述原始图像的情况下,以第二裁剪边界作为所述原始图像新的第二边界裁剪所述原始图像,得到所述第一图像;所述第二裁剪边界为所述第二人脸区域的第二边界。The image cropping unit is specifically configured to: when the distance between the second boundary of the first human face area and the second boundary of the original image is less than a second threshold and the second human face area is located in the original In the case of an image, use the second cropping boundary as the new second boundary of the original image to crop the original image to obtain the first image; the second cropping boundary is the second edge of the second human face area. boundary.
  9. 根据权利要求6至8任一项所述的装置,其特征在于,所述第一人脸区域信息包括:所述第一人脸区域的顶点坐标以及所述第一人脸区域的长和宽;The device according to any one of claims 6 to 8, wherein the information of the first human face area includes: the coordinates of vertices of the first human face area and the length and width of the first human face area ;
    所述获取单元,具体用于将所述第一人脸区域的长和宽分别与所述预设比例系数的乘积作为所述第二人脸区域的长和宽,以及根据所述第一人脸区域的顶点坐标、长以及宽确定所述第二人脸区域的顶点坐标。The obtaining unit is specifically configured to use the product of the length and width of the first human face area and the preset proportional coefficient as the length and width of the second human face area, and according to the first human face area The vertex coordinates, length and width of the face area determine the vertex coordinates of the second human face area.
  10. 根据权利要求6至9任一项所述的装置,其特征在于,所述装置还包括:The device according to any one of claims 6 to 9, wherein the device further comprises:
    缩放插值单元,用于根据所述原始图像的宽、高以及宽与高的比例对所述第一图像进行缩放插值,得到第二图像;所述第二图像的宽、高以及宽与高的比例分别与所述原始图像的宽、高以及宽与高的比例相同。A zoom interpolation unit, configured to perform zoom interpolation on the first image according to the width, height, and ratio of width to height of the original image to obtain a second image; the width, height, and ratio of width to height of the second image The ratios are the same as the width, height and width-to-height ratio of the original image, respectively.
  11. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有计算机程序,所述计算机程序包括程序指令,所述程序指令当被处理器执行时,使所述处理器执行权利要求1至5任意一项所述的方法。A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes The method according to any one of claims 1 to 5.
  12. 一种电子设备,其特征在于,包括存储器和处理器,其中,所述存储器用于存储指令,所述处理器用于执行所述存储器存储的指令,使得所述处理器执行权利要求1至5任意一项所述的方法。An electronic device, characterized by comprising a memory and a processor, wherein the memory is used to store instructions, and the processor is used to execute the instructions stored in the memory, so that the processor performs any of claims 1 to 5. one of the methods described.
PCT/CN2021/119420 2021-08-04 2021-09-18 Image cropping method and related product WO2023010661A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110890240.3A CN113628229B (en) 2021-08-04 2021-08-04 Image cropping method and related product
CN202110890240.3 2021-08-04

Publications (1)

Publication Number Publication Date
WO2023010661A1 true WO2023010661A1 (en) 2023-02-09

Family

ID=78382663

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/119420 WO2023010661A1 (en) 2021-08-04 2021-09-18 Image cropping method and related product

Country Status (2)

Country Link
CN (1) CN113628229B (en)
WO (1) WO2023010661A1 (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115334237B (en) * 2022-07-26 2024-01-23 广州紫为云科技有限公司 Portrait focusing method, device and medium based on USB camera
CN116703701B (en) * 2022-12-15 2024-05-17 荣耀终端有限公司 Picture clipping method and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060072847A1 (en) * 2004-10-01 2006-04-06 Microsoft Corporation System for automatic image cropping based on image saliency
CN103959802A (en) * 2012-08-10 2014-07-30 松下电器产业株式会社 Video provision method, transmission device, and reception device
CN110276308A (en) * 2019-06-25 2019-09-24 上海商汤智能科技有限公司 Image processing method and device
CN110400266A (en) * 2019-06-13 2019-11-01 北京小米移动软件有限公司 A kind of method and device of image flame detection, storage medium
CN110537200A (en) * 2017-04-20 2019-12-03 夏普株式会社 Image processing apparatus, filming apparatus, image printer, the control method of image processing apparatus and image processing program
CN111626166A (en) * 2020-05-19 2020-09-04 Oppo广东移动通信有限公司 Image processing method, image processing device, electronic equipment and storage medium
CN112219393A (en) * 2018-06-07 2021-01-12 麦克赛尔株式会社 Portable information terminal

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016101767A1 (en) * 2014-12-24 2016-06-30 北京奇虎科技有限公司 Picture cropping method and device and image detecting method and device
CN110298858B (en) * 2019-07-01 2021-06-22 北京奇艺世纪科技有限公司 Image clipping method and device
CN112529784B (en) * 2019-09-18 2024-05-28 华为技术有限公司 Image distortion correction method and device
CN110766729B (en) * 2019-10-16 2023-05-16 Oppo广东移动通信有限公司 Image processing method, device, storage medium and electronic equipment
CN112598580B (en) * 2020-12-29 2023-07-25 广州光锥元信息科技有限公司 Method and device for improving definition of portrait photo

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060072847A1 (en) * 2004-10-01 2006-04-06 Microsoft Corporation System for automatic image cropping based on image saliency
CN103959802A (en) * 2012-08-10 2014-07-30 松下电器产业株式会社 Video provision method, transmission device, and reception device
CN110537200A (en) * 2017-04-20 2019-12-03 夏普株式会社 Image processing apparatus, filming apparatus, image printer, the control method of image processing apparatus and image processing program
CN112219393A (en) * 2018-06-07 2021-01-12 麦克赛尔株式会社 Portable information terminal
CN110400266A (en) * 2019-06-13 2019-11-01 北京小米移动软件有限公司 A kind of method and device of image flame detection, storage medium
CN110276308A (en) * 2019-06-25 2019-09-24 上海商汤智能科技有限公司 Image processing method and device
CN111626166A (en) * 2020-05-19 2020-09-04 Oppo广东移动通信有限公司 Image processing method, image processing device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN113628229B (en) 2022-12-09
CN113628229A (en) 2021-11-09

Similar Documents

Publication Publication Date Title
CN110660066B (en) Training method of network, image processing method, network, terminal equipment and medium
WO2023010661A1 (en) Image cropping method and related product
TWI441514B (en) Fisheye correction with perspective distortion reduction method and related image processor
CN108040210B (en) Local distortion correction method, mobile terminal and related medium product
JP5906028B2 (en) Image processing apparatus and image processing method
CN110276308B (en) Image processing method and device
JP3684017B2 (en) Image processing apparatus and method
KR20190129947A (en) Methods and apparatus for determining facial image quality, electronic devices and computer storage media
US20110211233A1 (en) Image processing device, image processing method and computer program
WO2017054442A1 (en) Image information recognition processing method and device, and computer storage medium
JP7192582B2 (en) Object tracking device and object tracking method
US20160358341A1 (en) Fast Template-Based Tracking
CN111105367B (en) Face distortion correction method and device, electronic equipment and storage medium
CN113409372A (en) Image registration method, related device, equipment and storage medium
CN114037992A (en) Instrument reading identification method and device, electronic equipment and storage medium
CN107153806B (en) Face detection method and device
EP4068151B1 (en) Linear processing method and apparatus in face image, terminal device, and storage medium
CN112927163A (en) Image data enhancement method and device, electronic equipment and storage medium
US11647294B2 (en) Panoramic video data process
CN112532875B (en) Terminal device, image processing method and device thereof, and storage medium
CN113628095B (en) Portrait area grid point information storage method and related product
CN115761827A (en) Cosmetic progress detection method, device, equipment and storage medium
CN113222862A (en) Image distortion correction method, device, electronic equipment and storage medium
CN111784733A (en) Image processing method, device, terminal and computer readable storage medium
CN112101134A (en) Object detection method and device, electronic device and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21952530

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE