Detailed Description
Exemplary embodiments of the present disclosure are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present disclosure to facilitate understanding, and should be considered as merely exemplary. Accordingly, one of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the present disclosure. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
In addition, it should be understood that the term "and/or" is merely an association relationship describing the association object, and means that three relationships may exist, for example, a and/or B, and that three cases, a alone, a and B together, and B alone, may exist. In addition, the character "/" herein generally indicates that the front and rear associated objects are an "or" relationship.
Fig. 1 is a flowchart of an embodiment of a text replacement method according to the present disclosure. As shown in fig. 1, the following detailed implementation is included.
In step 101, a picture to be processed is acquired and presented.
In step 102, a touch screen event of a picture to be processed is monitored, and an application line is generated and displayed according to a monitoring result, wherein the application line is used for identifying characters to be replaced in the picture to be processed.
In step 103, a target picture is generated according to the painted line, the obtained target text and the picture to be processed, wherein the target picture is obtained by replacing the text to be replaced with the target text.
By adopting the scheme of the embodiment of the method, the characters to be replaced in the pictures to be processed can be automatically replaced based on the obtained smearing lines, the target characters and the like, so that the character replacement requirement of a user is met, any characters required by the user can be replaced, the flexibility of editing the pictures is improved, the degree of freedom of creative expression of the user is improved, and the like.
In practical application, after a user enters a related editing page, a picture to be processed can be loaded and displayed, a canvas (canvas) can be initialized through a two-dimensional canvas class library (konva. Js), the picture to be processed is drawn on the canvas, and various events such as smearing, moving and the like can be bound for the canvas, so that various interaction functions can be realized.
Then, the user can switch to a character replacement function, namely canvas function setting (setCanvasMode) for character replacement can be performed, and further painting can be performed on the picture to be processed aiming at the character to be replaced, wherein painting can be performed at one place or at a plurality of places.
In the konva. Js framework, stage (Stage) and Layer (Layer) are two core concepts, and a user can create multiple layers on one Stage, each Layer being responsible for different editorial contents.
The touch screen event aiming at the picture to be processed can be monitored, and the smearing line can be generated according to the monitoring result. In some embodiments of the present disclosure, in response to monitoring a touch screen start (touchstart) event, a touch screen region may be determined according to the touch screen start event and a touch screen movement (touchmove) event and a touch screen end (touchend) event corresponding to the touch screen start event, which are monitored, and thus a line corresponding to the touch screen region may be determined as a smear line.
For example, a touch screen start event may be monitored on a stage, and when this event is monitored, a line object (Konva. Line) instance may be created and added to the current layer. The touch screen movement event can then be monitored on the stage, and a touch screen area (also referred to as a movement path or a painting area, etc.) is drawn by acquiring the movement track of the user's finger or cursor on the stage, and the touch screen area can be composed of a series of points (points). When the touch screen ending event is monitored, the ending of the coating process can be determined, and the coating line corresponding to the coating can be finally determined.
When the next touch screen start event is monitored, the above process may be repeated and another application line may be determined accordingly.
According to the method, the required smearing lines can be determined efficiently and accurately, so that a good foundation is laid for subsequent treatment.
And generating a final required target picture according to the coating line, the acquired target text and the picture to be processed. In some embodiments of the present disclosure, a mask (mask) picture corresponding to a picture to be processed may be generated according to a painted line first, and then a target picture may be generated according to the mask picture, a target text, and the picture to be processed. Accordingly, the target picture is generated based on the mask picture, and accuracy and the like of the obtained target picture can be improved.
In some embodiments of the disclosure, the method for generating the mask image corresponding to the image to be processed according to the application lines can comprise the steps of respectively determining the application line as the line to be optimized in response to each generation of the application line, generating a corresponding group (group) for the line to be optimized in response to the determination that the line to be optimized is the first application line generated or in response to the determination that the line to be optimized is the non-first application line and no target line exists in a historical line, wherein the group only comprises the line to be optimized, the historical line is the application line generated before the line to be optimized, the target line is the application line overlapped with the line to be optimized, merging the line to be optimized and the target line into the same group in response to the determination that the target line exists, and generating the mask image according to all current groups in response to the acquisition of a mask image generation instruction.
Assuming that the application line 1 is the first application line generated, after the application line 1 is generated, a group 1 corresponding to the application line 1 can be generated, only the application line 1 is included in the group 1, then the application line 2 is generated, no overlap exists between the application line 2 and the application line 1, a group 2 corresponding to the application line 2 can be generated, only the application line 2 is included in the group 2, then the application line 3 is generated, an overlap exists between the application line 3 and the application line 1, then the application line 3 can be combined into the group to which the application line 1 belongs, namely into the group 1, then the application line 4 is further generated, and an overlap exists between the application line 4 and the application line 2, then the application line 4 can be combined into the group to which the application line 2 belongs, namely into the group 2.
By combining the coating lines meeting the requirements into the same group, the subsequent management and operation of the coating lines can be facilitated.
In addition, undo and redo operations may also be supported in the schemes of the present disclosure, which may include picture granularity undo operations and smear granularity undo operations.
Fig. 2 is a schematic diagram of undo operations of different granularity as described in the present disclosure. As shown in fig. 2, the undoing operation of the picture granularity may refer to undoing the target picture to a picture to be processed, etc., the undoing operation of the coating granularity may refer to undoing one or more coating lines, and the redoing may refer to restoring the undone one or more coating lines.
Accordingly, in some embodiments of the present disclosure, in response to obtaining an application line withdrawal instruction, a newly generated application line may be determined from currently displayed application lines as a line to be processed, a group to which the line to be processed belongs may be determined as a group to be processed, then the line to be processed may be withdrawn and displayed, in response to determining that only the line to be processed is included in the group to be processed, the group to be processed may be withdrawn, and in response to determining that other application lines other than the line to be processed are included in the group to be processed, the group to which the other application lines belong may be redetermined according to the withdrawal operation. How the user issues the application line withdrawal instruction is not limited.
For example, after the application lines 1,2, 3, 4 and 5 are sequentially generated, the application line cancel instruction sent by the user is obtained, so that the application line 5 can be canceled and displayed, then the application line cancel instruction sent by the user is obtained, so that the application line 4 can be canceled and displayed, and so on.
In some embodiments of the present disclosure, in response to each generation of an application line, the application line may be recorded into a past (past) array in a history (history) stack record, where the past array and the future (future) array are both initially empty, and accordingly, after an application line withdrawal instruction is obtained, the application line at the top of the stack may be taken out of the past array, determined as a line to be processed, and the line to be processed may be added to the future array.
For example, after the application lines 1, 2,3, 4 and 5 are sequentially generated, an application line withdrawal instruction sent by the user is obtained, and then the application lines 1, 2,3, 4 and 5 are recorded in the past, the application line 5 at the top of the stack can be taken out from the past array according to the principle of first-in-last-out, and the application line 5 can be determined to be a line to be processed and added into the future array.
That is, to support undo and redo operations on the application line, a history stack of information may be maintained, which may include a past array for storing past states stored in chronological order, latest at the end of the data, and a future array for storing future states that, when the user performs an undo operation on the application line, will be entered into the future array, and subsequently, if a redo operation is performed, will never be moved back into the past array.
In practice, a present variable may also be maintained for storing the state in progress, such as the just-popped smear line. Therefore, when the undoing operation is executed, the coating line positioned at the top of the stack can be taken out of the past array and assigned to the current variable, the taken coating line can be put into the future array through the current variable, when the redoing operation is executed, the coating line positioned at the top of the stack can be taken out of the future array and assigned to the current variable, and the taken coating line can be put into the past array through the current variable. By means of the current variable, data transfer between the past and future arrays can be facilitated.
After determining the line to be treated, the line to be treated can be displayed in a dismissing manner, for example, the coating line 5 is displayed in a dismissing manner, and then the user can only see the displayed coating line 1, coating line 2, coating line 3 and coating line 4.
In addition, the group to which the line to be processed belongs can be determined and used as the group to be processed. In some embodiments of the disclosure, in response to each generation of an application line, the application line may be determined as a line to be optimized, and after a packet to which the line to be optimized belongs is determined, original packet (originGroup) information corresponding to the line to be optimized may be generated, where the original packet information includes a packet list (groupList) and a future packet list (futureGroupList), where a packet to which the line to be optimized belongs is recorded in the packet list, the future packet list is initially empty, and in response to determining that the line to be optimized is a generated non-first application line, for each historical line (an application line generated before the line to be optimized), a non-empty record may be added to the packet list corresponding to the historical line in response to determining that the line to be optimized is the same as the packet to which the historical line belongs, and in response to determining that the packet to which the line to be optimized belongs is different from the historical line, an empty record (null) is added to the packet list corresponding to the historical line, and in response to the operation, the application line to be processed is not the first update line, a new packet corresponding to the historical line is updated, and the first update record corresponding to the first update list is taken out, and the original packet list corresponding to the original packet list is taken out.
The original grouping information can be maintained for each coating line, so that the coating lines such as the to-be-processed groups and the like to which the to-be-processed lines belong can be conveniently and accurately determined by means of the original grouping information.
Further, after the lines to be processed are withdrawn, in response to determining that only the lines to be processed are included in the packets to be processed, the packets to be processed may be withdrawn, in response to determining that other coating lines except the lines to be processed are included in the packets to be processed, the packets to which the other coating lines belong may be redetermined according to the withdrawal operation.
In many cases, the packet to which the determined other application line belongs is still the previous packet. For example, assuming that the line to be processed is the application line 4, the group to be processed is the group 2, and the group 2 includes the application line 2 in addition to the application line 4, after the application line 4 is removed, the group to which the application line 2 belongs is still the group 2. However, for some special cases, for example, if there are 3 application lines, namely, an application line a, an application line b and an application line c in sequence from first to last according to the generation time, the application lines a and b originally belong to the group a and the group b respectively, but the application lines c, the application line a and b are overlapped, then the application lines a, b and c are combined into one group, such as the group c, at this time, the group a and the group b can be destroyed, and in this case, if the application line c is removed, the original group a and the group b can be recovered, namely, the application line a still belongs to the group a, and the application line a still belongs to the group b.
By the processing, the grouping conditions of the remaining unremoved coating lines can be updated in time according to the withdrawal conditions of the coating lines, so that the accuracy of subsequent processing results and the like are ensured.
Taking the application lines 1,2, 3, 4 and 5 generated in sequence, and the application lines 5, 4, 3 and 2 are withdrawn in sequence as an example, the above description will be further described below.
Fig. 3 is a schematic diagram of an updating manner of the history stack information and the original grouping information corresponding to each application line after the application line 1 is generated according to the present disclosure.
As shown in fig. 3, in the initial case, after the past array and the future array are both empty, the application line 1 may be recorded in the past array after the application line 1 is generated, and specific information of the application line 1 is recorded without limitation, and in addition, assuming that the packet to which the application line 1 belongs is packet 1, original packet information corresponding to the application line 1 may also be generated, where packet 1 is recorded in a packet list, and the future packet list is empty.
Fig. 4 is a schematic diagram of an update manner of the history stack information and the original packet information corresponding to each application line after the application line 2 is generated according to the present disclosure.
As shown in fig. 4, after the application line 2 is generated, the application line 2 may be recorded in the past array, if there is no overlap between the application line 2 and the application line 1, and if the packet to which the application line 2 belongs is the packet 2, then the original packet information corresponding to the application line 2 may also be generated, where the packet 2 is recorded in the packet list, in addition, the original packet information corresponding to the application line 1 may also be updated, and since the application line 2 is different from the packet to which the application line 1 belongs, an empty record, that is, null, may be added in the packet list of the original packet information corresponding to the application line 1.
Fig. 5 is a schematic diagram of an update manner of the history stack information and the original packet information corresponding to each application line after the application line 3 is generated according to the present disclosure.
As shown in fig. 5, after the application line 3 is generated, the application line 3 may be recorded in the past array, if there is an overlap between the application line 3 and the application line 1, and if the packet to which the application line 3 belongs is the packet 1, then the original packet information corresponding to the application line 3 may be generated, where the packet 1 is recorded in the packet list, and in addition, the original packet information corresponding to the application line 1 and the application line 2 may be updated, where, since the packet to which the application line 2 belongs is different from the packet to which the application line 3 belongs, an empty record may be added in the packet list of the original packet information corresponding to the application line 2, and since the packet to which the application line 1 and the application line 3 belong is the same, a non-empty record may be added in the packet list of the original packet information corresponding to the application line 1 for recording the packet 1 to which the application line 3 belongs.
Fig. 6 is a schematic diagram of an update manner of the history stack information and the original packet information corresponding to each application line after the application line 4 is generated according to the present disclosure.
As shown in fig. 6, after the application line 4 is generated, the application line 4 may be recorded in the past array, if there is an overlap between the application line 4 and the application line 2, and if the packet to which the application line 4 belongs is the packet 2, then the original packet information corresponding to the application line 4 may be generated, where the packet 2 is recorded in the packet list, and in addition, the original packet information corresponding to the application line 1, the application line 2 and the application line 3 may be updated, where, because the packet to which the application line 3 and the application line 4 belong is different, an empty record may be added in the packet list of the original packet information corresponding to the application line 3, and because the packet to which the application line 2 and the application line 4 belong is the same, a non-empty record may be added in the packet list of the original packet information corresponding to the application line 2, and because the packet to which the application line 1 and the application line 4 belong is also different, an empty record may be added in the packet list of the original packet information corresponding to the application line 1.
Fig. 7 is a schematic diagram of an update manner of the history stack information and the original packet information corresponding to each application line after the application line 5 is generated according to the present disclosure.
As shown in fig. 7, after the application line 5 is generated, the application line 5 may be recorded in the past array, and if no overlap exists between the application line 5 and each other application line, and if the packet to which the application line 5 belongs is the packet 3, then the original packet information corresponding to the application line 5 may be generated, where the packet 3 is recorded in the packet list, and in addition, the original packet information corresponding to the application line 1, the application line 2, the application line 3, and the application line 4 may be updated, where, since the packet to which the application line 5 belongs is different from each other application line, an empty record may be added to the packet list of the original packet information corresponding to the application line 1, the application line 2, the application line 3, and the application line 4.
Fig. 8 is a schematic diagram of updating the historical stack information and the original grouping information corresponding to each application line after the application line 5 is removed according to the present disclosure.
As shown in fig. 8, the application line 5 may be first taken out from the past array and added to the future array, and then the original grouping information corresponding to the application line 1, the application line 2, the application line 3, the application line 4 and the application line 5 may be updated respectively, that is, the record at the top of the stack is taken out from the grouping list and added to the future grouping list, in addition, since the grouping 3 to which the application line 5 belongs only includes the application line 5, the grouping 3 may be cancelled, and from the perspective of the user, the displayed application line 1, application line 2, application line 3 and application line 4 are unchanged, but the application line 5 is cancelled and displayed.
Fig. 9 is a schematic diagram of updating the history stack information and the original packet information corresponding to each application line after the application line 4 is removed according to the present disclosure.
As shown in fig. 9, the application line 4 may be first taken out from the past array and added into the future array, and then the original grouping information corresponding to the application line 1, the application line 2, the application line 3 and the application line 4 may be updated respectively, that is, the record at the top of the stack is taken out from the grouping list and added into the future grouping list, in addition, the grouping 2 to which the application line 4 belongs further includes the application line 2, which belongs to the grouping 2, from the background point of view, the application line 2 may be redrawn, but from the point of view of the user, the displayed application line 1, the application line 2 and the application line 3 are unchanged, and only the application line 4 is further shown in a withdrawal mode.
Fig. 10 is a schematic diagram of updating the history stack information and the original packet information corresponding to each application line after the application line 3 is removed according to the present disclosure.
As shown in fig. 10, the application line 3 may be first taken out from the past array and added into the future array, and then the original grouping information corresponding to the application line 1, the application line 2 and the application line 3 may be updated respectively, that is, the record at the top of the stack is taken out from the grouping list and added into the future grouping list, in addition, the grouping 1 to which the application line 3 belongs further includes the application line 1, the grouping to which the application line 3 belongs still is the grouping 1, from the background point of view, the application line 1 may be redrawn, but from the point of view of the user, the displayed application line 1 and the application line 2 are unchanged, and only the application line 3 is further shown in a withdrawal manner.
Fig. 11 is a schematic diagram of updating the history stack information and the original packet information corresponding to each application line after the application line 2 is removed according to the present disclosure.
As shown in fig. 11, the application line 2 may be first taken out from the past array and added to the future array, and then the original grouping information corresponding to the application line 1 and the application line 2 may be updated respectively, that is, the record at the top of the stack is taken out from the grouping list and added to the future grouping list, and in addition, the grouping 2to which the application line 2 belongs does not include other application lines any more, so that the grouping 2 may be revoked, and from the perspective of the user, the displayed application line 1 is unchanged, but the application line 2 is further revoked and displayed.
In some embodiments of the present disclosure, when each packet is generated, mapping (map) information corresponding to the packet may also be generated separately, where the mapping information synchronously records the smear lines included in the corresponding packet, and accordingly, for the packet to be processed, whether the packet to be processed includes only the line to be processed may be determined by querying mapping information corresponding to the packet to be processed.
For example, when generating the packet 1, mapping information corresponding to the packet 1 may be generated, where only the application lines 1 are recorded, and if the subsequent application lines 3 are combined into the packet 1, the application lines 3 are correspondingly added in the mapping information, that is, the mapping information may be synchronously updated according to the change condition of the application lines included in the packet 1, so that the subsequent application lines included in the packet to be processed may be quickly and accurately determined according to the mapping information.
As previously described, the scheme of the present disclosure supports redo operations in addition to undo operations. Accordingly, in some embodiments of the present disclosure, in response to obtaining at least one application line undo instruction, obtaining an application line redo instruction, determining an application line that was undone and displayed last time as a line to be redone, and resuming displaying the line to be redone.
For example, after the application line 5, the application line 4, the application line 3 and the application line 2 are sequentially withdrawn and displayed, the application line 2 can be displayed again after the application line redo instruction is obtained, the application line 3 can be displayed again after the application line redo instruction is obtained, and so on.
That is, by adopting the scheme disclosed by the disclosure, a user can cancel or redo any smearing line according to actual needs, so that different use requirements of the user can be met, and the flexibility of editing pictures and the like are further improved.
In some embodiments of the present disclosure, when determining the line to be reworked, the line to be reworked may be taken out of the unused array as the line to be reworked, and may be added to the past array.
In addition, in some embodiments of the present disclosure, the method for recovering and displaying the line to be reworked may include updating original grouping information corresponding to the line to be reworked according to a second updating method, where the second updating method includes taking out a record located at a stack top of a future grouping list, adding the record to the grouping list, recovering and displaying the line to be reworked, and updating original grouping information corresponding to each painted line in a past array before adding the line to be reworked according to the second updating method.
When the line is reworked, the historical stack information and the related original grouping information can be processed in a mode opposite to that when the line is displayed in a withdrawal mode, so that the method is simple and convenient, and the accuracy of a processing result and the like are ensured.
In addition, when the lines to be reworked are restored to be displayed, the lines to be reworked can be regarded as newly generated coating lines, and the related processing is carried out on the lines to be reworked according to the processing mode when the coating lines are generated.
The foregoing mainly describes the undoing operation and the redoing operation of the smearing granularity, the undoing operation of the picture granularity is relatively simple to implement, if a history stack information can be generated, the history stack information comprises a past array and a future array, the updated picture can be recorded into the past array each time the picture of the picture granularity is updated, when the picture is undone, the picture positioned at the stack top can be taken out from the past array, and the picture can be put into the future array, and the picture display can be updated according to the undoing operation.
When the user considers that the smearing lines are not required to be adjusted any more, a mask image generation instruction can be sent out, and accordingly, a mask image can be generated according to all current groups. How the user issues the mask picture generation instruction is not limited, and for example, may be to click a predetermined button or the like.
In some embodiments of the present disclosure, the method for generating a mask picture according to all current packets may include creating a result canvas, filling the result canvas with a predetermined color, sorting all current packets according to a predetermined order, traversing each packet in turn according to a front-to-back sorting order, and drawing, for each traversed packet, a coating line in the packet onto the result picture according to a corresponding color, where colors corresponding to the packets located at different sorting positions are defined in advance, where colors corresponding to any two packets are different, and where colors corresponding to any two packets are not the predetermined color, converting, in response to determining that traversing is finished, the latest obtained result canvas into a predetermined picture format, and obtaining the mask picture.
The specific order of the predetermined sequence can be determined according to actual needs, so long as the predetermined sequence can be matched with the subsequent target text input sequence. For example, all packets may be currently ordered in order of generation time from first to last.
Since text replacement usually involves multiple replacements, in order to make the coating lines correspond to the input target text, in the scheme disclosed in the disclosure, the coating layers to be coated fill different colors according to the coating sequence, that is, the coating layers may be in a predetermined color, for example, black, and the color of the coating lines above may be determined according to the coating sequence, so that the coating sequence may be determined based on the different colors by analyzing the coating pictures.
In addition, in the scheme disclosed in the disclosure, an order (order) value can be set for each packet, and the order of generating the packets is marked. For example, after an application line is generated, if it is determined that the application line does not meet the merging condition, the order value with the largest value may be selected from the order values of the generated packets, and after 1 is added to the order value with the largest value, the value may be used as the order value of the packet to which the application line belongs, if it is determined that the application line meets the merging condition, the order value of the merged packet may be inherited, if it is merged into the existing packet 1, the order value is 1, and in addition, when the undoing operation or the redoing operation is performed, the order value of the related packet may be adjusted if necessary. Accordingly, all packets may be currently ordered in a time-of-generation from first to last order based on the order value.
An initial result canvas and context may be created, after which the result picture may be filled with a predetermined color, such as black, after which each packet may be sequentially traversed in a front-to-back ordering order, and for each traversed packet, the smear lines in the packet may be drawn onto the result picture in a corresponding color, specifically, a temporary canvas and context may be created, the smear lines in the packet may be drawn onto the temporary canvas, after which the drawn content may be modified to a corresponding color according to the ordering position of the packet, further, the content in the temporary canvas may be drawn onto the result canvas according to the position of the smear lines in the packet in the picture to be processed, etc., after all packets are processed in the above manner, the latest obtained result canvas may be converted into a predetermined picture format, which is not limited in format, such as a portable graphic (PNG, portable Network Graphics) picture based on base64 encoding, which is an encoding manner for transmitting 8-bit byte codes.
In addition to obtaining the mask layer picture, in some embodiments of the present disclosure, M groups of target characters sequentially input by a user in an input box may be obtained, the value of M is the same as the number of all the current groups, a line changing symbol may be used to mark between adjacent groups of target characters, accordingly, according to different colors drawn in the mask layer picture, the position of M groups of to-be-replaced characters in the to-be-processed picture and the replacement sequence of M groups of to-be-replaced characters may be determined, and optical character recognition (OCR, optical Character Recognition) may be performed on the to-be-processed picture to obtain a character recognition result, and then, according to the position of M groups of to-be-replaced characters and the character recognition result, the to-be-replaced character with the replacement sequence of i bits may be replaced by using the target characters input for i times, and i is not less than 1 and not more than M, and then the target picture may be generated according to the replacement result.
In addition, in some embodiments of the present disclosure, one or any combination of the following processes may be performed, where before determining the positions of M groups of to-be-replaced characters in the to-be-processed picture and the replacement sequence of the M groups of to-be-replaced characters, in response to determining that the sizes of the mask picture and the to-be-processed picture are different, the size of the mask picture is adjusted to be the size of the to-be-processed picture, the aspect ratio of the mask picture and the to-be-processed picture is the same, before performing OCR recognition on the to-be-processed picture, performing picture quality optimization processing on the to-be-processed picture, and after generating the target picture, performing picture quality optimization processing on the target picture.
For example, the size of the to-be-processed picture is 1000×1000, and the size of the mask picture is 100×100, then the mask picture can be adjusted to 1000×1000, so that when the positions of the M groups of to-be-replaced characters and the replacement sequence of the M groups of to-be-replaced characters in the to-be-processed picture are determined according to different colors drawn in the mask picture, the accuracy of the determination result can be improved.
In addition, quality optimization processing can be performed on the picture to be processed, so that accuracy of a subsequent OCR recognition result is improved. For example, denoising, normalization, color adjustment and other processes can be performed on the image to be processed, wherein the denoising process can eliminate noise points possibly interfering with OCR recognition, the normalization process can keep the brightness and contrast of the image stable so as to adapt to different shooting environments, the color adjustment process is helpful to improve the contrast of texts and backgrounds, and the processes can help to improve the accuracy of OCR recognition results and enhance the overall robustness of the system.
The text in the picture can be converted into an editable text format by performing OCR (optical character recognition) on the picture to be processed, a natural language processing (NLP, natural Language Processing) technology can be introduced on the basis of OCR, the system can understand the semantic relation of text content by utilizing the NLP technology, in certain scenes, some characters can be misidentified by OCR, and the NLP technology can correct the errors by context reasoning, in addition, parameters of OCR can be automatically adjusted to adapt to different text formats, and the cross-language recognition capability and the like are improved.
Assuming that the value of M is 3, in order to facilitate expression, M groups of to-be-replaced characters are respectively referred to as to-be-replaced character 1, to-be-replaced character 2 and to-be-replaced character 3, and M groups of target characters are respectively referred to as target character 1, target character 2 and target character 3, taking to-be-replaced character 1 as an example, a deep learning repair network or a traditional binocular stereo matching (PATCHMATCH) algorithm can be adopted to remove to-be-replaced character 1, and filling content matched with a background can be generated so as to prevent edge blurring or repair artifacts from occurring, the deep learning repair network can intelligently predict the content of an occluded area, and automatically fill appropriate pixel values so as to enable the to be naturally fused with surrounding environment, and the deep learning algorithm can learn a more complex texture mode, so that the repair result is more complicated, in order to further improve the naturalness of repair, the image style migration technology can be utilized, after that the filling content and the original background style are seamlessly joined as much as possible, the target character 1 can be added into a to-be-processed picture, and the target character 1 can be determined according to user preference and/or the deep learning algorithm, and the color of the target character 1 can be migrated in a real style, and the font style can be synthesized, and the font style 1 can be synthesized by the real style.
In addition, in some embodiments of the present disclosure, after the text is replaced, N target pictures with different styles may be generated according to the replacing result, where N is a positive integer greater than 1, and the specific value may be determined according to the actual needs.
A plurality of target pictures with different styles can be provided for users to select, so that individuation and flexibility are improved, and the different styles can comprise classical styles, modern styles, artistic styles and the like, so that different use requirements of the users can be met.
Further, the image quality optimization processing can be performed on the target image. For example, super-Resolution enhancement (Super-Resolution) and denoising processes may be performed on the target picture to improve the sharpness of the target picture.
In connection with the foregoing description, fig. 12 is a schematic diagram of an overall implementation process of the text replacement method according to the present disclosure. As shown in fig. 12, a to-be-processed picture may be obtained and displayed first, then, a relevant process of the coating line may be performed, for example, a touch screen event for the to-be-processed picture may be monitored, a coating line may be generated and displayed according to a monitoring result, in addition, for each coating line, a group to which the coating line belongs may be determined separately, and a undoing operation, a redoing operation, etc. may be supported for each coating line, then, a mask picture corresponding to the to-be-processed picture may be generated according to the coating line, that is, a coating trace may be derived, for example, in response to obtaining a mask picture generation instruction, a mask picture may be generated according to all groups at present, further, a target text input by a user may be obtained, and then, a plurality of target pictures with different styles may be generated according to the mask picture, the target text, and the to-be-processed picture.
It should be noted that, for the sake of simplicity of description, the foregoing method embodiments are all expressed as a series of combinations of actions, but it should be understood by those skilled in the art that the present disclosure is not limited by the order of actions described, as some steps may take place in other order or simultaneously in accordance with the present disclosure. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all of the preferred embodiments, and that the acts and modules referred to are not necessarily required by the present disclosure. In addition, portions of one embodiment that are not described in detail may be referred to in the description of other embodiments.
The foregoing is a description of embodiments of the method, and the following further describes embodiments of the present disclosure through examples of apparatus.
Fig. 13 is a schematic diagram of a composition structure of an embodiment 1300 of a text replacement device according to the present disclosure. As shown in fig. 13, includes an acquisition module 1301, a generation module 1302, and a replacement module 1303.
An obtaining module 1301, configured to obtain and display a to-be-processed picture.
The generating module 1302 is configured to monitor a touch screen event for a picture to be processed, generate a painted line according to a monitoring result, and display the painted line, where the painted line is used to identify a text to be replaced in the picture to be processed.
The replacing module 1303 is configured to generate a target picture according to the line, the obtained target text, and the to-be-processed picture, where the target picture is a picture obtained by replacing the to-be-replaced text with the target text.
By adopting the scheme of the embodiment of the device, the to-be-replaced characters in the to-be-processed picture can be automatically replaced based on the obtained smearing lines, the target characters and the like, so that the character replacement requirement of a user is met, any characters required by the user can be replaced, the flexibility of editing the picture is improved, the degree of freedom of creative expression of the user is improved, and the like.
In some embodiments of the present disclosure, the generating module 1302 may determine, in response to monitoring the touch screen start event, a touch screen area according to the touch screen start event and the touch screen movement event and the touch screen end event corresponding to the monitored touch screen start event, and may further determine a line corresponding to the touch screen area as a smearing line.
In addition, in some embodiments of the present disclosure, the replacing module 1303 may first generate a mask image corresponding to the to-be-processed image according to the application line, and then may generate the target image according to the mask image, the target text, and the to-be-processed image.
In some embodiments of the present disclosure, the manner of generating the mask image corresponding to the image to be processed by the replacing module 1303 according to the application lines may include determining the application line as a line to be optimized in response to each generation of the application line, generating a corresponding group for the line to be optimized in response to determining that the line to be optimized is a first application line generated or in response to determining that the line to be optimized is a non-first application line and determining that no target line exists in the history line, where the group includes only the line to be optimized, the history line is the application line generated before the line to be optimized, and the target line is the application line overlapping the line to be optimized, merging the line to be optimized and the target line into the same group in response to determining that the target line exists, and generating the mask image according to all the current groups in response to obtaining the mask image generation instruction.
Undo and redo operations may also be supported in the schemes described in this disclosure. Accordingly, in some embodiments of the present disclosure, in response to obtaining the application line withdrawal instruction, the replacing module 1303 may determine, as a line to be processed, a newly generated application line from currently displayed application lines, and may determine, as a group to be processed, a group to which the line to be processed belongs, and then may withdraw the line to be processed from being displayed, and in response to determining that only the line to be processed is included in the group to be processed, may withdraw the group to be processed, and in response to determining that other application lines other than the line to be processed are included in the group to be processed, may redetermine the group to which the other application lines belong according to the withdrawal operation.
In some embodiments of the present disclosure, the replacing module 1303 may record, in response to each application line being generated, the application line in a past array in the history stack information, where the past array and the future array are both initially empty, and accordingly, after the application line withdrawal instruction is obtained, the application line at the top of the stack may be taken out of the past array, determined as a line to be processed, and the line to be processed may be added to the future array.
In some embodiments of the disclosure, a replacing module 1303 may determine, in response to each generation of an application line, the application line as a line to be optimized, and may generate, after determining that a packet to which the line to be optimized belongs, original packet information corresponding to the line to be optimized, where the original packet information includes a packet list and a future packet list, the packet list is recorded with the packet to which the line to be optimized belongs, the future packet list is initially empty, and, in response to determining that the line to be optimized is a generated non-first application line, for each historical line (the application line generated before the line to be optimized), may perform a process of adding, in response to determining that the line to be optimized is the same as the packet to which the historical line belongs, a non-empty record in the packet list corresponding to the historical line, and in response to determining that the packet to which the line to be optimized belongs is different from the packet to which the historical line belongs, adding, in the packet list corresponding to the historical line, when performing a revocation operation, updating the original packet information corresponding to the line to be processed in a first update manner, the first packet information corresponding to the line to be optimized (the historical line) may be updated, the first update record may be added to the original packet list, and the original packet corresponding to the previous packet list may be taken out, and the original packet list may be updated according to the update.
In some embodiments of the present disclosure, when generating each packet, the replacing module 1303 may also generate mapping information corresponding to the packet, where the mapping information synchronously records smearing lines included in the corresponding packet, and accordingly, for a packet to be processed, it may be determined whether the packet to be processed includes only the line to be processed by querying mapping information corresponding to the packet to be processed.
As previously described, the scheme of the present disclosure supports redo operations in addition to undo operations. Accordingly, in some embodiments of the present disclosure, the replacing module 1303 obtains the application line redoing instruction in response to obtaining the at least one application line undoing instruction, so as to determine the application line that was undone and displayed at the latest time as the line to be redone, and can resume displaying the line to be redone.
In some embodiments of the present disclosure, when determining the line to be reworked, the replacing module 1303 may take the line on the top of the stack from the unused array as the line to be reworked, and may add the line to be reworked to the past array.
In addition, in some embodiments of the present disclosure, the replacing module 1303 may restore the manner of displaying the line to be reworked by updating the original grouping information corresponding to the line to be reworked according to a second updating manner, where the second updating manner includes fetching a record located at the stack top of the future grouping list, adding the record to the grouping list, restoring to display the line to be reworked, and updating the original grouping information corresponding to each of the smeared lines in the past array before adding the line to be reworked according to the second updating manner.
In some embodiments of the present disclosure, the method for generating a mask picture by the replacing module 1303 according to all current packets may include creating a result canvas, filling the result canvas with a predetermined color, sorting all current packets according to a predetermined order, traversing each packet in turn according to a front-to-back sorting order, and drawing a coating line in each traversed packet onto the result picture according to a corresponding color, where colors corresponding to the packets located at different sorting positions are defined in advance, the colors corresponding to any two packets are different, and the colors corresponding to any two packets are not the predetermined color, and converting the latest obtained result canvas into a predetermined picture format in response to determining that traversing is completed, so as to obtain the mask picture.
In addition to obtaining the mask layer picture, in some embodiments of the present disclosure, the replacing module 1303 may further obtain M groups of target characters sequentially input by a user in an input box, where the value of M is the same as the number of all the current groups, and the adjacent groups of target characters may be marked by a line-changing symbol, accordingly, according to different colors drawn in the mask layer picture, the positions of M groups of to-be-replaced characters in the to-be-processed picture and the replacement sequence of M groups of to-be-replaced characters may be determined, and may perform optical character recognition on the to-be-processed picture to obtain a character recognition result, and then may replace the to-be-replaced character with the replacement sequence of the i bit by using the to-be-replaced character with the i-th input target character according to the positions of M groups of to the to-be-replaced characters and the character recognition result, where i is equal to or less than M is greater than or equal to 1, and further may generate the target picture according to the replacement result.
In addition, in some embodiments of the present disclosure, the replacing module 1303 may further perform one or any combination of determining a position of M groups of characters to be replaced in the image to be processed and a replacing sequence of the M groups of characters to be replaced, adjusting a size of the mask image to be the size of the image to be processed in response to determining that the size of the mask image is different from the size of the image to be processed, adjusting an aspect ratio of the mask image to be processed to be the same as that of the image to be processed, performing image quality optimization processing on the image to be processed before performing OCR recognition on the image to be processed, and performing image quality optimization processing on the target image after generating the target image.
In some embodiments of the present disclosure, after the replacing module 1303 completes the replacement of the text, N target pictures with different styles may also be generated according to the replacing result, where N is a positive integer greater than 1.
The specific workflow of the above apparatus embodiment may refer to the related description in the foregoing method embodiment, and will not be repeated.
The scheme disclosed by the disclosure can be applied to the field of artificial intelligence, and particularly relates to the fields of computer vision, image processing, natural language processing and the like. Artificial intelligence is the subject of studying certain thinking processes and intelligent behaviors (such as learning, reasoning, thinking, planning, etc.) that make a computer simulate a person, and has technology at both hardware and software levels, and artificial intelligence hardware technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing, etc., and artificial intelligence software technologies mainly include computer vision technologies, speech recognition technologies, natural language processing technologies, machine learning/deep learning, big data processing technologies, knowledge graph technologies, etc.
In addition, the pictures, the text, and the like in the embodiments of the present disclosure are not specific to a specific user, and cannot reflect personal information of a specific user. In the technical scheme of the disclosure, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing and the like of the personal information of the user accord with the regulations of related laws and regulations, and the public order colloquial is not violated.
According to embodiments of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.
Fig. 14 shows a schematic block diagram of an electronic device 1400 that may be used to implement embodiments of the present disclosure. Electronic devices are intended to represent various forms of digital computers, such as laptops, desktops, workstations, servers, blade servers, mainframes, and other appropriate computers. The electronic device may also represent various forms of mobile apparatuses, such as personal digital assistants, cellular telephones, smartphones, wearable devices, and other similar computing apparatuses. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the disclosure described and/or claimed herein.
As shown in fig. 14, the electronic device 1400 includes a computing unit 1401 that can perform various appropriate actions and processes according to a computer program stored in a Read-only memory (ROM) 1402 or a computer program loaded from a storage unit 1408 into a random access memory (RAM, random Access Memory) 1403. In the RAM 1403, various programs and data required for the operation of the electronic device 1400 can also be stored. The computing unit 1401, the ROM 1402, and the RAM 1403 are connected to each other through a bus 1404. An Input/Output (I/O) interface 1405 is also connected to bus 1404.
A plurality of components in the electronic device 1400 are connected to the I/O interface 1405, including an input unit 1406 such as a keyboard, a mouse, or the like, an output unit 1407 such as various types of displays, speakers, or the like, a storage unit 1408 such as a magnetic disk, an optical disk, or the like, and a communication unit 1409 such as a network card, a modem, a wireless communication transceiver, or the like. The communication unit 1409 allows the electronic device 1400 to exchange information/data with other devices through a computer network such as the internet and/or various telecommunications networks.
The computing unit 1401 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of computing unit 1401 include, but are not limited to, a central Processing unit (CPU, central Processing Unit), a graphics Processing unit (GPU, graphic Processing Unit), various specialized artificial intelligence (AI, artificial Intelligence) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSP, digital Signal Processing), and any suitable processor, controller, microcontroller, etc. The computing unit 1401 performs the various methods and processes described above, such as the methods described in this disclosure. For example, in some embodiments, the methods described in the present disclosure may be implemented as a computer software program tangibly embodied on a machine-readable medium, such as the storage unit 1408. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 1400 via the ROM 1402 and/or the communication unit 1409. When the computer program is loaded into RAM 1403 and executed by computing unit 1401, one or more steps of the methods described in the present disclosure may be performed. Alternatively, in other embodiments, computing unit 1401 may be configured to perform the methods described in the present disclosure in any other suitable way (e.g. by means of firmware).
Various implementations of the systems and techniques described here above can be implemented in digital electronic circuitry, integrated Circuit System, field programmable gate array (FPGA, fieldProgrammable GATE ARRAY), application Specific Integrated Circuit (ASIC), application SPECIFIC INTEGRATED Circuit, application Specific Standard Product (ASSP) SPECIFIC STANDARDPARTS, system On Chip (SOC), complex programmable logic device (CPLD, complex Programmable Logic Device), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include being implemented in one or more computer programs that are executable and/or interpretable on a programmable system including at least one programmable processor, which may be a special or general purpose programmable processor, operable to receive data and instructions from, and to transmit data and instructions to, a storage system, at least one input device, and at least one output device.
Program code for carrying out methods of the present disclosure may be written in any combination of one or more programming languages. These program code may be provided to a processor or controller of a general purpose computer, special purpose computer, or other programmable data processing apparatus such that the program code, when executed by the processor or controller, causes the functions/operations specified in the flowchart and/or block diagram to be implemented. The program code may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of this disclosure, a machine-readable medium may be a tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a random access Memory, a read-Only Memory, an erasable programmable read-Only Memory (EPROM), a flash Memory, an optical fiber, a compact disc read-Only Memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on a computer having a display device (e.g., a Cathode Ray Tube (CRT) or Liquid Crystal Display (LCD) CRYSTAL DISPLAY) monitor) for displaying information to the user and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the computer. Other kinds of devices may also be used to provide for interaction with a user, for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback), and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of the communication network include a local area network (LAN, local Area Network), a Wide Area Network (WAN), and the internet.
The computer system may include a client and a server. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server may be a cloud server, a server of a distributed system, or a server incorporating a blockchain.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps recited in the present disclosure may be performed in parallel or sequentially or in a different order, provided that the desired results of the technical solutions of the present disclosure are achieved, and are not limited herein.
The above detailed description should not be taken as limiting the scope of the present disclosure. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present disclosure are intended to be included within the scope of the present disclosure.