Printing method of thermal printer, thermal printer and storage medium
By binarizing the image and connecting domain analysis of the printed content of the thermal printer, and judging and adjusting the printed font size, the problem of unreadable content caused by improper font size when printing is solved, and the printing success rate and user experience are improved .
Patent Information
- Application Number
- CN202310142936.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-21
- Publication Date
- 2025-02-14
- Estimated Expiration
- 2043-02-21
AI Technical Summary
Due to improper font size scaling when printing, the printed content text is too small or too large and cannot be read. Users need to try and error on their own, resulting in waste of consumables and waste of operating time.
By binarizing the image of the printed content, extracting the external rectangle of the connecting domain, determining whether the printed font size meets the printer's requirements. If it does not meet, printing output will not be allowed, and the font size problem will be solved by prompting the user or automatically adjusting.
Improves the printing success rate, reduces user trial and error costs and waste of consumables, and ensures that high-quality, readable text content is printed.
Smart Images

Figure CN116061590B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of thermal printing, and in particular to a printing method of a thermal printer, a thermal printer and a storage medium. Background Art
[0002] Thermal printing technology is now being used more and more widely in all industries and fields, such as cashier, catering, bank, express delivery, etc., to print various documents. In recent years, the application scenarios of thermal printing technology have gradually expanded from commercial applications to consumer products, such as student error printers, children's cameras and other household consumer products, and the scale of the household market has gradually increased.
[0003] A thermal printer is a device that uses the heating element of the print head to contact the thermal printing paper to make it develop color and print the corresponding pattern. Thermal printers can support different print font sizes due to the differences in different sizes and models and different DPI print heads. Due to the limitations of thermal printing characteristics, the printed content generally needs to be scaled to the size width supported by the printer, and then binarized before printing. When the scaling ratio is too large, the printed content may be too small and unreadable, wasting the user's consumables.
[0004] Currently, it is common for users to make their own judgment based on the print results after printing. If the print effect is too poor, they can re-edit the print content and print again. In the current solution, users need to make their own trial and error, and the cost of trial and error includes not only the operation time, but also a considerable waste of printing consumables.
[0005] In view of this, the present invention patent is proposed. Summary of the invention
[0006] The present invention proposes a printing method for a thermal printer, which intervenes in the judgment when processing the printed content, extracts the text of the printed content, judges the font size, and obtains the judgment result of the print quality, and then makes corresponding processing on the printed content to improve the printing success rate; it can reduce the trial and error cost of the user, reduce the waste of consumables, and print out high-quality readable text content. Specifically, the following technical solutions are adopted:
[0007] A printing method for a thermal printer, comprising:
[0008] Performing image binarization processing on the printed content to obtain a printed binary image;
[0009] Extract the connected domains of the printed binary image and obtain the circumscribed rectangles of each connected domain;
[0010] Determine the font size of the printed text according to the height of the circumscribed rectangle of each connected domain;
[0011] It is determined whether the print font size meets the font size requirement of the thermal printer. If the determination result is yes, the print font size is printed out. If the determination result is no, the print out is not allowed.
[0012] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, determining the print font size of the printed text according to the height of the circumscribed rectangle of each connected domain includes:
[0013] Count the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram;
[0014] The print font size range is determined according to the rectangular height histogram, and the print font size of the printed text is obtained by taking an average value of the font sizes within the print font size range.
[0015] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, the counting of the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram comprises:
[0016] The connected domains are merged according to the rectangle intersection rule to obtain a merged connected domain, and a new merged connected domain circumscribed rectangle is obtained based on the merged connected domain;
[0017] The heights of the circumscribed rectangles of each merged connected domain are counted to obtain a rectangle height histogram.
[0018] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, the rectangle intersection rule includes:
[0019] Sort the connected domains according to the heights of their circumscribed rectangles;
[0020] When the height difference between two adjacent connected domains is within the preset range threshold, the connected domains are merged, otherwise, they are not merged.
[0021] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, in the process of merging connected domains according to the rectangular intersection rule to obtain a merged connected domain, if the height of the merged connected domain is greater than a preset maximum threshold or less than a preset minimum threshold, the merged connected domain is discarded.
[0022] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, determining the printing font size range according to the rectangular height histogram, and taking the average value of the printing font size range to obtain the print output font size includes:
[0023] A rectangular height distribution curve with peaks and valleys is obtained based on the rectangular height histogram;
[0024] According to the peak and valley characteristics, a cutting process is performed on the rectangular height distribution curve to obtain at least one peak curve segment;
[0025] The corresponding print font size range is determined according to the rectangular height distribution range of each peak curve segment, and the final print font size range is determined according to the proportion of each print font size range.
[0026] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, the corresponding printing font size range is determined according to the rectangular height distribution range of each peak curve segment, and the final printing font size range is determined according to the proportion of each printing font size range, including:
[0027] Determine whether the proportion of the minimum print font size range exceeds a preset threshold value of the first range;
[0028] If the judgment result is yes, the minimum print font size range is determined as the final print font size range; if the judgment result is no, it is determined whether the proportion of the next print font size range exceeds the second range preset threshold in the order of the print font size range from small to large, and the first range preset threshold and the second range preset threshold are the same or different;
[0029] The print font size ranges are judged in order from small to large whether they exceed the preset threshold of the corresponding range. Until the judgment result is yes, the print font size range corresponding to the current judgment result is output as the final print font size range. If the judgment results of all print font size ranges are no, the minimum print font size range is determined as the final print font size range.
[0030] As an optional embodiment of the present invention, in the printing method of the thermal printer of the present invention, it is determined whether the determined font size range meets the font size requirement of the thermal printer, and if the determination result is no, it also includes:
[0031] Determining a print content input source according to the print content;
[0032] If the print content input source is a screenshot of text content edited by a text editor, prompt the user to modify the font size;
[0033] If the input source of the print content is a photograph, the user is prompted to crop the picture.
[0034] The present invention also provides a thermal printer, which executes the printing method of the thermal printer.
[0035] The present invention also provides a computer-readable storage medium storing a computer-executable program, wherein when the computer-executable program is executed, the printing method of the thermal printer is implemented.
[0036] Compared with the prior art, the present invention has the following beneficial effects:
[0037] The printing method of the thermal printer of the present invention determines the print font size of the printed text by extracting the width and height of the connected domain of the print content image; presets the minimum limit print font size according to the paper width and print head DPI of different printers, and judges whether the current text image is suitable for printing. If it is not suitable for printing, the user is prompted to operate, or the image is operated in the form of automatic adjustment, thereby achieving the purpose.
[0038] Therefore, the printing method of the thermal printer proposed in the present invention intervenes in the judgment when processing the printed content. By extracting the text of the printed content and judging the print font size, after obtaining the judgment result of the print quality, the printed content is processed accordingly to improve the printing success rate. It can reduce the user's trial and error cost, reduce the waste of consumables, and print high-quality readable text content. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A flow chart of a printing method of a thermal printer according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] To make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be described clearly and completely in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of them.
[0041] Therefore, the following detailed description of the embodiments of the present invention is not intended to limit the scope of the invention claimed for protection, but merely represents some embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0042] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features and technical solutions in the embodiments may be combined with each other.
[0043] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0044] In the description of the present invention, it should be noted that the orientation or positional relationship indicated by the terms "upper", "lower", etc. is based on the orientation or positional relationship shown in the drawings, or the orientation or positional relationship in which the invention product is usually placed when in use, or the orientation or positional relationship commonly understood by those skilled in the art. Such terms are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.
[0045] See also Figure 1 As shown, the printing method of the thermal printer of this embodiment includes:
[0046] Performing image binarization processing on the printed content to obtain a printed binary image;
[0047] Extract the connected domains of the printed binary image and obtain the circumscribed rectangles of each connected domain;
[0048] Determine the font size of the printed text according to the height of the circumscribed rectangle of each connected domain;
[0049] It is determined whether the print font size meets the font size requirement of the thermal printer. If the determination result is yes, the print font size is printed out. If the determination result is no, the print out is not allowed.
[0050] The printing method of the thermal printer of the present embodiment determines the print font size of the printed text by extracting the width and height of the connected domain from the print content image; presets the minimum limit print font size according to the paper width and print head DPI of different printers, and determines whether the current text image is suitable for printing. If it is not suitable for printing, the user is prompted to operate, or the image is operated in the form of automatic adjustment, thereby achieving the purpose.
[0051] Therefore, the printing method of the thermal printer proposed in this embodiment intervenes in the judgment when processing the printed content. By extracting the text of the printed content and judging the print font size, after obtaining the judgment result of the print quality, the printed content is processed accordingly to improve the printing success rate. It can reduce the user's trial and error costs, reduce the waste of consumables, and print high-quality readable text content.
[0052] As an optional implementation of this embodiment, in the printing method of the thermal printer of this embodiment, determining the font size range of the printed text according to the height of the circumscribed rectangle of each connected domain includes:
[0053] Count the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram;
[0054] The print font size range is determined according to the rectangular height histogram, and the print font size of the printed text is obtained by taking an average value of the font sizes within the print font size range.
[0055] The connected area in the printed image content of this embodiment generally refers to the image area composed of foreground pixels with the same pixel value and adjacent positions in the image. Connected area analysis refers to finding and marking each connected area in the image. The height of the bounding rectangle of the connected domain of this embodiment represents the height of the printed text. The bounding rectangles of each connected domain are statistically analyzed to obtain a rectangle height histogram. According to the rectangle height histogram, multiple print font size ranges contained in the print content image are obtained. When printing, it is necessary to consider the printing effects of various font sizes. Therefore, the final print font size range of the print output is determined according to each print font size range. The average value of the font size within the final print font size range is taken to obtain the print font size of the printed text. In this way, the print font size of the printed text finally determined can meet the printing effect.
[0056] Furthermore, since a large number of connected domains may be identified in the printed content image, in order to improve the efficiency of determining the font size, in the printing method of the thermal printer of this embodiment, the counting of the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram includes:
[0057] The connected domains are merged according to the rectangle intersection rule to obtain a merged connected domain, and a new merged connected domain circumscribed rectangle is obtained based on the merged connected domain;
[0058] The heights of the circumscribed rectangles of each merged connected domain are counted to obtain a rectangle height histogram.
[0059] As an optional implementation of this embodiment, in the printing method of the thermal printer of this embodiment, the rectangle intersection rule includes:
[0060] Sort the connected domains according to the heights of their circumscribed rectangles;
[0061] When the height difference between two adjacent connected domains is within the preset range threshold, the connected domains are merged, otherwise, they are not merged.
[0062] Furthermore, in the printing method of the thermal printer described in this embodiment, in the process of merging the connected domains according to the rectangle intersection rule to obtain the merged connected domain, if the height of the merged connected domain is greater than the preset maximum threshold or less than the preset minimum threshold, the merged connected domain is discarded. In this way, before the connected domains are merged, the circumscribed rectangles of the connected domains that are too large or too small are excluded.
[0063] As an optional implementation of this embodiment, the printing method of the thermal printer described in this embodiment,
[0064] Determining the print font size range according to the rectangular height histogram, and taking an average value for the print font size range to obtain the print output font size comprises:
[0065] A rectangular height distribution curve with peaks and valleys is obtained based on the rectangular height histogram;
[0066] According to the peak and valley characteristics, a cutting process is performed on the rectangular height distribution curve to obtain at least one peak curve segment;
[0067] The corresponding print font size range is determined according to the rectangular height distribution range of each peak curve segment, and the final print font size range is determined according to the proportion of each print font size range.
[0068] This embodiment obtains a rectangular height distribution curve with peaks and troughs based on the rectangular height histogram to characterize the height distribution of the rectangular frame circumscribed in the connected domain. The rectangular height distribution curve of this embodiment generally contains at least one peak curve segment or multiple peak curve segments. This embodiment performs cutting processing on the rectangular height distribution curve based on the peak-trough characteristic, wherein the peak-trough characteristic refers to a peak between two troughs, and a peak curve segment is formed by cutting the curve segment between two adjacent troughs. A peak curve segment corresponds to a distribution range of the height of the rectangular frame circumscribed in the connected domain. The corresponding print font size range is determined according to the rectangular height distribution range of each peak curve segment, and the final print font size range is determined according to the proportion of each print font size range.
[0069] In the printing method of the thermal printer of the present embodiment, obtaining a rectangular height distribution curve with peaks and troughs based on a rectangular height histogram includes: performing smoothing processing on the rectangular height histogram to obtain a rectangular height distribution curve with peaks and troughs. In the present embodiment, the rectangular height histogram is formed according to the height statistics of the circumscribed rectangles of the connected domain, the horizontal axis is the height value of the circumscribed rectangle of the connected domain, and the vertical axis is the number; after the statistics are completed, there may be a situation where the height value of the circumscribed rectangle of the connected domain is highly discontinuous. For the situation where the difference in height values of the circumscribed rectangles of adjacent connected domains is small, smoothing processing is required to form a smooth and continuous rectangular height distribution curve. For example, in the rectangular height histogram, there are number values of height values of "5mm, 6mm, 8mm, 9mm", and the corresponding number values gradually increase, and there is no number value corresponding to the height value of "7mm", then it is necessary to perform a smooth transition connection between "5mm, 6mm, 8mm, 9mm" to avoid the formation of a rectangular height distribution curve that is disconnected here. However, for the situation where the difference in height values of the circumscribed rectangles of adjacent connected domains is large, there is no need to perform smoothing processing, and the rectangular height distribution curve is correspondingly disconnected when it is formed.
[0070] Further, as an optional implementation of this embodiment, the printing method of the thermal printer of this embodiment, the determining the corresponding printing font size range according to the rectangular height distribution range of each peak curve segment, and determining the final printing font size range according to the proportion of each printing font size range includes:
[0071] Determine whether the proportion of the minimum print font size range exceeds a preset threshold value of the first range;
[0072] If the judgment result is yes, the minimum print font size range is determined as the final print font size range; if the judgment result is no, it is determined whether the proportion of the next print font size range exceeds the second range preset threshold in the order of the print font size range from small to large, and the first range preset threshold and the second range preset threshold are the same or different;
[0073] The print font size ranges are judged in order from small to large whether they exceed the preset threshold of the corresponding range. Until the judgment result is yes, the print font size range corresponding to the current judgment result is output as the final print font size range. If the judgment results of all print font size ranges are no, the minimum print font size range is determined as the final print font size range.
[0074] For example, determine whether the proportion of the smallest print font size range exceeds the preset threshold value (30%) of the first range. If the judgment result is yes, directly determine the smallest print font size range as the final print font size range. If the judgment result is no, continue to determine whether the second smallest print font size range exceeds the preset threshold value (40%) of the second range. If the judgment result is yes, directly determine the second smallest print font size range as the final print font size range. If the judgment result is no, continue to determine whether the next print font size range exceeds its corresponding range preset threshold value.
[0075] In this embodiment, the preset range thresholds corresponding to various print font size ranges are different. The preset range threshold is set based on that the larger the font size value in the print font size range, the larger the preset range threshold. This is mainly because the larger the font size value in the print font size range, if it is determined as the final print font size range, the greater the probability that the minimum print font size cannot be printed normally. By increasing the preset range threshold corresponding to the print font size range corresponding to the large font size value, the print font size range can be determined as the main printing content, and the content smaller than the print font size range is interference content and is no longer considered when determining the print font size.
[0076] For example, the rectangular height distribution curve of the present embodiment is divided into a plurality of peak curve segments, and the corresponding printing font size segment ranges are sorted from small to large as (15, 18), (20, 22), and (23, 24). If the proportion of the printing font size segment range (15, 18) exceeds 30%, the smallest font size segment (15, 18) is directly determined as the final printing font size range. If the proportion of the printing font size segment range (15, 18) does not exceed 30%, it is further determined whether the proportion of the printing font size segment range (20, 22) exceeds 40%. If so, the printing font size segment range (20, 22) is determined as the final printing font size range. If not, it is further determined whether the proportion of the printing font size segment range (23, 24) exceeds 50%. If so, the printing font size segment range (23, 24) is determined as the final printing font size range. If not, the smallest font size segment (15, 18) is determined as the final printing font size range.
[0077] The printing method of the thermal printer described in this embodiment takes the average value of the font sizes within the printing font size range to obtain the printing font size of the printed text. For example, if (15, 18) is selected as the final printing font size range, the average value (15+16+17+18) / 4=16.5 is calculated for the printing font size range (15, 18), and the font size closest to 16 is taken as the printing font size of the printed text.
[0078] Furthermore, in the printing method of the thermal printer of this embodiment, judging whether the print font size meets the font size requirement of the thermal printer print output includes:
[0079] According to the device parameters, for example, 200 DPI, according to the actual printing experience, the tolerable minimum font size is set to 15, and 300 DPI is set to 21. By comparison, if the determined printing font size is smaller than this parameter, the final output result may not be suitable for printing, and printing output is not allowed.
[0080] As an optional implementation of this embodiment, the printing method of the thermal printer of this embodiment determines whether the determined font size range meets the font size requirement of the thermal printer, and if the determination result is no, further includes:
[0081] Determining a print content input source according to the print content;
[0082] If the print content input source is a screenshot of text content edited by a text editor, prompt the user to modify the font size;
[0083] If the input source of the print content is a photograph, the user is prompted to crop the picture.
[0084] As a specific example of the printing method of the thermal printer of this embodiment, the printing method of the thermal printer of this embodiment includes:
[0085] 1. Image Scaling
[0086] Thermal printers have limited print sizes. Printed content must be scaled to the size width supported by the printer. For example, the commonly used 57mm thermal paper consumables, depending on the printer type, a 200DPI printer prints 384 pixels wide, and a 300DPI printer prints 576 pixels wide. The image needs to be scaled to the corresponding size before it can be printed.
[0087] 2. Image Binarization
[0088] Due to the characteristics of thermal printers, they can only display black colors when heated, that is, they can only display black and white. Therefore, the image needs to be binarized before printing, and a binary image is also needed to extract the connected domain.
[0089] 3. Determine the text font size
[0090] Connected domains are extracted from the binary image to obtain the circumscribed rectangle information of the connected domain. The connected domains are merged according to the rectangle intersection rule to obtain the latest connected domain rectangle information. Rectangles that are too large or too small are excluded, such as those with a height exceeding half the image size and less than 2 pixels. The rectangle height histogram is statistically calculated and smoothed by the histogram. According to the peak and trough characteristics, the histogram is cut to obtain several possible font size ranges. According to the proportion of the histogram data of each font size range, the smallest font size range is prioritized. If it exceeds 30%, the final font size range is determined. The set parameter size is increased cumulatively according to the range. If all ranges fail, the minimum range is used by default. The range is averaged to obtain the final font size.
[0091] 4. Determine whether the font size is suitable for output
[0092] According to the device parameters, for example, at 200DPI, based on actual printing experience, the minimum tolerable font size is set to 15, and at 300DPI it is set to 21. By comparison, if it is smaller than this parameter, the final output result may not be suitable for printing. According to the decision, if the input source is a screenshot of the editor content, the user is prompted to modify the font size, and if the input source is a captured image, it is cropped.
[0093] The printing method of the thermal printer of the present embodiment extracts the width and height of the connected domain from the printed content image, performs statistics on the height, constructs a histogram, and then cuts and judges the histogram according to a certain logic to obtain the height of the text to be printed as the font size; according to the paper width and print head DPI of different printers, a minimum limit printing font size is preset to determine whether the current text image is suitable for printing. If it is not suitable for printing, the user is prompted to operate, or the image is operated in the form of automatic adjustment, thereby achieving the purpose.
[0094] The present embodiment also provides a thermal printer, and executes the printing method of the thermal printer. The thermal printer of the present embodiment automatically judges through the control end, intervenes in time before printing, and adjusts the editing font size in time according to the judgment result, or automatically cuts the text image or manually cuts it, so as to ensure that the final printed result is suitable and readable content.
[0095] This embodiment also provides a computer-readable storage medium storing a computer-executable program. When the computer-executable program is executed, the printing method of the thermal printer is implemented.
[0096] The computer-readable storage medium described in this embodiment may include a data signal propagated in a baseband or as part of a carrier wave, wherein a readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer-readable storage medium may also be any readable medium other than a readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, an apparatus, or a device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical cable, RF, etc., or any suitable combination of the above.
[0097] This embodiment further provides an electronic device, including a processor and a memory, wherein the memory is used to store a computer executable program, and when the computer program is executed by the processor, the processor executes the printing method of the thermal printer.
[0098] The electronic device is presented in the form of a general-purpose computing device. The processor may be one or more than one and work in coordination. The present invention does not exclude distributed processing, that is, the processor may be dispersed in different physical devices. The electronic device of the present invention is not limited to a single entity, but may also be the sum of multiple physical devices.
[0099] The memory stores a computer executable program, which is usually a machine-readable code. The computer-readable program can be executed by the processor to enable the electronic device to perform the method of the present invention, or at least part of the steps in the method.
[0100] The memory includes a volatile memory, such as a random access memory unit (RAM) and / or a cache memory unit, and may also be a non-volatile memory, such as a read-only memory unit (ROM).
[0101] It should be understood that the electronic device of the present invention may also include elements or components not shown in the above examples. For example, some electronic devices also include display units such as display screens, and some electronic devices also include human-computer interaction elements such as buttons and keyboards. As long as the electronic device can execute the computer-readable program in the memory to implement the method of the present invention or at least part of the steps of the method, it can be considered as an electronic device covered by the present invention.
[0102] Through the above description of the implementation mode, it is easy for those skilled in the art to understand that the present invention can be implemented by hardware capable of executing a specific computer program, such as the system of the present invention, and the electronic processing unit, server, client, mobile phone, control unit, processor, etc. contained in the system. The present invention can also be implemented by computer software that executes the method of the present invention, such as control software executed by a microprocessor, an electronic control unit, a client, a server, etc. However, it should be noted that the computer software that executes the method of the present invention is not limited to being executed by one or a specific hardware entity, and it can also be implemented in a distributed manner by unspecified specific hardware. For computer software, the software product can be stored in a computer-readable storage medium (which can be a CD-ROM, a U disk, a mobile hard disk, etc.), and can also be distributed and stored on the network, as long as it can enable the electronic device to execute the method according to the present invention.
[0103] The above embodiments are only used to illustrate the present invention and are not intended to limit the technical solutions described in the present invention. Although the present invention has been described in detail with reference to the above embodiments, the present invention is not limited to the above specific implementation methods. Therefore, any modification or equivalent replacement of the present invention; and all technical solutions and improvements thereof that do not depart from the spirit and scope of the invention are included in the scope of the claims of the present invention.
Claims
1. A printing method for a thermal printer, characterized in that: include: Performing image binarization processing on the printed content to obtain a printed binary image; Extract the connected domains of the printed binary image and obtain the circumscribed rectangles of each connected domain; Determine the font size of the printed text according to the height of the circumscribed rectangle of each connected domain; Determine whether the print font size meets the font size requirement of the thermal printer, if the determination result is yes, print out according to the determined print font size, if the determination result is no, do not allow print out; The step of determining the print font size of the printed text according to the height of the circumscribed rectangle of each connected region comprises: Count the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram; Determine a print font size range according to the rectangular height histogram, and take an average value of the font sizes within the print font size range to obtain a print font size of the printed text; The counting of the heights of the circumscribed rectangles of each connected domain to obtain a rectangle height histogram comprises: The connected domains are merged according to the rectangle intersection rule to obtain a merged connected domain, and a new merged connected domain circumscribed rectangle is obtained based on the merged connected domain; The heights of the circumscribed rectangles of each merged connected domain are counted to obtain a rectangle height histogram.
2. The printing method of the thermal printer according to claim 1, characterized in that: The rectangle intersection rules include: Sort the connected domains according to the heights of their circumscribed rectangles; When the height difference between two adjacent connected domains is within the preset range threshold, the connected domains are merged, otherwise, they are not merged.
3. The printing method of the thermal printer according to claim 1, characterized in that: In the process of merging connected domains according to the rectangular intersection rule to obtain a merged connected domain, if the height of the merged connected domain is greater than a preset maximum threshold or less than a preset minimum threshold, the merged connected domain is discarded.
4. The printing method of a thermal printer according to claim 1, characterized in that: Determining the print font size range according to the rectangular height histogram, and taking an average value for the print font size range to obtain the print output font size comprises: A rectangular height distribution curve with peaks and valleys is obtained based on the rectangular height histogram; According to the peak and valley characteristics, a cutting process is performed on the rectangular height distribution curve to obtain at least one peak curve segment; The corresponding print font size range is determined according to the rectangular height distribution range of each peak curve segment, and the final print font size range is determined according to the proportion of each print font size range.
5. The printing method of the thermal printer according to claim 4, characterized in that: Determining the corresponding print font size range according to the rectangular height distribution range of each peak curve segment, and determining the final print font size range according to the proportion of each print font size range includes: Determine whether the proportion of the minimum print font size range exceeds a preset threshold value of the first range; If the judgment result is yes, the minimum print font size range is determined as the final print font size range; if the judgment result is no, it is determined whether the proportion of the next print font size range exceeds the second range preset threshold in the order of the print font size range from small to large, and the first range preset threshold and the second range preset threshold are the same or different; In order from small to large, the print font size ranges are judged in turn whether they exceed the preset threshold values of the corresponding ranges. Until the judgment result is yes, the print font size range corresponding to the current judgment result is output as the final print font size range. If the judgment results of all print font size ranges are no, the minimum print font size range is determined as the final print font size range, wherein the size of the print font size range is determined by comparing the font size values.
6. The printing method of a thermal printer according to claim 1, characterized in that: Determine whether the determined font size range meets the font size requirement of the thermal printer. If the determination result is no, further comprising: Determining a print content input source according to the print content; If the print content input source is a screenshot of text content edited by a text editor, prompt the user to modify the font size; If the input source of the print content is a photograph, the user is prompted to crop the picture.
7. A thermal printer, characterized in that: Execute the printing method of the thermal printer as described in any one of claims 1-6.
8. A computer-readable storage medium storing a computer-executable program, characterized in that: When the computer executable program is executed, the printing method of the thermal printer according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Assessing print quality using intensity histograms and perimeter lengths
US20210203790A1