Image contour cutting method and device, equipment and storage medium
By processing images line by line by line and looking up and fitting, the problems of low image contour extraction efficiency and poor accuracy in the prior art are solved, and efficient and accurate contour cutting path acquisition is achieved, which is suitable for complex backgrounds and multi-object scenes.
Patent Information
- Application Number
- CN202311727584.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-14
- Publication Date
- 2025-06-17
AI Technical Summary
In the prior art, image contour extraction efficiency is low and the accuracy is poor, especially in complex backgrounds and multi-object scenes, and traditional algorithms occupy a large memory and are inefficient in large images or real-time applications.
By loading the pending image line by line and performing background tolerance processing and binarization processing, the preset contour point set is obtained by using the preset contour search algorithm, filtering and smoothing processing, and finally obtaining the contour cutting path through fitting.
It realizes efficient and accurate image contour cutting, less computing memory space, fast computing speed, strong anti-interference ability, and is suitable for high-precision, real-time and efficient cutting of object contours in applications such as digital cutting machines.
Smart Images

Figure CN120163841A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and in particular, to an image contour cutting method, apparatus, device, and storage medium. Background Art
[0002] In the application of high-precision cutting of products by a digital cutting machine, extracting the contour from an image and generating a contour cutting path is a key task. However, in practical applications, noise and interference in the image may lead to inaccurate contour extraction. When the image of the product is fused with a complex background, especially some images with complex shapes or textures, it will be difficult to accurately extract the contour; when there are multiple objects or multiple connected contours in the image, the contour extraction algorithm may require additional processing to ensure the correct identification and segmentation of each object. In addition, some traditional contour extraction algorithms may have a large memory footprint, low efficiency, and low real-time performance in large images or real-time applications, or the generated contour cutting path may not be smooth enough, resulting in a large error when the cutting machine performs the image cutting operation. Summary of the Invention
[0003] In view of this, embodiments of the present invention provide an image contour cutting method, apparatus, device, and storage medium to solve the problems of low efficiency and poor accuracy in image contour extraction in the prior art.
[0004] In a first aspect, an embodiment of the present invention provides an image contour cutting method, the method comprising:
[0005] Loading the image to be processed line by line and performing background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image;
[0006] Using a preset contour search algorithm to search for contours in the preset binary image to obtain a first set of image contour points;
[0007] Filtering or smoothing the first set of image contour points to obtain a second set of image contour points;
[0008] Fitting the second set of image contour points to obtain a contour cutting path.
[0009] Preferably, after fitting the second set of image contour points to obtain a contour cutting path, it further includes:
[0010] Storing the contour cutting path using a linked list data structure.
[0011] Preferably, the loading the image to be processed line by line and performing background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image includes:
[0012] Load the image to be processed line by line;
[0013] For each line of the image loaded, perform tolerance background color separation processing on the line of the image and adjust the number of bits of the obtained binary image to eight bits;
[0014] Complete the tolerance background color separation processing and bit number adjustment for all lines of the image to be processed to obtain the preset binary image.
[0015] Preferably, the preset binary image is subjected to contour search using a preset contour search algorithm, and obtaining the first image contour point set includes:
[0016] Use the findContours contour search algorithm in Opencv to search for each contour in the preset binary image, where each contour is represented by a set containing a series of nodes;
[0017] Obtain the set of nodes corresponding to all contours in the preset binary image, which is the first image contour point set.
[0018] Preferably, the filtering or smoothing process of the first image contour point set to obtain the second image contour point set includes:
[0019] Generate set X and set Y respectively according to the x coordinate values and y coordinate values of all nodes in the first image contour point set;
[0020] Perform Gaussian filtering on set X and set Y respectively, and merge set X and set Y after Gaussian filtering processing to obtain a sub-pixel smooth contour point set, which is the second image point set.
[0021] Preferably, the fitting of the second image contour point set to obtain the contour cutting path includes:
[0022] Use the least squares method to perform Bezier curve fitting on the second image contour point set;
[0023] Obtain the nodes with fitting error greater than or equal to the preset precision threshold, denoted as segmented nodes, perform curve segmentation on the segmented nodes and then perform Bezier curve fitting again until its fitting error is less than the preset precision threshold;
[0024] Obtain the multi-segment Bezier curve path obtained after Bezier curve fitting, which is the contour cutting path.
[0025] Preferably, the filtering or smoothing process of the first image contour point set to obtain the second image contour point set includes:
[0026] Obtain the area of each contour in the first image contour point set;
[0027] Filter out the contours with an area less than or equal to the preset contour threshold, and retain the remaining contours. The set of contour points corresponding to the remaining contours is the second image contour point set.
[0028] Preferably, the obtaining of the contour cutting path by fitting the second image contour point set includes:
[0029] Obtain the number of nodes in the second image contour point set;
[0030] When the number of nodes is less than or equal to a preset value, obtain the contour cutting path according to the second image contour point set;
[0031] When the number of nodes is greater than the preset value, use the approxPolyDP algorithm in Opencv to perform node polyline fitting and obtain the contour cutting path.
[0032] In a second aspect, an embodiment of the present invention provides an image contour cutting device, which includes:
[0033] A preprocessing module for loading the image to be processed line by line and performing background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image;
[0034] A contour searching module for searching for contours in the preset binary image by using a preset contour searching algorithm to obtain a first image contour point set;
[0035] A denoising module for filtering or smoothing the first image contour point set to obtain a second image contour point set;
[0036] A path obtaining module for fitting the second image contour point set to obtain a contour cutting path.
[0037] In a third aspect, an embodiment of the present invention provides an image contour cutting device, including: at least one processor, at least one memory, and computer program instructions stored in the memory, which implement the method of the first aspect in the above-mentioned implementation manner when the computer program instructions are executed by the processor.
[0038] In a fourth aspect, an embodiment of the present invention provides a storage medium, on which computer program instructions are stored, which implement the method of the first aspect in the above-mentioned implementation manner when the computer program instructions are executed by the processor.
[0039] In summary, the beneficial effects of the present invention are as follows:
[0040] The image contour cutting method, device, equipment and storage medium provided by the embodiments of the present invention load the image to be processed line by line and perform background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image; use a preset contour search algorithm to search for contours in the preset binarized image to obtain a first set of image contour points; perform filtering or smoothing processing on the first set of image contour points to obtain a second set of image contour points; and perform fitting on the second set of image contour points to obtain a contour cutting path. The image contour cutting method of the present invention has less memory space occupation, fast calculation speed and strong anti-interference ability. By adjusting the parameters in the fitting algorithm, the scale of path nodes can also be adjusted, which is beneficial to realizing high-precision, real-time and efficient cutting of object contours in applications such as digital cutting machines. Description of the Drawings
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following will briefly introduce the drawings required to be used in the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings, and all of them are within the protection scope of the present invention.
[0042] Figure 1 It is a schematic flowchart of the image contour cutting method in the embodiments of the present invention.
[0043] Figure 2 It is a schematic flowchart of performing background tolerance processing and binarization processing on the image to be processed in the embodiments of the present invention.
[0044] Figure 3 It is a schematic flowchart of obtaining the first set of image contour points in the embodiments of the present invention.
[0045] Figure 4 It is a schematic flowchart of performing smoothing processing on the first set of image contour points in the embodiments of the present invention.
[0046] Figure 5 It is a schematic flowchart of obtaining a contour cutting path by fitting with a Bessel curve in the embodiments of the present invention.
[0047] Figure 6 It is a schematic flowchart of performing filtering processing on the first set of image contour points in the embodiments of the present invention.
[0048] Figure 7 It is a schematic flowchart of obtaining a contour cutting path by fitting with a polyline in the embodiments of the present invention.
[0049] Figure 8 It is a schematic structural diagram of the image contour cutting device in the embodiments of the present invention.
[0050] Figure 9It is a schematic structural diagram of the image contour cutting device according to an embodiment of the present invention. Detailed implementation manners
[0051] The features of various aspects of the present invention and exemplary embodiments will be described in detail below. In order to make the objectives, technical solutions and advantages of the present invention clearer and more understandable, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only configured to explain the present invention and are not configured to limit the present invention. For those skilled in the art, the present invention can be implemented without some of these specific details. The following description of the embodiments is only intended to provide a better understanding of the present invention by showing examples of the present invention.
[0052] It should be noted that in this article, relational terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not expressly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, the elements defined by the statement "including..." do not exclude the existence of additional identical elements in the process, method, article or device including the said elements.
[0053] Embodiment 1
[0054] An embodiment of the present invention provides an image contour cutting method, which is used for digital image cutting applications and can also be applied to various application scenarios that require background color separation and extraction of smooth contour paths.
[0055] Please refer to Figure 1 , the image contour cutting method specifically includes the following steps:
[0056] S1: Load the image to be processed line by line and perform background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image;
[0057] S2: Use a preset contour search algorithm to search for contours in the preset binary image to obtain a first set of image contour points;
[0058] S3: Filter or smooth the first set of image contour points to obtain a second set of image contour points;
[0059] S4: Fit the second set of image contour points to obtain a contour cutting path.
[0060] Specifically, the image to be processed is an image for which contour extraction is required. The image to be processed is loaded using an image processing library (such as OpenCV). After loading, background tolerance processing is performed according to a predefined background color and tolerance value, and the image is converted into a binary image. The purpose of this step is to separate the background in the image, making it easier to extract the contours of the target object. A preset contour search algorithm (such as the findContours function in OpenCV) is used to search for contours in the binary image. This algorithm returns a list containing all the contours. Each contour is represented by a set containing a series of nodes, which describes the boundary of the object in the image. Denote the set of these nodes as the first set of image contour points. The obtained first set of image contour points is filtered and smoothed. For example, small-area contours can be removed or noise can be reduced through smoothing to ensure more accurate contour fitting in subsequent steps, obtaining the second set of image contour points. Then, a fitting algorithm (such as approxPolyDP in OpenCV) is used to fit the second set of image contour points to obtain the final contour cutting path. The contour cutting path is a set of a series of nodes that describes the shape of the contour. Preferably, the obtained contour cutting path is stored in a linked list data structure. The linked list can store the nodes in the path in order, forming an ordered data structure, which is convenient for subsequent processing and applications. This image contour cutting method extracts the image contour from the image to be processed through the above steps and represents it as an ordered contour cutting path. This path can be used in applications such as digital cutting machines, thereby achieving high-precision cutting of objects.
[0061] Preferably, please refer to Figure 2 , the step of loading the image to be processed line by line and performing background tolerance processing and binary processing on the image to be processed line by line to obtain a preset binary image includes:
[0062] S21: Load the image to be processed line by line;
[0063] S22: For each line of the image loaded, perform tolerance background color separation processing on this line of the image and adjust the number of bits of the obtained binary image to eight bits;
[0064] S23: After completing the tolerance background color separation processing and bit number adjustment for all lines of the image to be processed, obtain the preset binary image.
[0065] The background tolerance processing here separates the tolerance background color of the image to be processed, aiming to separate the foreground objects from the background in the image to be processed. Tolerance refers to the degree of tolerance for color differences. By selecting a target color (usually the background color), and then according to a certain tolerance range, pixels similar to the target color are regarded as the background, while pixels with obvious differences from the target color are regarded as the foreground, so as to separate the background and the foreground. By using an image processing library, the image to be processed is loaded line by line. Then, for each row of pixels, calculate the difference between its color and the preset background color. If the color difference is within the preset tolerance range, set the pixel to white (255), otherwise set it to black (0). This process will be carried out pixel by pixel line by line, so as to achieve the tolerance background color separation processing. Repeat this process until the tolerance background color separation processing is carried out for all rows of the entire image. Since the image obtained by the tolerance background color separation processing is a binary image, adjust its depth (number of bits) to an 8-bit grayscale image, that is, the preset binary image.
[0066] Preferably, please refer to Figure 3 , the obtaining of the first image contour point set by performing contour finding on the preset binary image using a preset contour finding algorithm includes:
[0067] S31: Use the findContours contour finding algorithm in Opencv to find each contour in the preset binary image, where each contour is represented by a set containing a series of nodes;
[0068] S32: Obtain the set of nodes corresponding to all contours in the preset binary image, which is the first image contour point set.
[0069] Specifically, call the findContours function provided by OpenCV to perform contour finding on the preset binary image. This function returns a list of all contours in the image. Traverse the contour list returned by the findContours function. Each contour is an object (set) containing a series of nodes, and these nodes describe the shape of the contour. Merge the objects of the corresponding nodes in all contours into a large set, which is the contour point set of the first image.
[0070] In one embodiment, after obtaining the first image contour point set, use Gaussian filtering and Bezier curve fitting methods to obtain a smooth image contour path. Preferably, please refer to Figure 4 , the filtering or smoothing processing of the first image contour point set to obtain the second image contour point set includes:
[0071] S41: Generate set X and set Y respectively according to the x coordinate values and y coordinate values of all nodes in the first image contour point set;
[0072] S42: Perform Gaussian filtering on the set X and the set Y respectively, and merge the set X and the set Y after Gaussian filtering processing to obtain a sub-pixel smooth contour point set, which is the second image point set.
[0073] Specifically, traverse all the nodes in the first image contour point set, form the set X with their x coordinate values, and form the set Y with their y coordinate values. Use a Gaussian filter to perform smoothing processing on the set X and the set Y respectively. Gaussian filtering can reduce noise and make the point set smoother. Here, Gaussian filtering can be implemented through the GaussianBlur function in OpenCV. Merge the set X and the set Y after Gaussian filtering processing to obtain a sub-pixel smooth contour point set, thereby obtaining a smoother and less noisy contour point set, denoted as the second image contour point set. Such a processing process helps to improve the quality of the contour and makes subsequent operations more accurate. It is worth pointing out that the parameters of Gaussian filtering can be set according to the actual situation to meet specific requirements and scenarios.
[0074] After performing high-pass filtering on the second image contour point set, preferably, please refer to Figure 5 , the obtaining of the contour cutting path by fitting the second image contour point set includes:
[0075] S51: Use the least squares method to perform Bezier curve fitting on the second image contour point set;
[0076] S52: Obtain the nodes whose fitting error is greater than or equal to the preset precision threshold, denoted as segmentation nodes, perform curve segmentation on the segmentation nodes and then perform Bezier curve fitting again until its fitting error is less than the preset precision threshold;
[0077] S53: Obtain the multi-segment Bezier curve paths obtained after Bezier curve fitting, which are the contour cutting paths.
[0078] Specifically, the least squares method is used to fit the B-spline curve to the second image contour point set after high-pass filtering. The least squares method is a mathematical optimization method that adjusts the parameters of the B-spline curve to minimize the fitting error between the curve and the point set. Calculate the error between the fitted curve and the original contour point set, and mark the nodes whose errors are greater than or equal to the preset precision threshold. Denote the marked nodes as segmentation nodes, cut the contour in the segmentation nodes into multiple segments, and perform B-spline curve fitting on each segment again. Repeat the steps of calculating the error and curve fitting until the fitting error of all segments is less than the preset precision threshold, and the final B-spline curve fitting result is obtained. This result is a path composed of multiple B-spline curves, which is the contour cutting path. In practical applications, the node scale of the B-spline curve path can be controlled by adjusting the preset precision threshold. The smaller the preset precision threshold, the more small segments of the curve will be generated, and users can make fine adjustments according to their needs.
[0079] In the embodiment of the present invention, the obtained contour cutting path is stored using a linked list data structure, which facilitates subsequent large-scale addition, deletion, and partial modification operations on the contour cutting path (point set) when needed. After obtaining the image contour cutting path, this path can be used in applications such as digital cutting machines to achieve high-precision cutting of objects. In the embodiment of the present invention, key points on the cutting contour are adaptively determined according to the gray gradient and curvature information of the image, and these key points are fitted using the B-spline curve algorithm to form a smooth cutting result that closely adheres to the edge of the object, thus being able to adapt to different types and complexities of images.
[0080] In another embodiment, after obtaining the first image contour point set, a polyline fitting method is used to generate a polyline-shaped contour cutting path. Preferably, please refer to Figure 6 , the filtering or smoothing process of the first image contour point set to obtain the second image contour point set includes:
[0081] S61: Obtain the area of each contour in the first image contour point set;
[0082] S62: Filter the contours with an area less than or equal to the preset contour threshold, and retain the remaining contours. The contour point set corresponding to the remaining contours is the second image contour point set.
[0083] Specifically, after obtaining the contour point set of the first image, each contour is traversed and its area is calculated. Exemplarily, for each contour, the contourArea function of OpenCV is used to calculate its area. For each contour, it is checked whether its area is less than or equal to a preset contour threshold. If so, the contour is removed from the first image contour point set, and the contour point set corresponding to the remaining contours is denoted as the second image contour point set. By screening the areas, small contours can be removed to prevent small contours from interfering with the cutting. In one embodiment, square centimeters are used as the unit for area calculation, so as to facilitate calculating the area size and filtering small contours during actual cutting applications.
[0084] Preferably, refer to Figure 7 , the obtaining the contour cutting path by fitting the second image contour point set includes:
[0085] S71: Obtain the number of nodes in the second image contour point set;
[0086] S72: When the number of nodes is less than or equal to a preset value, obtain the contour cutting path according to the second image contour point set;
[0087] S73: When the number of nodes is greater than the preset value, use the approxPolyDP algorithm in Opencv to perform node polyline fitting and obtain the contour cutting path.
[0088] Specifically, first, the number of contour nodes is judged. If the number of contour nodes is less than or equal to the preset value, it means the contour is relatively simple and the original data can be directly used without further fitting. If the number of contour nodes is greater than 15, it means the contour is relatively complex, and a fitting algorithm is used to reduce the number of nodes to make it more simplified. The preset value here can be adjusted according to the actual situation. Preferably, the preset value is 15. In this sub - embodiment, by using the approxPolyDP algorithm of OpenCV for polyline fitting, the fitting accuracy can be controlled by adjusting the accuracy parameter of approxPolyDP. The smaller the accuracy parameter, the closer the fitting result is to the original curve and the more nodes there are; on the contrary, the larger the accuracy parameter, the more simplified the fitting result is and the number of nodes decreases. Further, after the fitting is completed, if it is still desired to further adjust the node scale, some additional processing can be performed on the fitted nodes, such as adding or deleting nodes, to meet specific requirements.
[0089] Similarly, finally, a linked list data structure is adopted to store the obtained contour cutting path, which facilitates subsequent large-scale addition, deletion, and partial modification operations on the contour cutting point set. After obtaining the image contour cutting path, this path can be used in applications such as digital cutting machines to achieve high-precision cutting of objects. In the embodiment of the present invention, key points on the cutting contour are adaptively determined based on the gray gradient and curvature information of the image, and these key points are connected in the form of a broken line to form a relatively smooth cutting result that closely adheres to the object edge, thereby being able to adapt to different types and complexities of images.
[0090] In summary, the image contour cutting method provided by the embodiment of the present invention loads the image to be processed line by line and performs background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image; uses a preset contour search algorithm to search for contours in the preset binary image to obtain a first image contour point set; filters or smooths the first image contour point set to obtain a second image contour point set; and fits the second image contour point set to obtain a contour cutting path. The image contour cutting method of the present invention has less memory space occupation, fast calculation speed, and strong anti-interference ability. By adjusting the parameters in the fitting algorithm, the scale of path nodes can also be adjusted, which is beneficial to achieving high-precision, real-time, and efficient cutting of object contours in applications such as digital cutting machines.
[0091] Embodiment 2
[0092] Please refer to Figure 8 , the embodiment of the present invention provides an image contour cutting device, and the device includes:
[0093] A preprocessing module, configured to load the image to be processed line by line and perform background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binary image;
[0094] A contour search module, configured to use a preset contour search algorithm to search for contours in the preset binary image to obtain a first image contour point set;
[0095] A denoising module, configured to filter or smooth the first image contour point set to obtain a second image contour point set;
[0096] A path acquisition module, configured to fit the second image contour point set to obtain a contour cutting path.
[0097] In summary, the image contour cutting device provided by the embodiments of the present invention loads the image to be processed line by line and performs background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image; uses a preset contour search algorithm to search for contours in the preset binarized image to obtain a first set of image contour points; filters or smooths the first set of image contour points to obtain a second set of image contour points; and fits the second set of image contour points to obtain a contour cutting path. The image contour cutting method of the present invention has less memory space occupation, fast calculation speed, and strong anti-interference ability. By adjusting the parameters in the fitting algorithm, the scale of path nodes can also be adjusted. According to this contour cutting path, it is beneficial to achieve high-precision, real-time, and efficient cutting of the object contour by applications such as digital cutting machines.
[0098] Embodiment 3
[0099] In addition, the image contour cutting method of the embodiments of the present invention can be implemented by an image contour cutting device. Figure 9 The hardware structure diagram of the image contour cutting device provided by the embodiments of the present invention is shown.
[0100] The image contour cutting device may include a processor 301 and a memory 302 storing computer program instructions.
[0101] Specifically, the processor 301 may include a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention.
[0102] The memory 302 may include a mass storage for data or instructions. By way of example and not limitation, the memory 302 may include a hard disk drive (HDD), a floppy disk drive, a flash memory, an optical disk, a magneto-optical disk, a tape, or a universal serial bus (USB) drive or a combination of two or more of these. In a suitable case, the memory 302 may include a removable or non-removable (or fixed) medium. In a suitable case, the memory 302 may be internal or external to the data processing device. In a specific embodiment, the memory 302 is a non-volatile solid state memory. In a specific embodiment, the memory 302 includes a read only memory (ROM). In a suitable case, the ROM may be a mask programmed ROM, a programmable ROM (PROM), an erasable PROM (EPROM), an electrically erasable PROM (EEPROM), an electrically rewritable ROM (EAROM), or a flash memory or a combination of two or more of these.
[0103] The processor 301 reads and executes the computer program instructions stored in the memory 302 to implement any one of the image contour cutting methods in the above embodiments.
[0104] In one example, the image contour cutting device may further include a communication interface 303 and a bus 310. Among them, as Figure 9 shown, the processor 301, the memory 302, and the communication interface 303 are connected through the bus 310 to complete communication with each other.
[0105] The communication interface 303 is mainly used to implement communication between various modules, devices, units, and / or devices in the embodiments of the present invention.
[0106] The bus 310 includes hardware, software, or both, and couples the components of the image contour cutting device to each other. By way of example and not limitation, the bus 310 may include an Accelerated Graphics Port (AGP) or other graphics bus, an Enhanced Industry Standard Architecture (EISA) bus, a Front Side Bus (FSB), a HyperTransport (HT) interconnect, an Industry Standard Architecture (ISA) bus, an InfiniBand interconnect, a Low Pin Count (LPC) bus, a memory bus, a MicroChannel Architecture (MCA) bus, a Peripheral Component Interconnect (PCI) bus, a PCI-Express (PCI-X) bus, a Serial Advanced Technology Attachment (SATA) bus, a Video Electronics Standards Association Local (VLB) bus, or other suitable buses or a combination of two or more of these. In a suitable case, the bus 310 may include one or more buses. Although the embodiments of the present invention describe and illustrate specific buses, the present invention contemplates any suitable bus or interconnect.
[0107] Embodiment 4
[0108] In addition, in combination with the image contour cutting method in the above embodiments, the embodiments of the present invention may provide a computer-readable storage medium to implement. Computer program instructions are stored on the computer-readable storage medium; when the computer program instructions are executed by the processor 301, any one of the image contour cutting methods in the above embodiments is implemented.
[0109] In summary, the image contour cutting method, device, equipment and storage medium provided by the embodiments of the present invention load the image to be processed line by line and perform background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image; use a preset contour search algorithm to search for contours in the preset binarized image to obtain a first set of image contour points; perform filtering or smoothing processing on the first set of image contour points to obtain a second set of image contour points; and perform fitting on the second set of image contour points to obtain a contour cutting path. The image contour cutting method of the present invention has the advantages of less memory space occupation, fast calculation speed, strong anti-interference ability, and adjustable path node scale by adjusting the parameters in the fitting algorithm. According to the contour cutting path, it is beneficial to realize high-precision, real-time and efficient cutting of the object contour by applications such as digital cutting machines.
[0110] It should be clear that the present invention is not limited to the specific configurations and processes described above and shown in the figures. For the sake of brevity, detailed descriptions of known methods are omitted here. In the above embodiments, several specific steps are described and shown as examples. However, the method process of the present invention is not limited to the specific steps described and shown. Those skilled in the art can make various changes, modifications and additions, or change the order between steps after understanding the spirit of the present invention.
[0111] It should also be noted that the functional blocks shown in the above structural block diagrams can be implemented as hardware, software, firmware or a combination thereof. When implemented in hardware, it can be, for example, an electronic circuit, an application specific integrated circuit (ASIC), appropriate firmware, a plug-in, a functional card, and so on. When implemented in software, the elements of the present invention are programs or code segments used to perform the required tasks. The program or code segment can be stored in a machine-readable medium or transmitted via a data signal carried in a carrier wave on a transmission medium or a communication link. "Machine-readable medium" can include any medium capable of storing or transmitting information. Examples of machine-readable media include electronic circuits, semiconductor memory devices, ROM, flash memory, erasable ROM (EROM), floppy disks, CD-ROMs, optical disks, hard disks, fiber optic media, radio frequency (RF) links, and so on. The code segment can be downloaded via a computer network such as the Internet, an intranet, and so on.
[0112] It should also be noted that the exemplary embodiments mentioned in the present invention describe some methods or systems based on a series of steps or devices. However, the present invention is not limited to the order of the above steps, that is, the steps can be executed in the order mentioned in the embodiments, or different from the order in the embodiments, or several steps can be executed simultaneously.
[0113] As described above, this is only the specific implementation manner of the present invention. Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the systems, modules, and units described above can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein. It should be understood that the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various equivalent modifications or substitutions, and these modifications or substitutions should all be covered within the protection scope of the present invention.
Claims
1. An image contour cutting method, characterized in that, The method includes: Loading the image to be processed line by line and performing background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image; Using a preset contour search algorithm to search for contours in the preset binarized image to obtain a first set of image contour points; Filtering or smoothing the first set of image contour points to obtain a second set of image contour points; Fitting the second set of image contour points to obtain a contour cutting path.
2. The image contour cutting method according to claim 1, characterized in that, After fitting the second set of image contour points to obtain a contour cutting path, it further includes: Storing the contour cutting path using a linked list data structure.
3. The image contour cutting method according to claim 1, characterized in that, The step of loading the image to be processed line by line and performing background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image includes: Loading the image to be processed line by line; For each line of the image loaded, performing tolerance background color separation processing on the line of the image and adjusting the number of bits of the obtained binarized image to eight bits; Completing the tolerance background color separation processing and bit number adjustment for all lines of the image to be processed to obtain the preset binarized image.
4. The image contour cutting method according to claim 3, characterized in that, The step of using a preset contour search algorithm to search for contours in the preset binarized image to obtain a first set of image contour points includes: Using the findContours contour search algorithm in Opencv to search for each contour in the preset binarized image, where each contour is represented by a set containing a series of nodes; Obtaining the set of nodes corresponding to all contours in the preset binarized image, which is the first set of image contour points.
5. The image contour cutting method according to any one of claims 1-4, characterized in that, The step of filtering or smoothing the first set of image contour points to obtain a second set of image contour points includes: Generating set X and set Y respectively according to the x coordinate values and y coordinate values of all nodes in the first set of image contour points; Performing Gaussian filtering on set X and set Y respectively, and merging set X and set Y after Gaussian filtering processing to obtain a sub-pixel smooth contour point set, which is the second set of image points.
6. The image contour cutting method according to any one of claim 5, characterized in that, The step of fitting the second set of image contour points to obtain a contour cutting path includes: Performing B-spline curve fitting on the second set of image contour points using the least squares method; Obtaining the nodes with fitting error greater than or equal to a preset precision threshold, denoted as segmented nodes, performing curve segmentation on the segmented nodes and then performing B-spline curve fitting again until the fitting error is less than the preset precision threshold; Obtaining the multi-segment B-spline curve path obtained after B-spline curve fitting, which is the contour cutting path.
7. The image contour cutting method according to any one of claims 1-4, characterized in that, The step of filtering or smoothing the first set of image contour points to obtain a second set of image contour points includes: Obtaining the area of each contour in the first set of image contour points; Filtering the contours with area less than or equal to a preset contour threshold, and retaining the remaining contours, and the set of contour points corresponding to the remaining contours is the second set of image contour points.
8. The image contour cutting method according to claim 7, characterized in that, The step of fitting the second set of image contour points to obtain a contour cutting path includes: Obtaining the number of nodes in the second set of image contour points; When the number of nodes is less than or equal to a preset value, the contour cutting path is obtained according to the second set of image contour points; When the number of the nodes is greater than a preset value, the approxPolyDP algorithm in Opencv is used to fit the node broken line and obtain the contour cutting path.
9. An image contour cutting device, characterized in that, The device includes: A preprocessing module, configured to load the image to be processed line by line and perform background tolerance processing and binarization processing on the image to be processed line by line to obtain a preset binarized image; A contour searching module, configured to search for contours of the preset binarized image by using a preset contour searching algorithm to obtain a first set of image contour points; A denoising module, configured to perform filtering or smoothing processing on the first set of image contour points to obtain a second set of image contour points; A path obtaining module, configured to fit the second set of image contour points to obtain a contour cutting path.
10. An image contour cutting device, characterized in that, Including: At least one processor, at least one memory, and computer program instructions stored in the memory, which implement the method according to any one of claims 1-7 when the computer program instructions are executed by the processor.