Disclosure of Invention
The application aims to provide a method and a device for controlling a robot to draw an image, the robot and a computer readable medium.
A first aspect of the application provides a method of controlling a robot to render an image, comprising:
acquiring a target image to be drawn;
decomposing the target image into a plurality of layers of contours from outside to inside step by step, and generating a contour track point sequence corresponding to each layer of contour;
and carrying out data cleaning on the contour track point sequence according to a preset drawing precision range, and inputting the contour track point sequence subjected to data cleaning into a mechanical arm for drawing.
In some embodiments of the present application, the decomposing the target image into multiple layers of contours from outside to inside step by step and generating a sequence of contour track points corresponding to each layer of contours includes:
s1, retrieving the outermost layer contour of the target image and recording the retrieved initial contour track point sequence;
step S2, adjusting the initial contour track point sequence according to a preset stroke width, and generating a contour track point sequence corresponding to the outermost contour;
step S3, subtracting the outermost layer contour from the target image to obtain a residual image;
step S4, the same processing from step S1 to step S3 is carried out on the residual partial images until the condition of ending the retrieval is triggered; the search ending condition is as follows: and calculating to obtain the area of the image of the residual part, and finishing the retrieval if the area of the image of the residual part is smaller than a preset area threshold.
In some embodiments of the present application, the performing data cleaning on the contour trace point sequence according to a preset drawing precision range includes:
calculating the distance between the current track point and the next track point from the initial track point of each layer of outline;
if the distance is smaller than a preset drawing precision range, filtering the next track point;
if the distance is larger than the preset drawing precision range, searching from the next track point again until all track points on the current contour are traversed, and finishing primary filtering;
and after the preliminary filtering, if the number of the residual track points in the current contour is 1, deleting the contour.
In some embodiments of the present application, before the step of decomposing the target image into the multi-layer contour from outside to inside, the method further includes:
and preprocessing the target image.
A second aspect of the present application provides an apparatus for controlling a robot to draw an image, comprising:
the acquisition module is used for acquiring a target image to be drawn;
the generating module is used for decomposing the target image into a plurality of layers of contours from outside to inside step by step and generating a contour track point sequence corresponding to each layer of contour;
and the data cleaning module is used for carrying out data cleaning on the contour track point sequence according to a preset drawing precision range and inputting the contour track point sequence subjected to data cleaning into the mechanical arm for drawing.
In some embodiments of the present application, the generating module is specifically configured to:
s1, retrieving the outermost layer contour of the target image, and recording the retrieved initial contour track point sequence;
s2, adjusting the initial contour track point sequence according to a preset stroke width, and generating a contour track point sequence corresponding to the outermost contour;
s3, subtracting the outermost layer outline from the target image to obtain a residual image;
s4, the same processing from S1 to S3 is carried out on the residual images until the condition of ending the retrieval is triggered; the search ending condition is as follows: and calculating to obtain the area of the image of the residual part, and finishing the retrieval if the area of the image of the residual part is smaller than a preset area threshold.
In some embodiments of the present application, the data cleansing module is specifically configured to:
calculating the distance between the current track point and the next track point from the initial track point of each layer of outline;
if the distance is smaller than a preset drawing precision range, filtering the next track point;
if the distance is larger than the preset drawing precision range, searching from the next track point again until all track points on the current contour are traversed, and finishing primary filtering;
and after the preliminary filtering, if the number of the residual track points in the current contour is 1, deleting the contour.
In some embodiments of the present application, the apparatus further comprises:
and the preprocessing module is used for preprocessing the region image before the generation module gradually decomposes the target image into a plurality of layers of contours from outside to inside.
A third aspect of the present application provides a robot comprising: memory, a processor and a computer program stored on the memory and executable on the processor, the processor executing the computer program when executing the computer program to perform the method of the first aspect of the application.
A fourth aspect of the present application provides a computer readable medium having computer readable instructions stored thereon which are executable by a processor to implement the method of the first aspect of the present application.
Compared with the prior art, the method, the device, the robot and the medium for controlling the robot to draw the image are realized by acquiring the target image to be drawn; decomposing the target image into a plurality of layers of contours from outside to inside step by step, and generating a contour track point sequence corresponding to each layer of contour; and carrying out data cleaning on the contour track point sequence according to a preset drawing precision range, and inputting the contour track point sequence subjected to data cleaning into a mechanical arm for drawing. This scheme can be according to the input image to and the effective drawing precision of actual arm, generate the drawing orbit, can draw the input image completely, and optimize the process that the arm was drawn, thereby satisfied the diversified demand of user.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
It is to be noted that, unless otherwise specified, technical or scientific terms used herein shall have the ordinary meaning as understood by those skilled in the art to which this application belongs.
In addition, the terms "first" and "second", etc. are used to distinguish different objects, rather than to describe a particular order. Furthermore, the terms "include" and "have," as well as any variations thereof, are intended to cover non-exclusive inclusions. For example, a process, method, system, article, or apparatus that comprises a list of steps or elements is not limited to only those steps or elements listed, but may alternatively include other steps or elements not listed, or inherent to such process, method, article, or apparatus.
The embodiment of the application provides a method and a device for controlling a robot to draw an image, the robot and a computer readable medium, which are described below with reference to the accompanying drawings.
Referring to fig. 1, which illustrates a flowchart of a method for controlling a robot to draw an image according to some embodiments of the present application, as shown, the method for controlling the robot to draw an image may include the following steps:
step S101: acquiring a target image to be drawn;
in this embodiment, the target image may be any image, for example, a portrait, a forest landscape, or the like, a color image, or a binary image such as black and white.
In order to better meet the user requirement, in some embodiments of the present application, before step S102, the method may further include: and preprocessing the target image.
For example, after a portrait of a person is obtained, different machine vision preprocessing is performed on the portrait of the person according to the actual needs of a user, such as image sharpening on a blurred image, adaptive filtering on a noise image, smoothing on a rough-line image, and the like.
Step S102: decomposing the target image into a plurality of layers of contours from outside to inside step by step, and generating a contour track point sequence corresponding to each layer of contour;
in this embodiment, as shown in fig. 2, step S102 may specifically be implemented as follows:
step S201, retrieving the outermost layer contour of the target image, and recording the retrieved initial contour track point sequence;
for example, searching all the outlines of a portrait of a person from outside to inside, first searching the outermost outline of the portrait of the person, a large number of outline trace points may be searched, and a sequence α 1 of the searched initial outline trace points may be recorded, each group of points representing an outline.
Step S202, adjusting the initial contour track point sequence according to a preset stroke width, and generating a contour track point sequence corresponding to the outermost contour;
specifically, the preset stroke width is the stroke width of the actually used pen, and according to the stroke of the actually used pen, if the total width of a plurality of pixels of the image corresponding to the stroke width is calculated to be K, the K is used as the width, the contour trace points are connected one by one, and a corresponding contour trace point sequence L1 is generated.
Step S203, subtracting the outermost layer outline from the target image to obtain a remaining part image, and calculating the area of the remaining part image;
step S204, judging whether the area of the residual partial image is smaller than a preset area threshold value or not; if not, the same processing from the step S201 to the step S203 is carried out on the residual partial image; if yes, the search is ended.
For example, from the original personSubtracting the contour track point sequence L1 obtained in the step S202 from the portrait image, and repeatedly decomposing the original portrait into a contour track point sequence (α) of an outermost contour α 1, a second outer contour α 2, a second outer contour … and an innermost contour α n by adopting the same processing in the steps S201 to S203 for the rest part of the image (α)1,α2…,αn) And completing the retrieval until the retrieval ending condition is triggered. The search ending condition is as follows: and calculating to obtain the area of the image of the residual part, and finishing the retrieval if the area of the image of the residual part is smaller than a preset area threshold.
Step S103: and carrying out data cleaning on the contour track point sequence according to a preset drawing precision range, and inputting the contour track point sequence subjected to data cleaning into a mechanical arm for drawing.
Specifically, step S103 may be specifically implemented as:
calculating the distance between the current track point and the next track point from the initial track point of each layer of outline; if the distance is smaller than a preset drawing precision range, filtering the next track point; if the distance is larger than the preset drawing precision range, searching from the next track point again until all track points on the current contour are traversed, and finishing primary filtering; and after the preliminary filtering, if the number of the residual track points in the current contour is 1, deleting the contour.
Specifically, a sequence of contour trace points (α)1,α2…,αn) When the mechanical arm is input, preprocessing such as data conversion is required, so that the distance between contour track points is smaller than the precision range of the mechanical arm, and the mechanical arm cannot be drawn correctly. Therefore, the sequence of contour trace points may be subjected to data cleaning or the like in advance. For example, starting from the starting point of each contour track, calculating the distance between the current track point a and the next track point a +1, if the distance is smaller than the precision range of the mechanical arm (preset drawing precision range), filtering the next point, and if the distance is larger than the precision range of the mechanical arm, starting to search from the point a +1 until all points on the contour are traversed; after the preliminary filtering, if only 1 contour point is left in the contour, the contour is deleted to prevent the breakageSpoiling the aesthetics of the final painting result.
Compared with the prior art, the method for controlling the robot to draw the image can generate the drawing track according to the input image and the actual effective drawing precision of the mechanical arm, can completely draw the input image, and optimizes the process of drawing the mechanical arm, so that various requirements of users are met.
In the above embodiment, a method for controlling a robot to draw an image is provided, and correspondingly, the present application also provides an apparatus for controlling a robot to draw an image. The device for controlling the robot to draw the image can implement the method for controlling the robot to draw the image, and the device for controlling the robot to draw the image can be implemented by software, hardware or a combination of software and hardware. For example, the apparatus for controlling a robot to draw an image may include integrated or separate functional modules or units to perform the corresponding steps of the above-described methods. Referring to fig. 3, a schematic diagram of an apparatus for controlling a robot to draw an image according to some embodiments of the present disclosure is shown. Since the apparatus embodiments are substantially similar to the method embodiments, they are described in a relatively simple manner, and reference may be made to some of the descriptions of the method embodiments for relevant points. The device embodiments described below are merely illustrative.
As shown in fig. 3, the apparatus 10 for controlling a robot to draw an image may include:
an obtaining module 101, configured to obtain a target image to be drawn;
the generating module 102 is configured to gradually decompose the target image into multiple layers of contours from outside to inside, and generate a contour track point sequence corresponding to each layer of contour;
and the data cleaning module 103 is used for performing data cleaning on the contour track point sequence according to a preset drawing precision range, and inputting the contour track point sequence subjected to data cleaning into the mechanical arm for drawing.
In some implementations of the embodiments of the present application, the generating module 102 is specifically configured to:
s1, retrieving the outermost layer contour of the target image, and recording the retrieved initial contour track point sequence;
s2, adjusting the initial contour track point sequence according to a preset stroke width, and generating a contour track point sequence corresponding to the outermost contour;
s3, subtracting the outermost layer outline from the target image to obtain a residual image;
s4, the same processing from S1 to S3 is carried out on the residual images until the condition of ending the retrieval is triggered; the search ending condition is as follows: and calculating to obtain the area of the image of the residual part, and finishing the retrieval if the area of the image of the residual part is smaller than a preset area threshold.
In some implementations of the embodiments of the present application, the data cleansing module 103 is specifically configured to:
calculating the distance between the current track point and the next track point from the initial track point of each layer of outline;
if the distance is smaller than a preset drawing precision range, filtering the next track point;
if the distance is larger than the preset drawing precision range, searching from the next track point again until all track points on the current contour are traversed, and finishing primary filtering;
and after the preliminary filtering, if the number of the residual track points in the current contour is 1, deleting the contour.
In some implementations of embodiments of the present application, the apparatus 10 further comprises:
and the preprocessing module is used for preprocessing the region image before the generation module gradually decomposes the target image into a plurality of layers of contours from outside to inside.
The apparatus 10 for controlling a robot to draw an image according to the embodiment of the present application has the same advantages as the method for controlling a robot to draw an image according to the previous embodiment of the present application.
The embodiment of the present application further provides a robot corresponding to the method for controlling the robot to draw an image provided in the foregoing embodiments, please refer to fig. 4, which shows a schematic diagram of a robot provided in some embodiments of the present application. As shown in fig. 4, the robot 20 includes: the system comprises a processor 200, a memory 201, a bus 202 and a communication interface 203, wherein the processor 200, the communication interface 203 and the memory 201 are connected through the bus 202; the memory 201 stores a computer program that can be executed on the processor 200, and the processor 200 executes the method for controlling the robot to draw the image provided by any one of the foregoing embodiments when executing the computer program.
The Memory 201 may include a high-speed Random Access Memory (RAM) and may further include a non-volatile Memory (non-volatile Memory), such as at least one disk Memory. The communication connection between the network element of the system and at least one other network element is realized through at least one communication interface 203 (which may be wired or wireless), and the internet, a wide area network, a local network, a metropolitan area network, and the like can be used.
Bus 202 can be an ISA bus, PCI bus, EISA bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. The memory 201 is used for storing a program, and the processor 200 executes the program after receiving an execution instruction, and the method for controlling the robot to draw an image disclosed in any embodiment of the present application may be applied to the processor 200, or implemented by the processor 200.
The processor 200 may be an integrated circuit chip having signal processing capabilities. In implementation, the steps of the above method may be performed by integrated logic circuits of hardware or instructions in the form of software in the processor 200. The Processor 200 may be a general-purpose Processor, and includes a Central Processing Unit (CPU), a Network Processor (NP), and the like; but may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components. The various methods, steps, and logic blocks disclosed in the embodiments of the present application may be implemented or performed. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module may be located in ram, flash memory, rom, prom, or eprom, registers, etc. storage media as is well known in the art. The storage medium is located in the memory 201, and the processor 200 reads the information in the memory 201 and completes the steps of the method in combination with the hardware thereof.
The robot provided by the embodiment of the application and the method for controlling the robot to draw the image provided by the embodiment of the application have the same beneficial effects as the method adopted, operated or realized by the robot.
Referring to fig. 5, a computer readable storage medium is shown as an optical disc 30, on which a computer program (i.e., a program product) is stored, and when the computer program is executed by a processor, the computer program executes the method for controlling a robot to draw an image according to any of the foregoing embodiments.
It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory, or other optical and magnetic storage media, which are not described in detail herein.
The computer-readable storage medium provided by the above-mentioned embodiment of the present application and the method for controlling the robot to draw the image provided by the embodiment of the present application have the same beneficial effects as the method adopted, run or implemented by the application program stored in the computer-readable storage medium.
It should be noted that the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; such modifications and substitutions do not depart from the spirit and scope of the present disclosure, and the present disclosure should be construed as being covered by the claims and the specification.