Picture cropping method, device and equipment and computer readable storage medium

CN115482151BActive Publication Date: 2026-08-21BEIJING SANKUAI ONLINE TECH CO LTD
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211036933.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-08-25
Publication Date
2026-08-21
Estimated Expiration
2042-08-25

AI Technical Summary

Technical Problem

[0003]然而,在对待裁剪图片进行裁剪的过程中,当待裁剪图片发生旋转时,裁剪框的四个顶点中有至少一个顶点位于旋转后的待裁剪图片之外,进而使得根据裁剪框裁剪到的图片中包含了除待裁剪图片之外的空白区域,使得图片裁剪的效果较差

Benefits of technology

[0068]本申请实施例提供的技术方案在对目标图片进行裁剪时,当目标图片发生旋转,且裁剪框的多个顶点中存在位于旋转后的目标图片之外的顶点时,通过对旋转后的目标图片的尺寸进行调整,以得到调整后的目标图片,使得裁剪框的多个顶点均位于调整后的目标图片上,在不改变裁剪框的前提下,使得裁剪到的图片中不包含除目标图片之外的空白区域,使得图片裁剪效果较好。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115482151B_ABST
    Figure CN115482151B_ABST
Patent Text Reader

Abstract

The application discloses a picture cropping method and device, equipment and a computer readable storage medium, and belongs to the technical field of picture processing. The method comprises the following steps: displaying a target picture to be cropped and a cropping frame; in response to the target picture being rotated based on a rotation operation, and there being a vertex of the cropping frame located outside the target picture after rotation, adjusting the size of the target picture after rotation to obtain an adjusted target picture, so that each vertex of the cropping frame is located on the adjusted target picture; determining a cropping area on the adjusted target picture according to the cropping frame, and obtaining a cropped picture according to the cropping area. The cropped picture obtained by the method does not include a blank area other than the target picture, so that the picture cropping effect is better.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and in particular to an image cropping method, apparatus, device, and computer-readable storage medium. Background Technology

[0002] With the rapid development of image processing technology, there are more and more types of image processing software, and their functions are becoming increasingly rich. Image cropping is one such function. When cropping images, image processing software usually uses a cropping frame, and the size and position of the cropping frame are adjusted to crop the image to be cropped.

[0003] However, during the cropping process, when the image to be cropped is rotated, at least one of the four vertices of the cropping frame is located outside the rotated image to be cropped. This results in the cropped image containing blank areas other than the image to be cropped, leading to poor image cropping results. Summary of the Invention

[0004] This application provides an image cropping method, apparatus, device, and computer-readable storage medium, which can be used to solve problems in related technologies. The technical solution is as follows:

[0005] On one hand, embodiments of this application provide an image cropping method, the method comprising:

[0006] Displays the target image to be cropped and the cropping box;

[0007] In response to the target image being rotated based on a rotation operation, and the presence of vertices outside the rotated target image among the vertices of the cropping frame, the size of the rotated target image is adjusted to obtain an adjusted target image, such that all vertices of the cropping frame are located on the adjusted target image.

[0008] Based on the cropping frame, a cropping area is determined on the adjusted target image, and a cropped image is obtained based on the cropping area.

[0009] In one possible implementation, adjusting the size of the rotated target image to obtain the adjusted target image includes:

[0010] Based on the coordinates of each vertex of the cropping frame, the circumscribed region of the cropping frame is determined, the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping frame is located on the edge of the circumscribed region;

[0011] Determine the length and width of the outer region;

[0012] The size of the rotated target image is adjusted according to the length and width of the outer region to obtain the adjusted target image.

[0013] In one possible implementation, determining the length and width of the circumscribed region includes:

[0014] The length and width of the cropping frame are determined based on the coordinates of each vertex of the cropping frame.

[0015] The length and width of the outer region are determined based on the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image.

[0016] In one possible implementation, determining the length and width of the enclosing region based on the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image includes:

[0017] The first value is determined according to the law of cosines based on the length of the cropping frame and the rotation angle of the target image.

[0018] The second value is determined according to the law of sine based on the width of the cropping frame and the rotation angle of the target image.

[0019] The sum of the first value and the second value is used as the length of the outer region;

[0020] The third value is determined according to the law of sine based on the length of the cropping frame and the rotation angle of the target image.

[0021] The fourth value is determined according to the law of cosines based on the width of the cropping frame and the rotation angle of the target image.

[0022] The sum of the third and fourth values ​​is used as the width of the outer region.

[0023] In one possible implementation, adjusting the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image includes:

[0024] Since the length of the rotated target image is less than the length of the outer region and the width of the rotated target image is less than the width of the outer region, the length of the rotated target image is adjusted to the length of the outer region, and the width of the rotated target image is adjusted to the width of the outer region.

[0025] Candidate regions are determined based on the coordinates of each vertex of the cropping frame, the rotation angle of the target image, and the adjusted length and width of the rotated target image.

[0026] Based on the coordinates of each vertex of the candidate region, the coordinates of each vertex of the rotated target image are adjusted to obtain the adjusted target image, the size of the adjusted target image being larger than the size of the rotated target image.

[0027] In one possible implementation, adjusting the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image includes:

[0028] Based on the premise that the length of the rotated target image is not less than the length of the outer region, and / or that the width of the rotated target image is not less than the width of the outer region, at least one target vertex located outside the rotated target image is determined among the vertices of the cropping frame.

[0029] Determine the target projection points corresponding to each of the at least one target vertex;

[0030] Based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, a first distance and a second distance are determined, wherein the first distance is the distance in the first dimension and the second distance is the distance in the second dimension;

[0031] Based on the first distance and the second distance, the coordinates of each vertex of the rotated target image are adjusted to obtain an adjusted target image, the size of which is larger than the size of the rotated target image.

[0032] In one possible implementation, determining the target projection points corresponding to the at least one target vertex includes:

[0033] For any target vertex among the at least one target vertex, project the target vertex onto each side of the rotated target image to obtain multiple projection points corresponding to the target vertex.

[0034] Determine the distances between each of the multiple projection points corresponding to any target vertex and the target vertex;

[0035] The projection point whose distance meets the distance requirement is taken as the target projection point corresponding to any target vertex.

[0036] In one possible implementation, determining the first distance and the second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex includes:

[0037] Since there is only one target vertex, the first distance is determined based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the first dimension, and the second distance is determined based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the second dimension.

[0038] Since there are multiple target vertices, a reference vertex is determined among the multiple target vertices based on the distance between each target vertex and the target projection point corresponding to each target vertex. The first distance is determined based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the first dimension. The second distance is determined based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the second dimension.

[0039] In one possible implementation, adjusting the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain the adjusted target image includes:

[0040] Based on the first distance, the values ​​of the first dimension of the coordinates of each vertex of the rotated target image are adjusted, and based on the second distance, the values ​​of the second dimension of the coordinates of each vertex of the rotated target image are adjusted to obtain the candidate coordinates of each vertex of the rotated target image.

[0041] Based on the candidate coordinates of each vertex of the rotated target image, the rotated target image is stretched to obtain the adjusted target image, where the coordinates of each vertex of the adjusted target image are the candidate coordinates of each vertex of the rotated target image.

[0042] In one possible implementation, determining the cropping region on the adjusted target image based on the cropping frame includes:

[0043] The area overlapping between the cropping frame and the adjusted target image is defined as the cropping region.

[0044] In one possible implementation, determining the cropping region on the adjusted target image based on the cropping frame includes:

[0045] Based on the coordinates of each vertex of the cropping frame and the coordinates of each vertex of the adjusted target image, determine multiple extension intersection points between each side of the cropping frame and the adjusted target image.

[0046] Based on the coordinates of the multiple extended intersection points, the first value range of the clipping box in the first dimension and the second value range in the second dimension are determined;

[0047] The clipping frame is stretched to obtain a stretched clipping frame. The size of the stretched clipping frame is larger than the size of the clipping frame before stretching. The values ​​of each vertex of the stretched clipping frame in the first dimension are within a first value range, and the values ​​of each vertex of the stretched clipping frame in the second dimension are within a second value range.

[0048] The area overlapping between the stretched cropping frame and the adjusted target image is defined as the cropping area.

[0049] On the other hand, embodiments of this application provide an image cropping device, the device comprising:

[0050] The display module is used to display the target image to be cropped and the cropping frame;

[0051] An adjustment module is used to adjust the size of the rotated target image in response to the target image being rotated based on a rotation operation, and the fact that there are vertices of the cropping frame located outside the rotated target image, so as to obtain an adjusted target image, such that all vertices of the cropping frame are located on the adjusted target image.

[0052] The determining module is used to determine the cropping area on the adjusted target image based on the cropping frame;

[0053] The cropping module is used to obtain a cropped image based on the cropping area.

[0054] In one possible implementation, the adjustment module is configured to determine the circumscribed region of the cropping frame based on the coordinates of each vertex of the cropping frame, wherein the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping frame is located on the edge of the circumscribed region; determine the length and width of the circumscribed region; and adjust the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image.

[0055] In one possible implementation, the adjustment module is used to determine the length and width of the cropping frame based on the coordinates of each vertex of the cropping frame; and to determine the length and width of the circumscribed region based on the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image.

[0056] In one possible implementation, the adjustment module is configured to: determine a first value according to the law of cosines based on the length of the cropping frame and the rotation angle of the target image; determine a second value according to the law of sines based on the width of the cropping frame and the rotation angle of the target image; use the sum of the first and second values ​​as the length of the circumscribed region; determine a third value according to the law of sines based on the length of the cropping frame and the rotation angle of the target image; determine a fourth value according to the law of cosines based on the width of the cropping frame and the rotation angle of the target image; and use the sum of the third and fourth values ​​as the width of the circumscribed region.

[0057] In one possible implementation, the adjustment module is configured to adjust the length of the rotated target image to the length of the outer region and the width of the rotated target image to the width of the outer region, based on the fact that the length of the rotated target image is less than the length of the outer region and the width of the rotated target image is less than the width of the outer region; determine candidate regions based on the coordinates of each vertex of the cropping frame, the rotation angle of the target image, and the adjusted length and width of the rotated target image; and adjust the coordinates of each vertex of the rotated target image based on the coordinates of each vertex of the candidate regions to obtain the adjusted target image, wherein the size of the adjusted target image is greater than the size of the rotated target image.

[0058] In one possible implementation, the adjustment module is configured to: determine at least one target vertex located outside the rotated target image among the vertices of the cropping frame, based on the fact that the length of the rotated target image is not less than the length of the outer region, and / or that the width of the rotated target image is not less than the width of the outer region; determine target projection points corresponding to the at least one target vertex; determine a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, wherein the first distance is a distance in a first dimension and the second distance is a distance in a second dimension; and adjust the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain an adjusted target image, wherein the size of the adjusted target image is larger than the size of the rotated target image.

[0059] In one possible implementation, the adjustment module is configured to, for any one of the at least one target vertices, project the any one target vertex onto each side of the rotated target image to obtain multiple projection points corresponding to the any one target vertex; determine the distances between the multiple projection points corresponding to the any one target vertex and the any one target vertex; and use the projection points whose distances meet the distance requirements as the target projection points corresponding to the any one target vertex.

[0060] In one possible implementation, the adjustment module is configured to: determine a first distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the first dimension, and determine a second distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the second dimension, provided that there are only one target vertex; and determine a reference vertex among the multiple target vertices based on the distance between each target vertex and its corresponding target projection point, determine the first distance based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the first dimension, and determine the second distance based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the second dimension.

[0061] In one possible implementation, the adjustment module is configured to adjust the values ​​of the first dimension of the coordinates of each vertex of the rotated target image according to the first distance, and adjust the values ​​of the second dimension of the coordinates of each vertex of the rotated target image according to the second distance to obtain candidate coordinates of each vertex of the rotated target image; and stretch the rotated target image according to the candidate coordinates of each vertex of the rotated target image to obtain the adjusted target image, wherein the coordinates of each vertex of the adjusted target image are the candidate coordinates of each vertex of the rotated target image.

[0062] In one possible implementation, the determining module is used to define the overlapping area between the cropping frame and the adjusted target image as the cropping area.

[0063] In one possible implementation, the determining module is configured to: determine multiple extension intersection points of each edge of the cropping frame and the adjusted target image based on the coordinates of each vertex of the cropping frame and the coordinates of each vertex of the adjusted target image; determine a first value range in a first dimension and a second value range in a second dimension of the cropping frame based on the coordinates of the multiple extension intersection points; stretch the cropping frame to obtain a stretched cropping frame, wherein the size of the stretched cropping frame is larger than the size of the original cropping frame, and the values ​​of each vertex of the stretched cropping frame in the first dimension are within the first value range, and the values ​​of each vertex of the stretched cropping frame in the second dimension are within the second value range; and define the overlapping area between the stretched cropping frame and the adjusted target image as the cropping region.

[0064] On the other hand, embodiments of this application provide a computer device, which includes a processor and a memory. The memory stores at least one piece of program code, which is loaded and executed by the processor to enable the computer device to implement any of the image cropping methods described above.

[0065] On the other hand, a computer-readable storage medium is also provided, wherein at least one piece of program code is stored in the computer-readable storage medium, the at least one piece of program code being loaded and executed by a processor to enable a computer to implement any of the image cropping methods described above.

[0066] On the other hand, a computer program or computer program product is also provided, wherein the computer program or computer program product stores at least one computer instruction, which is loaded and executed by a processor to enable the computer to implement any of the above-mentioned image cropping methods.

[0067] The technical solution provided in this application has at least the following beneficial effects:

[0068] The technical solution provided in this application provides that when cropping a target image, if the target image is rotated and there are vertices outside the rotated target image among the multiple vertices of the cropping frame, the size of the rotated target image is adjusted to obtain an adjusted target image, so that the multiple vertices of the cropping frame are all located on the adjusted target image. Without changing the cropping frame, the cropped image does not contain any blank areas other than the target image, resulting in a better image cropping effect. Attached Figure Description

[0069] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0070] Figure 1 This is a schematic diagram of the implementation environment of an image cropping method provided in an embodiment of this application;

[0071] Figure 2 This is a flowchart of an image cropping method provided in an embodiment of this application;

[0072] Figure 3 This is a schematic diagram showing a target image and a cropping frame according to an embodiment of this application;

[0073] Figure 4 This is a schematic diagram of an external area provided in an embodiment of this application;

[0074] Figure 5 This is a schematic diagram illustrating the determination of the coordinates of the center point of a clipping frame according to an embodiment of this application;

[0075] Figure 6 This is a schematic diagram of the rotation of a reference area provided in an embodiment of this application;

[0076] Figure 7 This is a schematic diagram showing an adjusted target image provided in an embodiment of this application;

[0077] Figure 8 This is a diagram illustrating the process of determining the target projection point corresponding to any target vertex, as provided in an embodiment of this application.

[0078] Figure 9 This is a schematic diagram of stretching a rotated target image to obtain an adjusted target image, according to an embodiment of this application.

[0079] Figure 10 This is a schematic diagram of a cropped image provided in an embodiment of this application;

[0080] Figure 11 This is a schematic diagram illustrating how to determine the intersection points of each side of a cropping frame with multiple extensions of the adjusted target image, as provided in an embodiment of this application.

[0081] Figure 12 This is a schematic diagram showing another cropped image provided in an embodiment of this application;

[0082] Figure 13 This is a schematic diagram of the structure of an image cropping device provided in an embodiment of this application;

[0083] Figure 14 This is a schematic diagram of the structure of a terminal device provided in an embodiment of this application. Detailed Implementation

[0084] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0085] It should be noted that the terms "first," "second," etc., used in this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0086] Figure 1 This is a schematic diagram illustrating the implementation environment of an image cropping method provided in an embodiment of this application, such as... Figure 1 As shown, the implementation environment includes: terminal device 101.

[0087] Optionally, the terminal device 101 can be any electronic product capable of human-computer interaction with a user through one or more methods such as a keyboard, touchpad, touchscreen, remote control, voice interaction, or handwriting device. The terminal device 101 includes, but is not limited to, mobile phones, computers, intelligent voice interaction devices, smart home appliances, vehicle terminals, and aircraft. The terminal device 101 is used to execute the image cropping method provided in the embodiments of this application.

[0088] Those skilled in the art should understand that the terminal device 101 described above is merely an example. Other existing or future terminal devices that are applicable to this application should also be included within the scope of protection of this application, and are hereby incorporated by reference.

[0089] This application provides an image cropping method, which is executed by a terminal device 101 and can be applied to the above-mentioned methods. Figure 1 The implementation environment is shown. Figure 2 The flowchart of an image cropping method provided in this application embodiment is shown as an example. Figure 2 As shown, the method includes the following steps 201 to 204.

[0090] In step 201, the target image to be cropped and the cropping frame are displayed.

[0091] In the exemplary embodiments of this application, an application for image cropping is installed and runs on the terminal device. This application can be any type of application; it can refer to an application that needs to be downloaded and installed, or it can refer to an embedded application that depends on a host application to run, such as a mini-program. This embodiment of the application does not limit the type of application. An embedded application is an application developed based on a programming language and that depends on a host application to run. Embedded applications do not require downloading and installation; they only need to be dynamically loaded into the host application to run. Users can find the embedded applications they need through search, scanning, or other methods, open them, and apply them. After use, closing the application does not occupy the terminal's memory, which is very convenient.

[0092] In one possible implementation, in response to an operation instruction on the application, the application's homepage is displayed; the homepage is the first page when the application is opened. Optionally, the homepage displays an image selection control for selecting a target image. In response to an operation instruction on the image selection control, multiple candidate images stored in the terminal device are displayed. In response to an operation instruction on any candidate image, that candidate image is selected as the target image. The homepage also displays an image display area for displaying the target image. The operation instruction can be a single click, a double click, or other operations; this embodiment does not limit the specific actions involved.

[0093] Optionally, the homepage also displays an image cropping control used to crop the target image. In response to an operation command on the image cropping control, a cropping box is displayed on the target image, with no vertices of the cropping box located outside the target image. In one possible implementation, all vertices of the cropping box are located on the target image. This includes: all vertices of the cropping box being located inside the target image; or, all vertices of the cropping box being located on the edges of the target image; or, some vertices of the cropping box being inside the target image and some vertices being located on the edges of the target image.

[0094] Optionally, the homepage also displays an image capture control. In response to operation commands to the image capture control, the camera device of the terminal device is invoked to capture images, and the captured images are used as the target images. For example, the camera device can be the terminal device's webcam.

[0095] like Figure 3 This is a schematic diagram showing a target image and a cropping frame according to an embodiment of this application. Figure 3 In the image selection control, 301 is the target image, 303 is the image capture control, and 304 is the cropping box. Figure 3As can be seen, all four vertices of the cropping box are located inside the target image.

[0096] In step 202, in response to the target image being rotated based on a rotation operation, and the presence of vertices in the cropping box that are outside the rotated target image, the size of the rotated target image is adjusted to obtain an adjusted target image, such that all vertices of the cropping box are located on the adjusted target image.

[0097] In one possible implementation, the angle of the target image can be adjusted during the cropping process, i.e., the target image can be rotated. Optionally, a rotation control (such as...) can also be displayed on the homepage. Figure 3 (305 in the code) The rotation control is used to rotate the target image. In response to the operation command for the rotation control, a rotation operation is received for the target image, causing the target image to rotate and obtaining the rotated target image.

[0098] Optionally, in response to the target image being rotated based on a rotation operation, it is determined whether there are any vertices in the cropping box located outside the rotated target image, based on the coordinates of each vertex of the cropping box and the coordinates of each vertex of the rotated target image. If there are vertices in the cropping box located outside the rotated target image, the size of the rotated target image is adjusted to obtain an adjusted target image, where all vertices of the cropping box are located on the adjusted target image. The size of the adjusted target image is larger than the size of the rotated target image.

[0099] Optionally, the application includes a coordinate determination function. When a target image and a cropping box are displayed, the coordinates of each vertex of the target image and the cropping box can be determined by calling this function. When the target image is rotated, the coordinates of each vertex of the rotated target image can also be determined. In one possible implementation, when the target image is rotated, the coordinates of each vertex of the rotated target image can also be determined based on the coordinates of each vertex of the target image and the rotation angle of the target image.

[0100] The coordinates of each vertex of the target image after rotation are determined according to the coordinates of each vertex of the target image and the rotation angle of the target image, according to the following formulas (1) and (2).

[0101] x′=x*cosθ-y*sinθ formula (1)

[0102] y′=x*sinθ+y*cosθ formula (2)

[0103] In the above formulas (1) and (2), (x, y) are the coordinates of any vertex of the target image, θ is the rotation angle of the target image, and (x′, y′) are the coordinates of any vertex of the rotated target image.

[0104] In one possible implementation, determining whether there are any vertices in the cropping box located outside the rotated target image, based on the coordinates of each vertex of the cropping box and the coordinates of each vertex of the rotated target image, includes: determining multiple vectors based on the coordinates of each vertex of the rotated target image; these multiple vectors can form a closed region, which is the region where the rotated target image is located; the number of vectors is the same as the number of vertices in the rotated target image; and then determining whether there are any vertices in the cropping box located outside the rotated target image based on the multiple vectors and the coordinates of each vertex of the cropping box.

[0105] In one possible implementation, the process of determining whether there are any vertices outside the rotated target image among the vertices of the cropping box, based on multiple vectors and the coordinates of each vertex of the cropping box, includes: for any vertex among the multiple vertices of the cropping box, performing a cross product between the coordinates of the vertex and each vector to obtain the cross product result between the vertex and each vector, the cross product result being used to represent the positional relationship between the vertex and the vector; and determining whether the vertex is outside the rotated target image based on the cross product result between the vertex and each vector.

[0106] For example, if the cross product between any vertex and a vector is less than 0, it means that the vertex is to the left of the vector; if the cross product between any vertex and a vector is greater than 0, it means that the vertex is to the right of the vector; and if the cross product between any vertex and a vector is equal to 0, it means that the vertex is on the vector.

[0107] In one possible implementation, the process of determining whether a vertex is outside the rotated target image based on the cross product between any vertex and each vector includes: determining whether a vertex is outside the region composed of multiple vectors based on the cross product between any vertex and each vector; if any vertex is outside the region composed of multiple vectors, then the vertex is determined to be outside the rotated target image; if any vertex is not outside the region composed of multiple vectors, then the vertex is determined not to be outside the rotated target image.

[0108] It should be noted that the process of determining whether each vertex of the cropping box is outside the rotated target image is similar, and will not be repeated here.

[0109] In one possible implementation, the process of adjusting the size of the rotated target image based on the existence of vertices outside the rotated target image among the vertices of the cropping box includes: determining the circumscribed region of the cropping box according to the coordinates of each vertex of the cropping box, wherein the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping box is located on the edge of the circumscribed region; determining the length and width of the circumscribed region; and adjusting the size of the rotated target image according to the length and width of the circumscribed region to obtain the adjusted target image.

[0110] Optionally, the process of determining the length and width of the bounding region includes: determining the length and width of the cropping box based on the coordinates of each vertex of the cropping box; and determining the length and width of the bounding region based on the length and width of the cropping box and the rotation angle of the target image.

[0111] In one possible implementation, a first value is determined using the law of cosines based on the length of the cropping box and the rotation angle of the target image; a second value is determined using the law of sines based on the width of the cropping box and the rotation angle of the target image; the sum of the first and second values ​​is used as the length of the bounding region; a third value is determined using the law of sines based on the length of the cropping box and the rotation angle of the target image; a fourth value is determined using the law of cosines based on the width of the cropping box and the rotation angle of the target image; and the sum of the third and fourth values ​​is used as the width of the bounding region. Figure 4 This is a schematic diagram of an external area provided in an embodiment of this application.

[0112] For example, the length of the outer region is determined according to the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image, according to the following formula (3), and the width of the outer region is determined according to the following formula (4).

[0113] M = m * cosθ + n * sinθ (Formula 3)

[0114] N = n*cosθ + m*sinθ (Formula 4)

[0115] In formulas (3) and (4) above, M is the length of the circumscribed region, N is the width of the circumscribed region, m is the length of the cropping box, n is the width of the cropping box, and θ is the rotation angle of the target image. m*cosθ is the first value, n*sinθ is the second value, n*cosθ is the third value, and m*sinθ is the fourth value.

[0116] For example, if the length of the cropping frame is 5 and the width is 3, and the rotation angle of the target image is 30 degrees, then the length of the circumscribed region is determined according to the above formulas (3) and (4). The width of the outer region is

[0117] In one possible implementation, after determining the length and width of the circumscribed region, the size of the rotated target image is adjusted according to the length and width of the circumscribed region. The process of obtaining the adjusted target image includes the following two cases.

[0118] Scenario 1: If the length of the rotated target image is less than the length of the bounding region, and the width of the rotated target image is less than the width of the bounding region, adjust the length and width of the rotated target image to match the length and width of the bounding region. Based on the coordinates of each vertex of the cropping box, the rotation angle of the target image, and the adjusted length and width of the rotated target image, determine the candidate region. Based on the coordinates of each vertex of the candidate region, adjust the coordinates of each vertex of the rotated target image to obtain the adjusted target image. The size of the adjusted target image is larger than the size of the rotated target image.

[0119] Optionally, the process of determining the candidate region based on the coordinates of each vertex of the cropping frame, the rotation angle of the target image, and the adjusted length and width of the rotated target image includes: determining the coordinates of the center point of the cropping frame based on the coordinates of each vertex of the cropping frame; determining the reference region based on the coordinates of the center point of the cropping frame and the adjusted length and width of the rotated target image; and rotating the reference region based on the rotation angle of the target image to obtain the candidate region.

[0120] Wherein, the length of the rotated target image is the length of the bounding region, and the width of the rotated target image is the width of the bounding region. For example, the length of the rotated target image is 5 cm, the width is 3 cm, and the length of the bounding region is... cm, the width of the outer region is If the value is in centimeters, then the length of the rotated target image needs to be adjusted to [value missing]. centimeters, width adjusted to centimeter.

[0121] This application does not limit the process of determining the coordinates of the center point of the clipping frame based on the coordinates of each vertex of the clipping frame. For example, the coordinates of two opposite vertices of the clipping frame are determined, and a first difference in the coordinates of these two opposite vertices in a first dimension and a second difference in the coordinates of these two vertices in a second dimension are determined. The coordinates of the center point of the clipping frame are then determined based on the first difference and the second difference.

[0122] For example, such as Figure 5 This is a schematic diagram illustrating the determination of the coordinates of the center point of a clipping frame according to an embodiment of this application. Figure 5In the diagram, the dashed box represents the clipping box, with the coordinates of its four vertices being A(x, y), B(x+m, y), C(x, y+n), and D(x+m, y+n). A and D are vertical angles, as are B and C. The first difference between the coordinates of A and D in the first dimension is determined to be m, and the second difference in the second dimension to be n. Therefore, the coordinates of the center point of the clipping box are determined to be (x+m / 2, y+n / 2).

[0123] In one possible implementation, the process of determining the reference region based on the coordinates of the center point of the cropping frame and the adjusted length and width of the rotated target image includes: taking the center point of the cropping frame as the center point of the reference region, determining the reference region, the length of the reference region being the adjusted length of the rotated target image, and the width of the reference region being the adjusted width of the rotated target image.

[0124] The process of rotating a reference region to obtain candidate regions based on the rotation angle of the target image includes: keeping the center point of the reference region stationary, rotating the reference region according to the rotation angle of the target image to obtain candidate regions. Figure 6 This is a schematic diagram of the rotation of a reference area provided in an embodiment of this application. Figure 6 In the diagram, (1) is the reference region and (2) is the candidate region.

[0125] In one possible implementation, after determining the candidate region, the coordinates of each vertex of the rotated target image are adjusted according to the coordinates of each vertex of the candidate region to obtain the adjusted target image. The process includes: adjusting the coordinates of each vertex of the rotated target image to the coordinates of each vertex of the candidate region to obtain the adjusted target image. Figure 7 This is a schematic diagram showing an adjusted target image provided in an embodiment of this application.

[0126] Scenario 2: Based on the condition that the length of the rotated target image is not less than the length of the bounding region, and / or the width of the rotated target image is not less than the width of the bounding region, determine at least one target vertex located outside the rotated target image among the vertices of the cropping box; determine the target projection points corresponding to the at least one target vertex; determine a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, where the first distance is the distance in the first dimension and the second distance is the distance in the second dimension; adjust the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain an adjusted target image, the size of which is larger than the size of the rotated target image.

[0127] The process of determining the target projection points corresponding to at least one target vertex includes: for any target vertex among the at least one target vertex, projecting the target vertex onto each edge of the rotated target image to obtain multiple projection points corresponding to the target vertex; determining the distances between the multiple projection points corresponding to the target vertex and the target vertex, and taking the projection point whose distance meets the distance requirement as the target projection point corresponding to the target vertex. Optionally, the projection point whose distance meets the distance requirement refers to the projection point with the smallest distance.

[0128] Optionally, the distances between multiple projection points corresponding to any target vertex and any target vertex can be determined according to the following formula (5).

[0129]

[0130] In the above formula (5), L is the distance between any projection point corresponding to any target vertex and any target vertex. (x1, y1) are the coordinates of any target vertex, and (x2, y2) are the coordinates of any projection point corresponding to any target vertex.

[0131] For example, Figure 8 This is a diagram illustrating the process of determining the target projection point corresponding to any target vertex, as provided in an embodiment of this application. Figure 8 As can be seen, there are two target vertices, namely target vertex N and target vertex P. Projecting target vertex N onto the edges of the rotated target image yields multiple projection points corresponding to target vertex N, namely projection point 1, projection point 2, projection point 3, and projection point 4. The distances between projection point 1, projection point 2, projection point 3, and projection point 4 are determined, resulting in the distances between each projection point and target vertex N. Since projection point 3 has the smallest distance to target vertex N, it is selected as the target projection point corresponding to target vertex N.

[0132] It should be noted that the target projection point corresponding to the target vertex is located on the edge of the rotated target image. The process of determining the target projection points corresponding to other target vertices is similar to that of determining the target projection point corresponding to target vertex N, and will not be repeated here.

[0133] In one possible implementation, after determining the target projection points corresponding to at least one target vertex, the process of determining a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex includes: assuming there is only one target vertex, determining the first distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the first dimension; and determining the second distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the second dimension. Optionally, the absolute value of the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the first dimension is used as the first distance, and the absolute value of the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the second dimension is used as the second distance.

[0134] For example, if there is one target vertex, the coordinates of the target vertex are (3, 5), and the coordinates of the target projection point corresponding to the target vertex are (4, 7), then the absolute value of the difference between 3 and 4 is taken as the first distance, and the absolute value of the difference between 5 and 7 is taken as the second distance, that is, the first distance is 1 and the second distance is 2.

[0135] Since there are multiple target vertices, a reference vertex is determined among the multiple target vertices based on the distance between each target vertex and its corresponding target projection point. A first distance is determined based on the difference between the coordinates of the reference vertex and the coordinates of its corresponding target projection point in the first dimension. A second distance is determined based on the difference between the coordinates of the reference vertex and the coordinates of its corresponding target projection point in the second dimension. Optionally, the absolute value of the difference between the coordinates of the reference vertex and the coordinates of its corresponding target projection point in the first dimension is used as the first distance, and the absolute value of the difference between the coordinates of the reference vertex and the coordinates of its corresponding target projection point in the second dimension is used as the second distance.

[0136] In one possible implementation, the process of determining a reference vertex among multiple target vertices based on the distance between each target vertex and its corresponding target projection point includes: taking the target vertex with the largest distance to its corresponding target projection point among the multiple target vertices as the reference vertex.

[0137] For example, there are two target vertices, namely target vertex N and target vertex P. The target projection point corresponding to target vertex N is projection point 1, and the target projection point corresponding to target vertex P is projection point 3. In response to the situation where the distance between target vertex N and projection point 1 is greater than the distance between target vertex P and projection point 3, target vertex N is used as a reference vertex. The absolute value of the difference between the coordinates of target vertex N and projection point 1 in the first dimension is used as the first distance, and the absolute value of the difference between the coordinates of target vertex N and projection point 1 in the second dimension is used as the second distance.

[0138] In one possible implementation, the process of adjusting the coordinates of each vertex of the rotated target image according to a first distance and a second distance to obtain an adjusted target image includes: adjusting the value of the first dimension of the coordinates of each vertex of the rotated target image according to the first distance; adjusting the value of the second dimension of the coordinates of each vertex of the rotated target image according to the second distance to obtain candidate coordinates of each vertex of the rotated target image; stretching the rotated target image according to the candidate coordinates of each vertex of the rotated target image to obtain an adjusted target image, wherein the coordinates of each vertex of the adjusted target image are the candidate coordinates of each vertex of the rotated target image.

[0139] like Figure 9 This is a schematic diagram illustrating how a rotated target image is stretched to obtain an adjusted target image, according to an embodiment of this application. Figure 9 In the image, (1) is the rotated target image, and (2) is the adjusted target image. Figure 9 It can be seen that the size of the adjusted target image is larger than the size of the rotated target image.

[0140] In step 203, the cropping area is determined on the adjusted target image based on the cropping frame, and the cropped image is obtained based on the cropping area.

[0141] In one possible implementation, the process of determining the cropping region on the adjusted target image based on the cropping frame and obtaining the cropped image based on the cropping region includes: taking the area overlapping between the cropping frame and the adjusted target image as the cropping region, cropping the cropping region, and obtaining the cropped image.

[0142] Optionally, a confirmation control (such as...) is also displayed on the homepage. Figure 3 Control 306 in the image contains a confirmation control used to indicate confirmation of cropping the target image. In response to receiving an operation instruction for the confirmation control, the cropping area is determined on the adjusted target image according to the cropping box, resulting in a cropped image. The cropped image is a portion of the adjusted target image and does not include blank areas other than the target image.

[0143] like Figure 10 This is a schematic diagram illustrating a cropped image provided in an embodiment of this application. Figure 10 (1) is for determining the cutting area. Figure 10 (2) is the cropped image obtained.

[0144] In one possible implementation, the cropping box can be stretched to increase the size of the cropped image. Optionally, based on the coordinates of each vertex of the cropping box and the coordinates of each vertex of the adjusted target image, multiple extension intersection points of each edge of the cropping box and the adjusted target image are determined; based on the coordinates of the multiple extension intersection points, the value range of the cropping box in a first dimension and the value range in a second dimension are determined; the cropping box is stretched to obtain a stretched cropping box, the size of which is larger than that of the original cropping box, and the values ​​of each vertex of the stretched cropping box in the first dimension are within a first value range, and the values ​​of each vertex of the stretched cropping box in the second dimension are within a second value range; the overlapping area between the stretched cropping box and the adjusted target image is taken as the cropping region; the cropping region is cropped to obtain the cropped image.

[0145] In one possible implementation, the process of determining the multiple extended intersection points of each side of the cropping box and the adjusted target image based on the coordinates of each vertex of the cropping box and the coordinates of each vertex of the adjusted target image includes: determining the equations corresponding to each side of the cropping box based on the coordinates of each vertex of the cropping box, resulting in four first equations; determining the equations corresponding to each of the four sides of the adjusted target image based on the coordinates of each vertex of the adjusted target image, resulting in four second equations; and determining the multiple extended intersection points of each side of the cropping box and the adjusted target image based on the four first equations and the four second equations.

[0146] Optionally, the intersection points of each side of the cropping frame with the multiple extensions of the adjusted target image can be determined according to the following formula (6).

[0147] Solving for:

[0148] In the above formula (6), ax+by=e is the equation corresponding to any side of the cropping box (or, ax+by=e is the equation corresponding to any side of the adjusted target image), cx+dy=f is the equation corresponding to any side of the adjusted target image (or, cx+dy=f is the equation corresponding to any side of the cropping box), and (x, y) is the extended intersection point.

[0149] like Figure 11 This is a schematic diagram illustrating how to determine the intersection points of each side of a cropping frame with multiple extensions of the adjusted target image, as provided in an embodiment of this application. Figure 11We know that the multiple extended intersection points are extension intersection point a, extension intersection point b, extension intersection point c, extension intersection point d, extension intersection point e, extension intersection point f, extension intersection point g, and extension intersection point h. Based on the coordinates of each extension intersection point, the maximum value of the clipping box in the first dimension is determined to be x4, and the minimum value is x5. Therefore, the first value range of the clipping box in the first dimension is [x5, x4]. The maximum value of the clipping box in the second dimension is determined to be y6, and the minimum value is y3. Therefore, the second value range of the clipping box in the second dimension is [y3, y6].

[0150] In response to receiving a stretching operation for the cropping box, determine whether the coordinates of each vertex of the stretched cropping box are within a first value range and a second value range. If the coordinates of each vertex of the stretched cropping box are within the first value range and the second value range, then take the overlapping area between the stretched cropping box and the adjusted target image as the cropping area, and crop the cropping area to obtain the cropped image.

[0151] like Figure 12 This is a schematic diagram showing another cropped image provided in an embodiment of this application. Figure 12 (1) is for determining the cutting area. Figure 12 (2) is the resulting cropped image. (From...) Figure 12 and Figure 10 It can be seen that, Figure 12 The size of the cropped image is larger than Figure 10 The resulting cropped image size.

[0152] If any of the vertices of the stretched cropping box contains coordinates outside the first value range, and / or if any of the vertices of the stretched cropping box contains coordinates outside the second value range, then the size of the cropping box is limited to ensure that the cropping box does not exceed the adjusted target image. The limitation is achieved by ensuring that the cropping box remains unchanged during the stretching operation. Optionally, the limitation can also be achieved by displaying a notification message indicating that further stretching of the cropping box is not possible. The notification message may include any content, and this embodiment does not limit its scope.

[0153] In one possible implementation, after obtaining the cropped image, it can be saved in the terminal device's storage space, and it can also be displayed in the image display area on the homepage so that users can see the cropped image.

[0154] When cropping a target image, if the target image is rotated and some vertices of the cropping frame are located outside the rotated target image, the size of the rotated target image is adjusted to obtain an adjusted target image. This ensures that all vertices of the cropping frame are located on the adjusted target image. Without changing the cropping frame, the cropped image does not contain any blank areas other than the target image, resulting in a better image cropping effect.

[0155] Furthermore, when cropping on the adjusted target image, the size of the cropping frame can be adjusted to make the cropped image larger, without including blank areas, thus further improving the image cropping effect.

[0156] Figure 13 The diagram shown is a structural schematic of an image cropping device provided in an embodiment of this application. Figure 13 As shown, the device includes:

[0157] Display module 1301 is used to display the target image to be cropped and the cropping frame;

[0158] The adjustment module 1302 is used to adjust the size of the rotated target image in response to the target image being rotated based on the rotation operation, and the fact that there are vertices in each of the cropping boxes located outside the rotated target image, so that each vertex of the cropping box is located on the adjusted target image.

[0159] The determination module 1303 is used to determine the cropping area on the adjusted target image based on the cropping frame;

[0160] The cropping module 1304 is used to obtain the cropped image based on the cropping area.

[0161] In one possible implementation, the adjustment module 1302 is used to determine the circumscribed region of the cropping frame based on the coordinates of each vertex of the cropping frame, wherein the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping frame is located on the edge of the circumscribed region; determine the length and width of the circumscribed region; and adjust the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image.

[0162] In one possible implementation, the adjustment module 1302 is used to determine the length and width of the cropping box based on the coordinates of each vertex of the cropping box; and to determine the length and width of the circumscribed region based on the length and width of the cropping box and the rotation angle of the target image.

[0163] In one possible implementation, the adjustment module 1302 is used to determine a first value according to the law of cosines based on the length of the cropping frame and the rotation angle of the target image; determine a second value according to the law of sines based on the width of the cropping frame and the rotation angle of the target image; use the sum of the first and second values ​​as the length of the bounding region; determine a third value according to the law of sines based on the length of the cropping frame and the rotation angle of the target image; determine a fourth value according to the law of cosines based on the width of the cropping frame and the rotation angle of the target image; and use the sum of the third and fourth values ​​as the width of the bounding region.

[0164] In one possible implementation, the adjustment module 1302 is used to adjust the length of the rotated target image to the length of the outer region and the width of the rotated target image to the width of the outer region, based on the fact that the length of the rotated target image is less than the length of the outer region and the width of the rotated target image is less than the width of the outer region; determine candidate regions based on the coordinates of each vertex of the cropping box, the rotation angle of the target image, and the adjusted length and width of the rotated target image; and adjust the coordinates of each vertex of the rotated target image based on the coordinates of each vertex of the candidate regions to obtain an adjusted target image, the size of which is larger than the size of the rotated target image.

[0165] In one possible implementation, the adjustment module 1302 is used to determine at least one target vertex located outside the rotated target image among the vertices of the cropping box, based on the fact that the length of the rotated target image is not less than the length of the outer region, and / or that the width of the rotated target image is not less than the width of the outer region; determine the target projection points corresponding to the at least one target vertex; determine a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, wherein the first distance is a distance in a first dimension and the second distance is a distance in a second dimension; and adjust the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain an adjusted target image, wherein the size of the adjusted target image is larger than the size of the rotated target image.

[0166] In one possible implementation, the adjustment module 1302 is used to project any target vertex onto the edges of the rotated target image for any target vertex among at least one target vertex, to obtain multiple projection points corresponding to any target vertex; determine the distances between the multiple projection points corresponding to any target vertex and any target vertex; and take the projection points whose distances meet the distance requirements as the target projection points corresponding to any target vertex.

[0167] In one possible implementation, the adjustment module 1302 is used to determine a first distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the first dimension when there is only one target vertex, and to determine a second distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the second dimension; and to determine a reference vertex among the multiple target vertices based on the distance between each target vertex and the target projection point corresponding to each target vertex, based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the first dimension, and to determine a second distance based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the second dimension.

[0168] In one possible implementation, the adjustment module 1302 is used to adjust the values ​​of the first dimension of the coordinates of each vertex of the rotated target image according to the first distance, and adjust the values ​​of the second dimension of the coordinates of each vertex of the rotated target image according to the second distance to obtain candidate coordinates of each vertex of the rotated target image; and stretch the rotated target image according to the candidate coordinates of each vertex of the rotated target image to obtain the adjusted target image, wherein the coordinates of each vertex of the adjusted target image are the candidate coordinates of each vertex of the rotated target image.

[0169] In one possible implementation, the determining module 1303 is used to define the overlapping area between the cropping frame and the adjusted target image as the cropping area.

[0170] In one possible implementation, the determining module 1303 is used to determine multiple extension intersection points of each edge of the cropping box and the adjusted target image based on the coordinates of each vertex of the cropping box and the coordinates of each vertex of the adjusted target image; determine a first value range of the cropping box in the first dimension and a second value range in the second dimension based on the coordinates of the multiple extension intersection points; stretch the cropping box to obtain a stretched cropping box, the size of the stretched cropping box is larger than the size of the original cropping box, the values ​​of each vertex of the stretched cropping box in the first dimension are within the first value range, and the values ​​of each vertex of the stretched cropping box in the second dimension are within the second value range; and use the overlapping area between the stretched cropping box and the adjusted target image as the cropping area.

[0171] When the aforementioned device crops a target image, if the target image is rotated and there are vertices of the cropping frame located outside the rotated target image, the size of the rotated target image is adjusted to obtain an adjusted target image. This ensures that all vertices of the cropping frame are located on the adjusted target image. Without changing the cropping frame, the cropped image does not contain any blank areas other than the target image, resulting in a better image cropping effect.

[0172] It should be understood that the above-described apparatus is only illustrated by the division of the functional modules described above when implementing its functions. In practical applications, the functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0173] Figure 14 A structural block diagram of a terminal device 1400 provided in an exemplary embodiment of this application is shown. The terminal device 1400 may be a portable mobile terminal, such as a smartphone, tablet computer, MP3 player (Moving Picture Experts Group Audio Layer III), MP4 player (Moving Picture Experts Group Audio Layer IV), laptop computer, or desktop computer. The terminal device 1400 may also be referred to as a user device, portable terminal, laptop terminal, desktop terminal, or other names.

[0174] Typically, terminal device 1400 includes a processor 1401 and a memory 1402.

[0175] Processor 1401 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1401 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1401 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1401 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 1401 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0176] The memory 1402 may include one or more computer-readable storage media, which may be non-transitory. The memory 1402 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1402 are used to store at least one instruction, which is executed by the processor 1401 to implement the image cropping method provided in the method embodiments of this application.

[0177] In some embodiments, the terminal device 1400 may also optionally include: a peripheral device interface 1403 and at least one peripheral device. The processor 1401, memory 1402, and peripheral device interface 1403 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1403 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of: a radio frequency circuit 1404, a display screen 1405, a camera assembly 1406, an audio circuit 1407, a positioning assembly 1408, and a power supply 1409.

[0178] Peripheral device interface 1403 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 1401 and memory 1402. In some embodiments, processor 1401, memory 1402 and peripheral device interface 1403 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1401, memory 1402 and peripheral device interface 1403 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.

[0179] The radio frequency (RF) circuit 1404 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1404 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1404 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 1404 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 1404 can communicate with other terminal devices through at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: the World Wide Web, metropolitan area networks, intranets, various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks, and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1404 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.

[0180] Display screen 1405 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1405 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1401 for processing. In this case, display screen 1405 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, there may be one display screen 1405, disposed on the front panel of terminal device 1400; in other embodiments, there may be at least two display screens, disposed on different surfaces of terminal device 1400 or in a folded design; in still other embodiments, display screen 1405 may be a flexible display screen, disposed on a curved or folded surface of terminal device 1400. Furthermore, display screen 1405 may also be configured as a non-rectangular, irregular shape, i.e., a non-rectangular screen. The display screen 1405 can be made of materials such as LCD (Liquid Crystal Display) and OLED (Organic Light-Emitting Diode).

[0181] The camera assembly 1406 is used to acquire images or videos. Optionally, the camera assembly 1406 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal device 1400, and the rear-facing camera is located on the back of the terminal device 1400. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1406 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm light flash and a cool light flash, which can be used for light compensation at different color temperatures.

[0182] The audio circuit 1407 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting the sound waves into electrical signals that are input to the processor 1401 for processing, or input to the radio frequency circuit 1404 to achieve voice communication. For stereo sound acquisition or noise reduction purposes, there may be multiple microphones, each located at a different part of the terminal device 1400. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 1401 or the radio frequency circuit 1404 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 1407 may also include a headphone jack.

[0183] The positioning component 1408 is used to locate the current geographical location of the terminal device 1400 in order to enable navigation or LBS (Location Based Service). The positioning component 1408 can be a positioning component based on the US GPS (Global Positioning System), China's BeiDou system, Russia's Granas system, or the European Union's Galileo system.

[0184] Power supply 1409 is used to power the various components in terminal device 1400. Power supply 1409 can be AC ​​power, DC power, a disposable battery, or a rechargeable battery. When power supply 1409 includes a rechargeable battery, the rechargeable battery can be a wired rechargeable battery or a wireless rechargeable battery. A wired rechargeable battery is a battery that is charged via a wired line, and a wireless rechargeable battery is a battery that is charged via a wireless coil. The rechargeable battery can also be used to support fast charging technology.

[0185] In some embodiments, the terminal device 1400 further includes one or more sensors 1410. The one or more sensors 1410 include, but are not limited to: an accelerometer 1411, a gyroscope 1412, a pressure sensor 1413, a fingerprint sensor 1414, an optical sensor 1415, and a proximity sensor 1416.

[0186] Accelerometer 1411 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established by terminal device 1400. For example, accelerometer 1411 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 1401 can control display screen 1405 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 1411. Accelerometer 1411 can also be used for games or for acquiring user motion data.

[0187] The gyroscope sensor 1412 can detect the orientation and rotation angle of the terminal device 1400. The gyroscope sensor 1412 can work in conjunction with the accelerometer sensor 1411 to collect 3D motion data from the user on the terminal device 1400. Based on the data collected by the gyroscope sensor 1412, the processor 1401 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.

[0188] The pressure sensor 1413 can be disposed on the side bezel of the terminal device 1400 and / or on the lower layer of the display screen 1405. When the pressure sensor 1413 is disposed on the side bezel of the terminal device 1400, it can detect the user's grip signal on the terminal device 1400, and the processor 1401 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 1413. When the pressure sensor 1413 is disposed on the lower layer of the display screen 1405, the processor 1401 can control the operable controls on the UI interface based on the user's pressure operation on the display screen 1405. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.

[0189] The fingerprint sensor 1414 is used to collect a user's fingerprint. The processor 1401 identifies the user based on the fingerprint collected by the fingerprint sensor 1414, or vice versa. When the user's identity is identified as trusted, the processor 1401 authorizes the user to perform relevant sensitive operations, including unlocking the screen, viewing encrypted information, downloading software, making payments, and changing settings. The fingerprint sensor 1414 can be located on the front, back, or side of the terminal device 1400. When the terminal device 1400 has a physical button or manufacturer logo, the fingerprint sensor 1414 can be integrated with the physical button or manufacturer logo.

[0190] An optical sensor 1415 is used to collect ambient light intensity. In one embodiment, the processor 1401 can control the display brightness of the display screen 1405 based on the ambient light intensity collected by the optical sensor 1415. Specifically, when the ambient light intensity is high, the display brightness of the display screen 1405 is increased; when the ambient light intensity is low, the display brightness of the display screen 1405 is decreased. In another embodiment, the processor 1401 can also dynamically adjust the shooting parameters of the camera assembly 1406 based on the ambient light intensity collected by the optical sensor 1415.

[0191] The proximity sensor 1416, also known as a distance sensor, is typically located on the front panel of the terminal device 1400. The proximity sensor 1416 is used to detect the distance between the user and the front of the terminal device 1400. In one embodiment, when the proximity sensor 1416 detects that the distance between the user and the front of the terminal device 1400 is gradually decreasing, the processor 1401 controls the display screen 1405 to switch from a screen-on state to a screen-off state; when the proximity sensor 1416 detects that the distance between the user and the front of the terminal device 1400 is gradually increasing, the processor 1401 controls the display screen 1405 to switch from a screen-off state to a screen-on state.

[0192] Those skilled in the art will understand that Figure 14 The structure shown does not constitute a limitation on the terminal device 1400, and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0193] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores at least one piece of program code that is loaded and executed by a processor to enable a computer to implement any of the above-described image cropping methods.

[0194] Optionally, the aforementioned computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.

[0195] In an exemplary embodiment, a computer program or computer program product is also provided, which stores at least one computer instruction, which is loaded and executed by a processor to enable the computer to implement any of the above-described image cropping methods.

[0196] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the target images involved in this application were all obtained with full authorization.

[0197] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0198] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0199] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. A method for cropping images, characterized in that, The method includes: displaying a target image to be cropped and a cropping frame; in response to the target image being rotated based on a rotation operation, and the presence of vertices in the cropping frame located outside the rotated target image, adjusting the size of the rotated target image to obtain an adjusted target image, such that all vertices of the cropping frame are located on the adjusted target image; determining a cropping region on the adjusted target image based on the cropping frame, and obtaining a cropped image based on the cropping region; the step of adjusting the size of the rotated target image to obtain the adjusted target image includes: determining the circumscribed region of the cropping frame based on the coordinates of each vertex of the cropping frame, wherein the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping frame is located on the edge of the circumscribed region; determining the length and width of the circumscribed region; and adjusting the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image. The step of adjusting the size of the rotated target image based on the length and width of the outer region to obtain an adjusted target image includes: determining at least one target vertex located outside the rotated target image among the vertices of the cropping frame, based on the condition that the length of the rotated target image is not less than the length of the outer region and / or the width of the rotated target image is not less than the width of the outer region; determining the target projection points corresponding to the at least one target vertex; determining a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, wherein the first distance is a distance in a first dimension and the second distance is a distance in a second dimension; and adjusting the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain an adjusted target image, wherein the size of the adjusted target image is larger than the size of the rotated target image. The step of determining the target projection points corresponding to the at least one target vertex includes: for any target vertex among the at least one target vertex, projecting the any target vertex onto each side of the rotated target image to obtain multiple projection points corresponding to the any target vertex; determining the distances between the multiple projection points corresponding to the any target vertex and the any target vertex; and taking the projection points whose distances meet the distance requirements as the target projection points corresponding to the any target vertex.The step of determining a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex includes: determining the first distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the first dimension, and determining the second distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection points corresponding to the target vertex in the second dimension.

2. The method according to claim 1, characterized in that, Determining the length and width of the outer region includes: determining the length and width of the cropping frame based on the coordinates of each vertex of the cropping frame; and determining the length and width of the outer region based on the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image.

3. The method according to claim 2, characterized in that, Determining the length and width of the enclosing region based on the length of the cropping frame, the width of the cropping frame, and the rotation angle of the target image includes: determining a first value according to the law of cosines based on the length of the cropping frame and the rotation angle of the target image; determining a second value according to the law of sines based on the width of the cropping frame and the rotation angle of the target image; using the sum of the first and second values ​​as the length of the enclosing region; determining a third value according to the law of sines based on the length of the cropping frame and the rotation angle of the target image; determining a fourth value according to the law of cosines based on the width of the cropping frame and the rotation angle of the target image; and using the sum of the third and fourth values ​​as the width of the enclosing region.

4. The method according to claim 1, characterized in that, The step of adjusting the size of the rotated target image based on the length and width of the outer region to obtain the adjusted target image further includes: adjusting the length of the rotated target image to the length of the outer region and adjusting the width of the rotated target image to the width of the outer region, since the length of the rotated target image is less than the length of the outer region and the width of the rotated target image is less than the width of the outer region; determining candidate regions based on the coordinates of each vertex of the cropping frame, the rotation angle of the target image, and the adjusted length and width of the rotated target image; and adjusting the coordinates of each vertex of the rotated target image based on the coordinates of each vertex of the candidate regions to obtain the adjusted target image, wherein the size of the adjusted target image is greater than the size of the rotated target image.

5. The method according to claim 1, characterized in that, The step of determining the first distance and the second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex further includes: based on the fact that there are multiple target vertices, determining a reference vertex among the multiple target vertices according to the distance between each target vertex and the target projection point corresponding to each target vertex; determining the first distance based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the first dimension; and determining the second distance based on the difference between the coordinates of the reference vertex and the coordinates of the target projection point corresponding to the reference vertex in the second dimension.

6. The method according to claim 1, characterized in that, The step of adjusting the coordinates of each vertex of the rotated target image according to the first distance and the second distance to obtain the adjusted target image includes: adjusting the value of the first dimension of the coordinates of each vertex of the rotated target image according to the first distance, and adjusting the value of the second dimension of the coordinates of each vertex of the rotated target image according to the second distance to obtain candidate coordinates of each vertex of the rotated target image; stretching the rotated target image according to the candidate coordinates of each vertex of the rotated target image to obtain the adjusted target image, wherein the coordinates of each vertex of the adjusted target image are the candidate coordinates of each vertex of the rotated target image.

7. The method according to any one of claims 1 to 6, characterized in that, Determining the cropping region on the adjusted target image based on the cropping frame includes: taking the area overlapping between the cropping frame and the adjusted target image as the cropping region.

8. The method according to any one of claims 1 to 6, characterized in that, The step of determining the cropping region on the adjusted target image based on the cropping frame includes: determining multiple extension intersection points of each edge of the cropping frame and the adjusted target image based on the coordinates of each vertex of the cropping frame and the coordinates of each vertex of the adjusted target image; determining a first value range of the cropping frame in a first dimension and a second value range in a second dimension based on the coordinates of the multiple extension intersection points; stretching the cropping frame to obtain a stretched cropping frame, wherein the size of the stretched cropping frame is larger than the size of the original cropping frame, and the values ​​of each vertex of the stretched cropping frame in the first dimension are within the first value range, and the values ​​of each vertex of the stretched cropping frame in the second dimension are within the second value range; and using the overlapping area between the stretched cropping frame and the adjusted target image as the cropping region.

9. An image cropping device, characterized in that, The device includes: a display module for displaying a target image to be cropped and a cropping frame; an adjustment module for adjusting the size of the rotated target image in response to the target image being rotated based on a rotation operation, and the presence of vertices of the cropping frame located outside the rotated target image, to obtain an adjusted target image such that all vertices of the cropping frame are located on the adjusted target image; a determination module for determining a cropping area on the adjusted target image based on the cropping frame; and a cropping module for obtaining a cropped image based on the cropping area. The adjustment module further includes adjusting the size of the rotated target image to obtain an adjusted target image, comprising: determining the circumscribed region of the cropping frame based on the coordinates of each vertex of the cropping frame, wherein the angle of the circumscribed region is the rotation angle of the target image, and each vertex of the cropping frame is located on the edge of the circumscribed region; determining the length and width of the circumscribed region; and adjusting the size of the rotated target image based on the length and width of the circumscribed region to obtain the adjusted target image. The step of adjusting the size of the rotated target image based on the length and width of the outer region to obtain an adjusted target image includes: determining at least one target vertex located outside the rotated target image among the vertices of the cropping frame, based on the condition that the length of the rotated target image is not less than the length of the outer region and / or the width of the rotated target image is not less than the width of the outer region; determining the target projection points corresponding to the at least one target vertex; determining a first distance and a second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex, wherein the first distance is a distance in a first dimension and the second distance is a distance in a second dimension; and adjusting the coordinates of each vertex of the rotated target image based on the first distance and the second distance to obtain an adjusted target image, wherein the size of the adjusted target image is larger than the size of the rotated target image. The step of determining the target projection points corresponding to the at least one target vertex includes: for any target vertex among the at least one target vertex, projecting the any target vertex onto each edge of the rotated target image to obtain multiple projection points corresponding to the any target vertex; determining the distances between the multiple projection points corresponding to the any target vertex and the any target vertex; and taking the projection points whose distances meet the distance requirements as the target projection points corresponding to the any target vertex. The step of determining the first distance and the second distance based on the coordinates of the at least one target vertex and the coordinates of the target projection points corresponding to the at least one target vertex includes: based on the fact that the number of target vertices is one, determining the first distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the first dimension, and determining the second distance based on the difference between the coordinates of the target vertex and the coordinates of the target projection point corresponding to the target vertex in the second dimension.

10. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one line of program code, the at least one line of program code being loaded and executed by the processor to enable the computer device to implement the image cropping method as described in any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one piece of program code, which is loaded and executed by a processor to enable the computer to implement the image cropping method as described in any one of claims 1 to 8.

Citation Information

Patent Citations

  • Method for shooting by rotating viewing frame

    CN103268590A

  • Picture clipping method and device in online presentation file, storage medium and equipment

    CN110568982A

  • Multifunctional Environment for Image Cropping

    US20130016122A1