TWI778735B - Image processing method, computer device, and storage medium - Google Patents

Image processing method, computer device, and storage medium Download PDF

Info

Publication number
TWI778735B
TWI778735B TW110128607A TW110128607A TWI778735B TW I778735 B TWI778735 B TW I778735B TW 110128607 A TW110128607 A TW 110128607A TW 110128607 A TW110128607 A TW 110128607A TW I778735 B TWI778735 B TW I778735B
Authority
TW
Taiwan
Prior art keywords
image
images
character
processing method
text
Prior art date
Application number
TW110128607A
Other languages
Chinese (zh)
Other versions
TW202307729A (en
Inventor
王正峯
王柏忠
林立哲
Original Assignee
鴻海精密工業股份有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 鴻海精密工業股份有限公司 filed Critical 鴻海精密工業股份有限公司
Priority to TW110128607A priority Critical patent/TWI778735B/en
Application granted granted Critical
Publication of TWI778735B publication Critical patent/TWI778735B/en
Publication of TW202307729A publication Critical patent/TW202307729A/en

Links

Images

Landscapes

  • Image Analysis (AREA)
  • Processing Or Creating Images (AREA)

Abstract

The present application provides an image processing method, a computer device, and a storage medium. The image processing method includes: determining a text area and a background area of a flawless image to obtain a first image of each text; removing the background area from the first image to obtain a second image; processing the second image to obtain a third image, N fourth images, and N fifth images corresponding to the fourth image one-to-one; calculating a similarity value between each fifth image and the corresponding third image, and determining a defect threshold; determining whether the fourth image corresponding to the fifth image is a defective image; when the fourth image is a flawed image, performing a shading processing on an intercepted background image, and synthesizing the flawed image and the intercepted background image after the shading processing, and obtaining a composite image. This application can assist in generating flawed training samples and reduce labor costs.

Description

影像處理方法、電腦裝置及儲存介質 Image processing method, computer device and storage medium

本發明涉及影像處理領域,尤其涉及一種影像處理方法、電腦裝置及儲存介質。 The present invention relates to the field of image processing, and in particular, to an image processing method, a computer device and a storage medium.

由於目前的工業生產過程中良率較高,所以較難取得大量的有瑕疵的印字圖像樣本,用以作為訓練樣本對瑕疵檢測模型進行訓練。現有的人工進行合成有瑕疵樣本的方法,在生成模擬資料後還需要人工對其中的有瑕疵資料進行標記,或是訓練另一個深度學習模型來加以分類,耗費較多人力和時間,並且人工標記過程中還容易出現錯漏。如何在保證準確率的前提下,高效解決訓練資料不足的問題,一直是深度學習在應用上的一大課題。 Due to the high yield rate in the current industrial production process, it is difficult to obtain a large number of defective printing image samples, which are used as training samples to train the defect detection model. The existing method of manually synthesizing defective samples requires manual labeling of the defective data after generating the simulated data, or training another deep learning model for classification, which consumes a lot of manpower and time, and requires manual labeling. Errors are also prone to occur in the process. How to efficiently solve the problem of insufficient training data under the premise of ensuring accuracy has always been a major issue in the application of deep learning.

鑒於以上內容,有必要提供一種影像處理方法、電腦裝置及儲存介質,能夠自動生成大量有瑕疵的印字圖像,降低人工合成以及標記的成本。 In view of the above, it is necessary to provide an image processing method, a computer device and a storage medium, which can automatically generate a large number of defective printing images and reduce the cost of manual synthesis and marking.

所述影像處理方法包括:獲取無瑕疵圖像,確定所述無瑕疵圖像的文字區與背景區,並確定所述文字區中每個文字的位置;根據所述每個文字的位置對所述文字區進行分割,獲得每個文字的第一圖像;對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像;根據預設的第一 影像處理方法處理所述每個文字的第二圖像,獲得每個文字的第三圖像;根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和所述N幅第五圖像一一對應,N為大於1的正整數;計算所述每個文字的N幅第五圖像中的每幅第五圖像與所述每個文字的第三圖像之間的相似性度量,獲得每個文字對應的N個相似性度量,並將每個文字的N幅第五圖像與所述每個文字對應的N個相似性度量分別建立關聯,根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值;比較每個文字對應的N個相似性度量中的每個相似性度量與所述瑕疵閾值的大小,其中,當任一文字對應的任意一個相似性度量大於所述瑕疵閾值時,確定與所述任意一個相似性度量關聯的第五圖像對應的第四圖像為有瑕疵圖像;當任意一幅第四圖像被確定為有瑕疵圖像時,從所述背景區中截取一幅背景圖像,所述截取的背景圖像的大小等於所述有瑕疵圖像的大小;及對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像。 The image processing method includes: acquiring a flawless image, determining a text area and a background area of the flawless image, and determining the position of each character in the text area; The text area is divided to obtain the first image of each character; the background is removed from the first image of each character to obtain the second image of each character; according to the preset first image The image processing method processes the second image of each character to obtain a third image of each character; processes the second image of each character according to a preset second image processing method to obtain each character N fourth images and N fifth images, the N fourth images of each character and the N fifth images are in one-to-one correspondence, and N is a positive integer greater than 1; Describe the similarity measure between each of the N fifth images of each character and the third image of each character, obtain N similarity measures corresponding to each character, and Associating the N fifth images of each character with the N similarity measures corresponding to each character respectively, and determining a defect threshold according to the N similarity measurements corresponding to all characters in the character area; compare The size of each similarity measure in the N similarity measures corresponding to each character and the defect threshold, wherein, when any similarity measure corresponding to any character is greater than the defect threshold, it is determined to be the same as the defect threshold. The fourth image corresponding to the fifth image associated with the similarity measure is a defective image; when any fourth image is determined to be a defective image, a background image is intercepted from the background area , the size of the intercepted background image is equal to the size of the defective image; and performing brightness processing on the intercepted background image, and synthesizing the defective image and the background after the brightness processing image to obtain a composite image.

可選地,所述第一影像處理方法包括圖像二值化、輪廓提取;所述第二影像處理方法包括抹除處理、圖像二值化、輪廓提取。 Optionally, the first image processing method includes image binarization and contour extraction; the second image processing method includes erasure processing, image binarization, and contour extraction.

可選地,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法一:利用大津演算法確定所述第一圖像的第一閾值,根據所述第一閾值獲取所述第一圖像的掩膜,並將所述掩膜與所述第一圖像進行按位元與運算,獲得所述第一圖像的前景文字圖像;及利用高斯模糊技術對所述前景文字圖像進行柔化邊緣處理,獲得所述第二圖像。 Optionally, removing the background from the first image of each character, and obtaining the second image of each character includes method 1: using the Otsu algorithm to determine the first threshold of the first image, according to obtaining the mask of the first image by the first threshold, and performing a bitwise AND operation on the mask and the first image to obtain a foreground text image of the first image; and The second image is obtained by softening the edge of the foreground text image by using the Gaussian blurring technique.

可選地,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法二:利用傅裡葉變換去除所述第一圖像中的網點,對去除網點後的所述第一圖像進行二值化;及利用高斯模糊技術對二值化後的所述第一圖像進行柔化邊緣處理,獲得所述第二圖像。 Optionally, removing the background from the first image of each character and obtaining the second image of each character includes method 2: removing the dots in the first image by using Fourier transform, Perform binarization on the first image after removing the dots; and perform edge softening processing on the binarized first image by using Gaussian blur technology to obtain the second image.

可選地,所述第一影像處理方法以及所述第二影像處理方法根據所述第一閾值進行圖像二值化,以及利用傅裡葉描述子演算法或不變矩演算法進行輪廓提取。 Optionally, the first image processing method and the second image processing method perform image binarization according to the first threshold, and perform contour extraction by using a Fourier descriptor algorithm or an invariant moment algorithm. .

可選地,所述根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和所述N幅第五圖像一一對應,包括:對所述每個文字的第二圖像進行N次隨機抹除,獲得每個文字的N幅第四圖像;對所述每個文字的N幅第四圖像執行圖像二值化,獲得N幅黑白圖像;對所述N幅黑白圖像進行輪廓提取,獲得所述N幅第五圖像。 Optionally, the second image of each character is processed according to the preset second image processing method to obtain N fourth images and N fifth images of each character, each There is a one-to-one correspondence between the N fourth images of the characters and the N fifth images, including: randomly erasing the second images of each character N times to obtain N fourth images of each character image; perform image binarization on the N fourth images of each character to obtain N black and white images; perform contour extraction on the N black and white images to obtain the N fifth images picture.

可選地,所述相似性度量是指所述每個文字的每幅第五圖像與所述每個文字的第三圖像之間的歐氏距離;其中,所述根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值包括:根據每個所述相似性度量的值對應的所述第五圖像的圖像個數,製作所述相似性度量與所述圖像個數的折線關係圖;及將所述折線關係圖中所述相似性度量的第一個局部最小值作為所述瑕疵閾值。 Optionally, the similarity measure refers to the Euclidean distance between each fifth image of each character and the third image of each character; The N similarity measures corresponding to all the texts respectively, and determining a defect threshold includes: according to the number of images of the fifth image corresponding to the value of each similarity measure, making the similarity measure and the a polyline relationship graph of the number of images; and the first local minimum value of the similarity measure in the polyline relationship graph as the defect threshold.

可選地,所述對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像包括:對所截取的背景圖像進行多次明暗度調整,獲得多幅調整圖像,將所述多幅調整圖像分別與所述有瑕疵圖像進行合成處理,獲得多幅合成圖像。 Optionally, performing brightness processing on the captured background image, synthesizing the defective image and the background image after brightness processing, and obtaining a composite image includes: processing the captured background image. The image is subjected to multiple brightness adjustment to obtain multiple adjusted images, and the multiple adjusted images are respectively combined with the defective image to obtain multiple synthesized images.

所述電腦可讀儲存介質儲存有至少一個指令,所述至少一個指令被處理器執行時實現所述影像處理方法。 The computer-readable storage medium stores at least one instruction, and the at least one instruction implements the image processing method when executed by the processor.

所述電腦裝置包括儲存器和至少一個處理器,所述儲存器中儲存有至少一個指令,所述至少一個指令被所述至少一個處理器執行時實現所述影像處理方法。 The computer device includes a memory and at least one processor, the memory stores at least one instruction, and the at least one instruction implements the image processing method when executed by the at least one processor.

相較於習知技術,所述影像處理方法、電腦裝置及儲存介質,能夠自動生成大量有瑕疵的印字圖像,不需要訓練額外的深度學習模型即可 對其中的訓練樣本進行自動標記,降低人工合成以及標記的成本。 Compared with the prior art, the image processing method, computer device and storage medium can automatically generate a large number of defective printing images without training an additional deep learning model. Automatically label the training samples in it, reducing the cost of artificial synthesis and labeling.

3:電腦裝置 3: Computer device

30:影像處理系統 30: Image processing system

31:儲存器 31: Storage

32:處理器 32: Processor

S1~S11:步驟 S1~S11: Steps

為了更清楚地說明本申請實施例或習知技術中的技術方案,下面將對實施例或習知技術描述中所需要使用的附圖作簡單地介紹,顯而易見地,下面描述中的附圖僅僅是本申請的實施例,對於本領域普通技術人員來講,在不付出創造性勞動的前提下,還可以根據提供的附圖獲得其他的附圖。 In order to more clearly illustrate the technical solutions in the embodiments of the present application or in the prior art, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only It is an embodiment of the present application. For those of ordinary skill in the art, other drawings can also be obtained according to the provided drawings without any creative effort.

圖1是本申請實施例提供的影像處理方法的流程圖。 FIG. 1 is a flowchart of an image processing method provided by an embodiment of the present application.

圖2是本申請實施例提供的電腦裝置的架構圖。 FIG. 2 is a structural diagram of a computer device provided by an embodiment of the present application.

圖3是本申請實施例提供的步驟S1和步驟S2的示例圖。 FIG. 3 is an example diagram of step S1 and step S2 provided by an embodiment of the present application.

圖4是本申請實施例提供的獲得第二圖像的過程的示例圖。 FIG. 4 is an example diagram of a process for obtaining a second image provided by an embodiment of the present application.

圖5是本申請實施例提供的獲得有瑕疵圖像的過程的示例圖。 FIG. 5 is an example diagram of a process for obtaining a defective image provided by an embodiment of the present application.

圖6是本申請實施例提供的折線關係圖的示例圖。 FIG. 6 is an example diagram of a polyline relationship diagram provided by an embodiment of the present application.

圖7是本申請實施例提供的獲得合成圖像的過程的示例圖。 FIG. 7 is an exemplary diagram of a process for obtaining a composite image provided by an embodiment of the present application.

為了能夠更清楚地理解本申請的上述目的、特徵和優點,下面結合附圖和具體實施例對本申請進行詳細描述。需要說明的是,在不衝突的情況下,本申請的實施例及實施例中的特徵可以相互組合。 In order to more clearly understand the above objects, features and advantages of the present application, the present application will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be noted that the embodiments of the present application and the features in the embodiments may be combined with each other in the case of no conflict.

在下面的描述中闡述了很多具體細節以便於充分理解本申請,所描述的實施例僅僅是本申請一部分實施例,而不是全部的實施例。基於本申請中的實施例,本領域普通技術人員在沒有做出創造性勞動前提下所獲得的所有其他實施例,都屬於本申請保護的範圍。 In the following description, many specific details are set forth to facilitate a full understanding of the present application, and the described embodiments are only a part of the embodiments of the present application, but not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

除非另有定義,本文所使用的所有的技術和科學術語與屬於本申請的技術領域的技術人員通常理解的含義相同。本文中在本申請的說明書 中所使用的術語只是為了描述具體的實施例的目的,不是旨在於限制本申請。 Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the technical field to which this application belongs. Specifications herein in this application The terminology used is for the purpose of describing particular embodiments only and is not intended to limit the application.

參閱圖1所示,為本申請較佳實施例的影像處理方法的流程圖。 Referring to FIG. 1 , it is a flowchart of an image processing method according to a preferred embodiment of the present application.

在本實施例中,所述影像處理方法可以應用於電腦裝置(例如圖2所示的電腦裝置3)中,對於需要進行影像處理的電腦裝置,可以直接在電腦裝置上集成本申請的方法所提供的用於影像處理的功能,或者以軟體開發套件(Software Development Kit,SDK)的形式運行在電腦裝置上。 In this embodiment, the image processing method can be applied to a computer device (for example, the computer device 3 shown in FIG. 2 ). For a computer device that needs to perform image processing, the method of the present application can be directly integrated on the computer device. The provided functions for image processing, or run on a computer device in the form of a software development kit (Software Development Kit, SDK).

如圖1所示,所述影像處理方法具體包括以下步驟,根據不同的需求,該流程圖中步驟的順序可以改變,某些步驟可以省略。 As shown in FIG. 1 , the image processing method specifically includes the following steps. According to different requirements, the order of the steps in the flowchart can be changed, and some steps can be omitted.

步驟S1,電腦裝置獲取無瑕疵圖像,確定所述無瑕疵圖像的文字區與背景區,並確定所述文字區中每個文字的位置。 In step S1, the computer device acquires a flawless image, determines a text area and a background area of the flawless image, and determines the position of each text in the text area.

在一個實施例中,電腦裝置可以回應用戶輸入獲取一幅無瑕疵圖像。所述無瑕疵圖像還可以預先儲存在電腦裝置的儲存器中,或者預先儲存在與電腦裝置通訊連接的其他設備中。本實施例中,所述無瑕疵圖像可以是工廠生產的印刷品的標準樣本(Golden Sample)圖像,所述無瑕疵圖像中包含文字(例如,漢字、數位、英文字母等)。需要說明的是,標準樣本圖像的位置不需要校正,其中文字的排列方向也不需要校正。 In one embodiment, the computer device may acquire a flawless image in response to user input. The flawless image may also be pre-stored in the memory of the computer device, or pre-stored in other devices communicatively connected to the computer device. In this embodiment, the flawless image may be a standard sample (Golden Sample) image of a printed matter produced by a factory, and the flawless image contains characters (eg, Chinese characters, numbers, English letters, etc.). It should be noted that the position of the standard sample image does not need to be corrected, and the arrangement direction of the characters also does not need to be corrected.

在一個實施例中,電腦裝置可以利用光學字元辨識(Optical Character Recognition,OCR)技術識別所述無瑕疵圖像的文字,進而確認所述無瑕疵圖像的文字區與背景區,並確定所述文字區中每個文字的位置。所述文字區是指包含文字的區域,電腦裝置可以利用感興趣區域技術(Region Of Interest,ROI),勾勒出所述文字區,例如圖3所示,沿文字的排列方向用週邊的大矩形框(實線)將所有文字框在其內,框出所述文字區,需要說明的是,圖3中大矩形框週邊的虛線框僅用於指示所述大矩形框;所述背景區是指不包含文字的區域,即所述無瑕疵圖像中所述文字區之外的區域,例如圖3所示陰影表示的區域。 In one embodiment, the computer device can use Optical Character Recognition (OCR) technology to recognize the text of the flawless image, and then confirm the text area and background area of the flawless image, and determine the text area and the background area of the flawless image. The position of each text in the description text area. The text area refers to an area containing text, and the computer device can use the Region Of Interest (ROI) technology to outline the text area. For example, as shown in FIG. The frame (solid line) encloses all the text in it, and frames the text area. It should be noted that the dotted frame around the large rectangular frame in FIG. 3 is only used to indicate the large rectangular frame; the background area is Refers to the area that does not contain text, that is, the area outside the text area in the flawless image, such as the area indicated by hatching in FIG. 3 .

步驟S2,電腦裝置根據所述每個文字的位置對所述文字區進行分割,獲得每個文字的第一圖像。 In step S2, the computer device divides the character area according to the position of each character to obtain a first image of each character.

在一個實施例中,電腦裝置可以使用OCR軟體的字元切割功能對所述文字區進行分割,分割出每個文字所在的區域,獲得每個文字的第一圖像,所述每個文字的第一圖像中包含該文字的完整文字輪廓的圖像。舉例而言,可以對圖3中的大矩形框(實線)進行分割,根據圖3中的小矩形框(實線),分割出文字“0”所在區域的矩形圖像,獲得如圖4中所示的文字“0”的第一圖像3B1,需要說明的是,圖3中小矩形框週邊的虛線框僅用於指示所述小矩形框。 In one embodiment, the computer device can use the character cutting function of the OCR software to segment the text area, segment the area where each text is located, and obtain the first image of each text, the The first image contains an image of the complete text outline of the text. For example, the large rectangular frame (solid line) in Figure 3 can be segmented, and according to the small rectangular frame (solid line) in Figure 3, a rectangular image of the area where the text "0" is located can be obtained, as shown in Figure 4 In the first image 3B1 of the character “0” shown in FIG. 3 , it should be noted that the dotted frame around the small rectangular frame in FIG. 3 is only used to indicate the small rectangular frame.

步驟S3,電腦裝置對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像。 In step S3, the computer device removes the background of the first image of each character to obtain a second image of each character.

在一個實施例中,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法一:電腦裝置利用大津演算法(OTSU Thresholding)確定所述第一圖像的第一閾值,根據所述第一閾值獲取所述第一圖像的掩膜(mask),並將所述掩膜與所述第一圖像進行按位元與(Bitwise AND)運算,獲得所述第一圖像的前景文字圖像;及利用高斯模糊技術(Gaussian Blur)對所述前景文字圖像進行柔化邊緣(Soft Edge)處理,獲得所述第二圖像。 In one embodiment, removing the background from the first image of each character to obtain the second image of each character includes method 1: a computer device determines the first image by using OTSU Thresholding The first threshold of the image, obtain the mask of the first image according to the first threshold, and perform a bitwise AND (Bitwise AND) operation on the mask and the first image , obtaining a foreground text image of the first image; and using a Gaussian Blur technology to perform Soft Edge processing on the foreground text image to obtain the second image.

在一個實施例中,所述方法一適用於背景複雜度較低的所述第一圖像的,例如,所述第一圖像為絲網印刷(Silk Screen Process Printing)圖像。所述大津演算法可以確定所述第一圖像的所述第一閾值,所述第一閾值包括所述第一圖像的圖像二值化(Thresholding)最佳分割閾值(例如,30);並按照所述第一閾值對所述第一圖像進行二值化,獲得所述第一圖像的所述掩膜。例如圖4中,利用大津演算法獲得第一圖像3B1的掩膜圖像3B2。 In one embodiment, the first method is suitable for the first image with low background complexity, for example, the first image is a silk screen printing (Silk Screen Process Printing) image. The Otsu algorithm may determine the first threshold of the first image, the first threshold comprising an image binarization (Thresholding) optimal segmentation threshold (eg, 30) of the first image ; and binarize the first image according to the first threshold to obtain the mask of the first image. For example, in FIG. 4 , the mask image 3B2 of the first image 3B1 is obtained by using the Otsu algorithm.

在一個實施例中,所述按位與運算可以將所述第一圖像中的前景 文字輪廓圖像與不包含文字輪廓的背景分離,獲得所述第一圖像的前景文字圖像和背景圖像,所述前景文字圖像的背景為透明。例如圖4中,根據圖像3B2獲得圖像3B1的前景文字圖像3B3和背景圖像3B4。 In one embodiment, the bitwise AND operation may convert the foreground in the first image The text outline image is separated from the background that does not contain the text outline, and the foreground text image and the background image of the first image are obtained, and the background of the foreground text image is transparent. For example, in FIG. 4 , the foreground text image 3B3 and the background image 3B4 of the image 3B1 are obtained according to the image 3B2.

在一個實施例中,如圖4中前景文字圖像3B3所示,由於所述前景文字圖像會包含鋸齒狀邊緣,所以可以利用高斯模糊技術對其進行柔化邊緣處理,獲得的所述第二圖像如圖4中第二圖像3B5所示。 In one embodiment, as shown in the foreground text image 3B3 in FIG. 4 , since the foreground text image may contain jagged edges, the Gaussian blur technology can be used to soften the edges, and the obtained first The two images are shown as the second image 3B5 in FIG. 4 .

在一個實施例中,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法二:電腦裝置利用傅裡葉變換(Fourier Transform)去除所述第一圖像中的網點,對去除網點後的所述第一圖像進行二值化;及利用高斯模糊技術對二值化後的所述第一圖像進行柔化邊緣處理,獲得所述第二圖像。 In one embodiment, removing the background from the first image of each character to obtain the second image of each character includes method 2: a computer device removes the first image by using Fourier Transform (Fourier Transform) For the dots in an image, binarize the first image after removing the dots; and use Gaussian blur technology to soften the edge of the binarized first image to obtain the first image. Second image.

在一個實施例中,所述方法二適用於含有網點(例如,方形網點、圓形網點等)的背景複雜度較高的所述第一圖像,例如,所述第一圖像為套色印刷圖像。所述傅裡葉變換可以改變所述第一圖像的頻率(Frequency),從而達到去除網點的效果;對去除網點後的所述第一圖像進行的所述二值化可以是所述方法一中的所述大津演算法;所述高斯模糊技術與所述方法一中所使用的技術相同。 In one embodiment, the second method is applicable to the first image with high background complexity including halftone dots (for example, square halftone dots, circular halftone dots, etc.), for example, the first image is color printing image. The Fourier transform can change the frequency (Frequency) of the first image, so as to achieve the effect of removing the dots; the binarization performed on the first image after removing the dots can be the method described above. The Otsu algorithm in one; the Gaussian blurring technique is the same as that used in method one.

步驟S4,電腦裝置根據預設的第一影像處理方法處理所述每個文字的第二圖像,獲得每個文字的第三圖像。 Step S4, the computer device processes the second image of each character according to the preset first image processing method to obtain a third image of each character.

在一個實施例中,所述第一影像處理方法包括圖像二值化、輪廓提取。電腦裝置根據所述第一閾值對所述第二圖像進行圖像二值化,例如,當所述第二圖像中任一位置處的圖元(pixel)值大於或等於所述第一閾值時,將該任一位置處的圖元二值化為255;當所述第二圖像中任一位置處的圖元值小於所述第一閾值時,將該任一位置處的圖元二值化為0。例如圖5所示,對第二圖像3B5進行圖像二值化後獲得圖像4A1。 In one embodiment, the first image processing method includes image binarization and contour extraction. The computer device performs image binarization on the second image according to the first threshold, for example, when the pixel value at any position in the second image is greater than or equal to the first When the threshold is set, the image element at any position is binarized to 255; when the value of the image element at any position in the second image is less than the first threshold, the image at any position is Meta binarization to 0. For example, as shown in FIG. 5 , an image 4A1 is obtained after the second image 3B5 is binarized.

在一個實施例中,電腦裝置利用傅裡葉描述子(Fourier Descriptors)演算法或不變矩(Invariant Moments)演算法,對圖像二值化後的所述第二圖像中的文字進行輪廓提取;所述傅裡葉描述子演算法可以識別圖像二值化後的所述第二圖像中文字輪廓的閉合邊緣,並對其進行重建,從而提取所述文字輪廓;所述不變矩演算法利用平移不變形、比例不變性和旋轉不變性等性質,描述圖像二值化後的所述第二圖像的整體特徵,從而提取圖像二值化後的所述第二圖像中的文字輪廓。例如圖5所示,對圖像4A1進行輪廓提取後得到文字“0”的第三圖像4A2。需要說明的是,所述無瑕疵圖像中每個文字都有與之一一對應的第三圖像,當所述無瑕疵圖像中包含M個文字時,共獲得M幅所述第三圖像,其中M表示大於0的正整數。 In one embodiment, the computer device utilizes Fourier descriptors Descriptors) algorithm or Invariant Moments algorithm to extract the outline of the text in the second image after image binarization; the Fourier descriptor algorithm can identify the second image The closed edge of the text outline in the second image after valueization is reconstructed, so as to extract the text outline; the invariant moment algorithm uses translation invariance, scale invariance and rotation invariance, etc. The property describes the overall characteristics of the second image after the image binarization, so as to extract the text outline in the second image after the image binarization. For example, as shown in FIG. 5 , after performing contour extraction on the image 4A1, a third image 4A2 with the character "0" is obtained. It should be noted that, each character in the flawless image has a third image corresponding to one of them, and when the flawless image contains M characters, a total of M pieces of the third image are obtained. image, where M represents a positive integer greater than 0.

步驟S5,電腦裝置根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和N幅第五圖像一一對應,N為大於1的正整數。 Step S5, the computer device processes the second image of each character according to the preset second image processing method, and obtains N fourth images and N fifth images of each character. The N fourth images of , and N fifth images are in one-to-one correspondence, and N is a positive integer greater than 1.

在一個實施例中,電腦裝置可以使用圖像抹除工具(例如,Photoshop中的橡皮擦工具)對所述每個文字的第二圖像進行N次隨機抹除,獲得每個文字的N幅第四圖像,例如圖5所示,對文字“0”的第二圖像3B5進行2次隨機抹除後,獲得文字“0”的2幅第四圖像:第四圖像4B1和第四圖像4C1。 In one embodiment, the computer device may use an image erasing tool (eg, an eraser tool in Photoshop) to randomly erase the second image of each character N times to obtain N images of each character For the fourth image, for example, as shown in FIG. 5 , after randomly erasing the second image 3B5 of the character “0” twice, two fourth images of the character “0” are obtained: the fourth image 4B1 and the second image 3B5 of the character “0”. Four images 4C1.

在一個實施例中,電腦裝置對所述每個文字的N幅第四圖像執行圖像二值化,獲得N幅黑白圖像,所述圖像二值化與步驟S4中所使用的方法相同,例如圖5所示,對第四圖像4B1進行圖像二值化後獲得圖像4B2,對第四圖像4C1進行圖像二值化後獲得圖像4C2。 In one embodiment, the computer device performs image binarization on the N fourth images of each character to obtain N black and white images, and the image binarization is the same as the method used in step S4. Similarly, for example, as shown in FIG. 5 , image 4B2 is obtained after image binarization is performed on the fourth image 4B1 , and image 4C2 is obtained after image binarization is performed on the fourth image 4C1 .

在一個實施例中,電腦裝置對所述N幅黑白圖像進行輪廓提取,獲得所述N幅第五圖像,所述輪廓提取與步驟S4中所使用的方法相同,例如圖5所示,對圖像4B2進行輪廓提取後獲得文字“0”的第五圖像4B3;對圖像4C2進行輪廓提取後獲得文字“0”的第五圖像4C3。 In one embodiment, the computer device performs contour extraction on the N black-and-white images to obtain the N fifth images, and the contour extraction is the same as that used in step S4, for example, as shown in FIG. 5 , The fifth image 4B3 with the character "0" is obtained after the contour extraction is performed on the image 4B2; the fifth image 4C3 with the character "0" is obtained after the contour extraction is performed on the image 4C2.

需要說明的是,當所述無瑕疵圖像中包含M個文字時,獲得每個文字的N幅第四圖像後,共獲得所有文字的M*N幅第四圖像,也就會獲得M*N幅第五圖像。 It should be noted that, when the flawless image contains M characters, after N fourth images of each character are obtained, M*N fourth images of all characters are obtained in total, and the M*N fifth images.

步驟S6,電腦裝置計算所述每個文字的N幅第五圖像中的每幅第五圖像與所述每個文字的第三圖像之間的相似性度量(Similarity Measurement),獲得每個文字對應的N個相似性度量,並將每個文字的N幅第五圖像與所述每個文字對應的N個相似性度量分別建立關聯,根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值。 Step S6, the computer device calculates the similarity measure (Similarity Measurement) between each fifth image in the N fifth images of each character and the third image of each character, and obtains each N similarity measures corresponding to each text, and the N fifth images of each text are associated with the N similarity measures corresponding to each text, respectively. The N similarity measures determine a flaw threshold.

在一個實施例中,所述相似性度量是指所述每個文字的每幅第五圖像與所述每個文字的第三圖像之間的歐氏距離(Euclidean Distance)。電腦裝置透過計算每個文字的每幅所述第五圖像與所述每個文字的第三圖像之間的歐氏距離,由此獲得與每個文字的每幅所述第五圖像對應的相似性度量的值。舉例而言,如圖5所示,對於有兩幅第五圖像的文字“0”而言,文字“0”的第五圖像4B3與第三圖像4A2之間的歐式距離為0.76,文字“0”的第五圖像4C3與第三圖像4A2之間的歐式距離為0.23。需要說明的是,當所述無瑕疵圖像中包含M個文字時,獲得每個文字的N幅第四圖像後,共獲得所有文字的M*N幅第四圖像,也就會獲得M*N幅第五圖像,進而獲得M*N個相似性度量的值。 In one embodiment, the similarity measure refers to the Euclidean Distance (Euclidean Distance) between each fifth image of each character and the third image of each character. The computer device calculates the Euclidean distance between each of the fifth images of each character and the third image of each character, thereby obtaining each of the fifth images of each character and each character The value of the corresponding similarity measure. For example, as shown in FIG. 5 , for the text “0” with two fifth images, the Euclidean distance between the fifth image 4B3 of the text “0” and the third image 4A2 is 0.76, The Euclidean distance between the fifth image 4C3 of the text "0" and the third image 4A2 is 0.23. It should be noted that, when the flawless image contains M characters, after N fourth images of each character are obtained, M*N fourth images of all characters are obtained in total, and the M*N fifth images, and then M*N similarity measure values are obtained.

在一個實施例中,所述根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值包括:根據每個所述相似性度量的值對應的所述第五圖像的圖像個數,製作所述相似性度量與所述圖像個數的折線關係圖。 In one embodiment, the determining a defect threshold according to the N similarity measures corresponding to all the texts in the text area comprises: according to the value of each similarity measure corresponding to the image of the fifth image According to the number of images, a graph of the relationship between the similarity measure and the number of images is made.

具體而言,當所述無瑕疵圖像中包含M個文字時,電腦裝置在獲得M*N個相似性度量的值之後,會統計每個相似性度量的值對應的第五圖像的個數,並以所述相似性度量為橫軸,所述第五圖像的個數為縱軸,製作所述折線關係圖。例如,與相似性度量的值為0.01對應的第五圖像的 個數為36,與相似性度量的值為0.35對應的第五圖像的個數為0,與相似性度量的值為0.82對應的第五圖像的個數為52等,製作得到的折線關係圖如圖6所示。 Specifically, when the flawless image contains M characters, after obtaining M*N similarity metric values, the computer device will count the number of the fifth image corresponding to each similarity metric value. and the number of the fifth images is taken as the horizontal axis and the number of the fifth images is taken as the vertical axis, and the polyline relationship graph is made. For example, the value of the fifth image corresponding to the similarity measure of 0.01 The number is 36, the number of fifth images corresponding to the similarity metric value of 0.35 is 0, the number of fifth images corresponding to the similarity metric value of 0.82 is 52, etc., the obtained polyline The relationship diagram is shown in Figure 6.

在一個實施例中,電腦裝置將所述折線關係圖中所述相似性度量的第一個局部最小值(Local Minimum)作為所述瑕疵閾值。舉例而言,如圖6所示,所述折線關係圖中所述相似性度量的第一個局部最小值為0.35,那麼所述瑕疵閾值為0.35,需要說明的是,圖6中的虛線僅用於示例第一個局部最小值為0.35。 In one embodiment, the computer device uses the first local minimum of the similarity measure in the polyline relationship graph as the defect threshold. For example, as shown in FIG. 6 , the first local minimum value of the similarity measure in the line graph is 0.35, then the defect threshold is 0.35. It should be noted that the dotted line in FIG. 6 is only For example the first local minimum is 0.35.

步驟S7,電腦裝置比較每個文字對應的N個相似性度量中的每個相似性度量與所述瑕疵閾值的大小,當任一文字對應的任意一個相似性度量小於或等於所述瑕疵閾值時,執行步驟S8,當任一文字對應的任意一個相似性度量大於所述瑕疵閾值時,執行步驟S9。 Step S7, the computer device compares the size of each similarity measure in the N similarity measures corresponding to each character with the flaw threshold, and when any similarity measure corresponding to any character is less than or equal to the flaw threshold, Step S8 is performed, and when any similarity measure corresponding to any character is greater than the flaw threshold, step S9 is performed.

步驟S8,電腦裝置確定與所述任意一個相似性度量關聯的所述第五圖像對應的第四圖像為無瑕疵圖像。 Step S8, the computer device determines that the fourth image corresponding to the fifth image associated with any one of the similarity metrics is a flawless image.

舉例而言,文字“0”的第五圖像4C3與第三圖像4A2之間的歐式距離為0.23,小於所述瑕疵閾值0.35,電腦裝置可以將第四圖像4C1標記為無瑕疵圖像。 For example, the Euclidean distance between the fifth image 4C3 of the character "0" and the third image 4A2 is 0.23, which is smaller than the defect threshold of 0.35, and the computer device can mark the fourth image 4C1 as a defect-free image .

步驟S9,電腦裝置確定與所述任意一個相似性度量關聯的所述第五圖像對應的第四圖像為有瑕疵圖像;當任意一幅所述第四圖像被確定為為有瑕疵圖像時,從所述背景區中截取一幅背景圖像,所述截取的背景圖像的大小等於所述有瑕疵圖像的大小;及對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像。 Step S9, the computer device determines that the fourth image corresponding to the fifth image associated with any one of the similarity metrics is a defective image; when any one of the fourth images is determined to be defective When taking an image, a background image is intercepted from the background area, and the size of the intercepted background image is equal to the size of the defective image; A composite image is obtained from the flawed image and the background image after shading processing.

舉例而言,如圖5所示,文字“0”的第五圖像4B3與第三圖像4A2之間的歐式距離為0.76,大於所述瑕疵閾值0.35,電腦裝置可以將第四圖像4B1標記為有瑕疵圖像4B1。 For example, as shown in FIG. 5 , the Euclidean distance between the fifth image 4B3 of the character "0" and the third image 4A2 is 0.76, which is greater than the defect threshold of 0.35, and the computer device can convert the fourth image 4B1 Labeled as defective image 4B1.

在一個實施例中,由於所述文字區與所述背景區的明暗度可能會有些許不同,所以可以對背景圖像進行多次(例如,4次)明暗度的調整,以增加對環境光源的容錯性,獲得多幅經過明暗度調後的圖像(為清楚說明本發明,這裡將經過明暗度調整後的圖像稱為“調整圖像”);將該多幅調整圖像分別與所述有瑕疵圖像進行合成處理,獲得多幅合成圖像。例如圖7所示,電腦裝置從所述背景區中截取一幅和有瑕疵圖像4B1大小一致的背景圖像6A,對背景圖像6A進行4次明暗度的調整,將所述有瑕疵圖像4B1和經過每次明暗度處理後的所述背景圖像6A合成,獲得合成圖像6B、合成圖像6C、合成圖像6D、合成圖像6E。 In one embodiment, since the text area and the background area may have slightly different brightness, the background image may be adjusted for multiple times (for example, four times) to increase the exposure to ambient light sources. to obtain a plurality of shading-adjusted images (in order to clearly illustrate the present invention, the shading-adjusted images are referred to as “adjusted images” here); The defective images are synthesized to obtain a plurality of synthesized images. For example, as shown in FIG. 7 , the computer device intercepts a background image 6A with the same size as the defective image 4B1 from the background area, adjusts the brightness and darkness of the background image 6A four times, and converts the defective image The image 4B1 is combined with the background image 6A after each shading process to obtain a combined image 6B, a combined image 6C, a combined image 6D, and a combined image 6E.

在一個實施例中,可以利用所述合成圖像作為有瑕疵樣本訓練神經網路,獲得瑕疵檢測模型;在獲得任一文字的合成圖像後,可以重複步驟S5至步驟S9,以獲得該任一文字的較多的(例如,80個)有瑕疵樣本。 In one embodiment, the synthetic image may be used as a defective sample to train a neural network to obtain a defect detection model; after obtaining the synthetic image of any character, steps S5 to S9 may be repeated to obtain the any character more (eg, 80) defective samples.

在一個實施例中,當所述無瑕疵圖像中包含M個文字時,電腦裝置獲得每個文字的N幅第四圖像後,共獲得M*N幅第四圖像;電腦裝置確定M*N幅第四圖像中的K幅第四圖像為有瑕疵圖像,並從所述背景區中截取K幅與每幅所述有瑕疵圖像一一對應的背景圖像;電腦裝置對每幅圖像進行L次明暗度調整,再將每幅明暗度調整後的背景圖像和與之對應的有瑕疵圖像進行合成,獲得K*L幅合成圖像,其中,K是小於M*N的正整數,L是大於一的正整數。 In one embodiment, when the flawless image includes M characters, after the computer device obtains N fourth images of each character, a total of M*N fourth images are obtained; the computer device determines M *K fourth images among the N fourth images are defective images, and K background images corresponding to each of the defective images are cut out from the background area; computer device Perform L times of brightness adjustment on each image, and then synthesize the background image after each brightness adjustment and the corresponding defective image to obtain K*L composite images, where K is less than M*N is a positive integer, and L is a positive integer greater than one.

步驟S10,電腦裝置確定所述合成圖像的個數與預設的第二閾值的大小關係,當所述合成圖像的個數小於所述預設的第二閾值時,執行步驟S1;當所述合成圖像的個數大於或等於所述預設的第二閾值時,執行步驟S11。 In step S10, the computer device determines the magnitude relationship between the number of the composite images and the preset second threshold, and when the number of the composite images is less than the preset second threshold, step S1 is performed; When the number of the composite images is greater than or equal to the preset second threshold, step S11 is performed.

在一個實施例中,所述預設的第二閾值可以是100000。 In one embodiment, the preset second threshold may be 100,000.

步驟S11,電腦裝置利用所述合成圖像訓練神經網路,獲得瑕疵檢測模型。 In step S11, the computer device uses the synthesized image to train a neural network to obtain a defect detection model.

上述圖1詳細介紹了本申請的影像處理方法,下面結合圖2,對實現所述影像處理方法的硬體裝置架構進行介紹。 The above-mentioned FIG. 1 describes the image processing method of the present application in detail. The following describes the hardware device architecture for implementing the image processing method with reference to FIG. 2 .

應該瞭解,所述實施例僅為說明之用,在專利申請範圍上並不受此結構的限制。 It should be understood that the embodiments are only used for illustration, and are not limited by this structure in the scope of the patent application.

參閱圖2所示,為本申請較佳實施例提供的電腦裝置的結構示意圖。在本申請較佳實施例中,所述電腦裝置3包括儲存器31、至少一個處理器32。本領域技術人員應該瞭解,圖2示出的電腦裝置的結構並不構成本申請實施例的限定,既可以是匯流排型結構,也可以是星形結構,所述電腦裝置3還可以包括比圖示更多或更少的其他硬體或者軟體,或者不同的部件佈置。 Referring to FIG. 2 , it is a schematic structural diagram of a computer device according to a preferred embodiment of the present application. In a preferred embodiment of the present application, the computer device 3 includes a storage 31 and at least one processor 32 . Those skilled in the art should understand that the structure of the computer device shown in FIG. 2 does not constitute a limitation of the embodiments of the present application. More or less other hardware or software, or different component arrangements are shown.

在一些實施例中,所述電腦裝置3包括一種能夠按照事先設定或儲存的指令,自動進行數值計算和/或資訊處理的終端,其硬體包括但不限於微處理器、專用積體電路、可程式設計閘陣列、數位訊號處理器及嵌入式設備等。 In some embodiments, the computer device 3 includes a terminal capable of automatically performing numerical calculations and/or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, dedicated integrated circuits, Programmable gate arrays, digital signal processors and embedded devices, etc.

需要說明的是,所述電腦裝置3僅為舉例,其他現有的或今後可能出現的電子產品如可適應於本申請,也應包含在本申請的保護範圍以內,並以引用方式包含於此。 It should be noted that the computer device 3 is only an example, and other existing or future electronic products, if applicable to the present application, should also be included within the protection scope of the present application, and are incorporated herein by reference.

在一些實施例中,所述儲存器31用於儲存程式碼和各種資料。例如,所述儲存器31可以用於儲存無瑕疵圖像,還可以儲存安裝在所述電腦裝置3中的影像處理系統30,並在電腦裝置3的運行過程中實現高速、自動地完成程式或資料的存取。所述儲存器31包括唯讀記憶體(Read-Only Memory,ROM)、可程式設計唯讀記憶體(Programmable Read-Only Memory,PROM)、可抹除可程式設計唯讀記憶體(Erasable Programmable Read-Only Memory,EPROM)、一次可程式設計唯讀記憶體(One-time Programmable Read-Only Memory,OTPROM)、電子抹除式可複寫唯讀記憶體(Electrically-Erasable Programmable Read-Only Memory,EEPROM)、唯 讀光碟(Compact Disc Read-Only Memory,CD-ROM)或其他光碟儲存器、磁碟儲存器、磁帶儲存器、或者任何其他能夠用於攜帶或儲存資料的電腦可讀的儲存介質。 In some embodiments, the storage 31 is used to store code and various data. For example, the storage 31 can be used to store flawless images, and can also store the image processing system 30 installed in the computer device 3 , and can realize high-speed and automatic completion of programs or programs during the operation of the computer device 3 . access to data. The storage 31 includes a Read-Only Memory (ROM), a Programmable Read-Only Memory (PROM), an Erasable Programmable Read-Only Memory (Erasable Programmable Read Only Memory) -Only Memory, EPROM), One-time Programmable Read-Only Memory (OTPROM), Electronically-Erasable Programmable Read-Only Memory (EEPROM) ,only Compact Disc Read-Only Memory (CD-ROM) or other optical disk storage, magnetic disk storage, magnetic tape storage, or any other computer-readable storage medium that can be used to carry or store data.

在一些實施例中,所述至少一個處理器32可以由積體電路組成,例如可以由單個封裝的積體電路所組成,也可以是由多個相同功能或不同功能封裝的積體電路所組成,包括一個或者多個中央處理器(Central Processing unit,CPU)、微處理器、數位訊號處理晶片、圖形處理器及各種控制晶片的組合等。所述至少一個處理器32是所述電腦裝置3的控制核心(Control Unit),利用各種介面和線路連接整個電腦裝置3的各個部件,透過運行或執行儲存在所述儲存器31內的程式或者模組,以及調用儲存在所述儲存器31內的資料,以執行電腦裝置3的各種功能和處理資料,例如執行影像處理的功能。 In some embodiments, the at least one processor 32 may be composed of an integrated circuit, for example, may be composed of a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same function or different functions , including one or more central processing units (Central Processing Units, CPUs), microprocessors, digital signal processing chips, graphics processors and combinations of various control chips. The at least one processor 32 is the control core (Control Unit) of the computer device 3, and uses various interfaces and lines to connect the various components of the entire computer device 3, by running or executing the program stored in the storage 31 or module, and call the data stored in the storage 31 to execute various functions of the computer device 3 and process data, such as the function of image processing.

在一些實施例中,所述影像處理系統30運行於電腦裝置3中。所述影像處理系統30可以包括多個由程式碼段所組成的功能模組。所述影像處理系統30中的各個程式段的程式碼可以儲存於電腦裝置3的儲存器31中,並由至少一個處理器32所執行,以實現圖1所示的影像處理的功能。 In some embodiments, the image processing system 30 runs in the computer device 3 . The image processing system 30 may include a plurality of functional modules composed of program code segments. The code of each program segment in the image processing system 30 can be stored in the memory 31 of the computer device 3 and executed by at least one processor 32 to realize the image processing function shown in FIG. 1 .

本實施例中,所述影像處理系統30根據其所執行的功能,可以被劃分為多個功能模組。本申請所稱的模組是指一種能夠被至少一個處理器所執行並且能夠完成固定功能的一系列電腦程式段,其儲存在儲存器中。 In this embodiment, the image processing system 30 can be divided into a plurality of functional modules according to the functions performed by the image processing system 30 . The module referred to in this application refers to a series of computer program segments that can be executed by at least one processor and can perform fixed functions, and are stored in a memory.

儘管未示出,所述電腦裝置3還可以包括給各個部件供電的電源(比如電池),優選的,電源可以透過電源管理裝置與所述至少一個處理器32邏輯相連,從而透過電源管理裝置實現管理充電、放電、以及功耗管理等功能。電源還可以包括一個或一個以上的直流或交流電源、再充電裝置、電源故障檢測電路、電源轉換器或者逆變器、電源狀態指示器等任意元件。所述電腦裝置3還可以包括多種感測器、藍牙模組、Wi-Fi模組等, 在此不再贅述。 Although not shown, the computer device 3 may also include a power source (such as a battery) for supplying power to various components. Preferably, the power source may be logically connected to the at least one processor 32 through the power management device, so as to realize the realization through the power management device. Manage charging, discharging, and power management functions. The power supply may also include one or more of a DC or AC power source, a recharging device, a power failure detection circuit, a power converter or inverter, a power supply status indicator, or any other element. The computer device 3 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., It is not repeated here.

應該瞭解,所述實施例僅為說明之用,在專利申請範圍上並不受此結構的限制。 It should be understood that the embodiments are only used for illustration, and are not limited by this structure in the scope of the patent application.

上述以軟體功能模組的形式實現的集成的單元,可以儲存在一個電腦可讀取儲存介質中。上述軟體功能模組儲存在一個儲存介質中,包括若干指令用以使得一台電腦裝置(可以是伺服器、個人電腦等)或處理器(processor)執行本申請各個實施例所述方法的部分。 The above-mentioned integrated units implemented in the form of software function modules can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, and includes several instructions for causing a computer device (which may be a server, a personal computer, etc.) or a processor (processor) to execute parts of the methods described in the various embodiments of the present application.

在進一步的實施例中,結合圖2,所述至少一個處理器32可執行所述電腦裝置3的作業系統以及安裝的各類應用程式(如所述的影像處理系統30)、程式碼等,例如,上述的各個模組。 In a further embodiment, referring to FIG. 2 , the at least one processor 32 can execute the operating system of the computer device 3 and various installed application programs (such as the image processing system 30 ), program codes, etc., For example, the above-mentioned modules.

所述儲存器31中儲存有程式碼,且所述至少一個處理器32可調用所述儲存器31中儲存的程式碼以執行相關的功能。儲存在所述儲存器31中的程式碼可以由所述至少一個處理器32所執行,從而實現所述各個模組的功能以達到影像處理的目的。 The storage 31 stores program codes, and the at least one processor 32 can call the program codes stored in the storage 31 to execute related functions. The program codes stored in the storage 31 can be executed by the at least one processor 32, so as to realize the functions of the various modules to achieve the purpose of image processing.

在本申請的一個實施例中,所述儲存器31儲存一個或多個指令(即至少一個指令),所述至少一個指令被所述至少一個處理器32所執行以實現圖1所示的影像處理的目的。 In one embodiment of the present application, the storage 31 stores one or more instructions (ie, at least one instruction), and the at least one instruction is executed by the at least one processor 32 to realize the image shown in FIG. 1 . the purpose of processing.

在本申請所提供的幾個實施例中,應該理解到,所揭露的裝置和方法,可以透過其它的方式實現。例如,以上所描述的裝置實施例僅僅是示意性的,例如,所述模組的劃分,僅僅為一種邏輯功能劃分,實際實現時可以有另外的劃分方式。 In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and other division methods may be used in actual implementation.

所述作為分離部件說明的模組可以是或者也可以不是物理上分開的,作為模組顯示的部件可以是或者也可以不是物理單元,即可以位於一個地方,或者也可以分佈到多個網路單元上。可以根據實際的需要選擇其中的部分或者全部模組來實現本實施例方案的目的。 The modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical units, that is, they can be located in one place or distributed to multiple networks. on the unit. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution in this embodiment.

另外,在本申請各個實施例中的各功能模組可以集成在一個處理 單元中,也可以是各個單元單獨物理存在,也可以兩個或兩個以上單元集成在一個單元中。上述集成的單元既可以採用硬體的形式實現,也可以採用硬體加軟體功能模組的形式實現。 In addition, each functional module in each embodiment of the present application may be integrated in one processing In a unit, each unit may exist physically alone, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented in the form of hardware, or can be implemented in the form of hardware plus software function modules.

對於本領域技術人員而言,顯然本申請不限於上述示範性實施例的細節,而且在不背離本申請的精神或基本特徵的情況下,能夠以其他的具體形式實現本申請。因此,無論從哪一點來看,均應將實施例看作是示範性的,而且是非限制性的,本申請的範圍由所附請求項而不是上述說明限定,因此旨在將落在請求項的等同要件的含義和範圍內的所有變化涵括在本申請內。不應將請求項中的任何附圖標記視為限制所涉及的請求項。此外,顯然“包括”一詞不排除其他單元或,單數不排除複數。裝置請求項中陳述的多個單元或裝置也可以由一個單元或裝置透過軟體或者硬體來實現。第一,第二等詞語用來表示名稱,而並不表示任何特定的順序。 It will be apparent to those skilled in the art that the present application is not limited to the details of the above-described exemplary embodiments, but that the present application can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application. Accordingly, the embodiments are to be regarded in all respects as illustrative and not restrictive, and the scope of this application is defined by the appended claims rather than the foregoing description, and is therefore intended to fall within the scope of the claims. All changes within the meaning and scope of the equivalents of , are included in this application. Any reference sign in a claim should not be construed as limiting the claim to which it relates. Furthermore, it is clear that the word "comprising" does not exclude other units or, and the singular does not exclude the plural. Multiple units or means stated in the device claim may also be implemented by one unit or means through software or hardware. The terms first, second, etc. are used to denote names and do not denote any particular order.

最後所應說明的是,以上實施例僅用以說明本申請的技術方案而非限制,儘管參照以上較佳實施例對本申請進行了詳細說明,本領域的普通技術人員應當理解,可以對本申請的技術方案進行修改或等同替換,而不脫離本申請技術方案的精神和範圍。 Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application rather than limitations. Although the present application has been described in detail with reference to the above preferred embodiments, those of ordinary skill in the art should The technical solutions can be modified or equivalently replaced without departing from the spirit and scope of the technical solutions of the present application.

S1~S11:步驟 S1~S11: Steps

Claims (9)

一種影像處理方法,其中,所述方法包括:獲取無瑕疵圖像,確定所述無瑕疵圖像的文字區與背景區,並確定所述文字區中每個文字的位置;根據所述每個文字的位置對所述文字區進行分割,獲得每個文字的第一圖像;對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像;根據預設的第一影像處理方法處理所述每個文字的第二圖像,獲得每個文字的第三圖像,其中,所述第一影像處理方法包括圖像二值化、輪廓提取;根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和N幅第五圖像一一對應,N為大於1的正整數,其中,所述第二影像處理方法包括抹除處理、圖像二值化、輪廓提取;計算所述每個文字的N幅第五圖像中的每幅第五圖像與所述每個文字的第三圖像之間的相似性度量,獲得每個文字對應的N個相似性度量,並將所述每個文字的N幅第五圖像與所述每個文字對應的N個相似性度量分別建立關聯,根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值;比較每個文字對應的N個相似性度量中的每個相似性度量與所述瑕疵閾值的大小,其中,當任一文字對應的任意一個相似性度量大於所述瑕疵閾值時,確定與所述任意一個相似性度量關聯的第五圖像對應的第四圖像為有瑕疵圖像;當任意一幅第四圖像被確定為有瑕疵圖像時,從所述背景區中截取一幅背景圖像,所述截取的背景圖像的大小等於所述有瑕疵圖像的大小;及對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像。 An image processing method, wherein the method includes: acquiring a flawless image, determining a text area and a background area of the flawless image, and determining the position of each character in the text area; The position of the text divides the text area to obtain a first image of each text; removes the background from the first image of each text to obtain a second image of each text; An image processing method processes the second image of each character to obtain a third image of each character, wherein the first image processing method includes image binarization and contour extraction; The two-image processing method processes the second images of each character to obtain N fourth images and N fifth images of each character, and N fourth images and N images of each character The fifth images are in one-to-one correspondence, and N is a positive integer greater than 1, wherein the second image processing method includes erasing processing, image binarization, and contour extraction; calculating the N fifth images of each character The similarity measure between each fifth image in the image and the third image of each word, N similarity measures corresponding to each word are obtained, and the N pictures of each word The fifth image is respectively associated with the N similarity measures corresponding to each text, and a defect threshold is determined according to the N similarity measures corresponding to all the texts in the text area; the N corresponding to each text are compared. The size of each similarity measure in the similarity measure and the flaw threshold, wherein when any one of the similarity measures corresponding to any character is greater than the flaw threshold, determine the fifth similarity measure associated with the any one of the similarity measures The fourth image corresponding to the image is a defective image; when any fourth image is determined to be a defective image, a background image is intercepted from the background area, and the intercepted background image The size of the image is equal to the size of the flawed image; and performing shading processing on the intercepted background image, synthesizing the flawed image and the background image after shading processing to obtain a composite image . 如請求項1所述的影像處理方法,其中,所述對所述每個文字 的第一圖像去除背景,獲得每個文字的第二圖像包括方法一:利用大津演算法確定所述第一圖像的第一閾值,根據所述第一閾值獲取所述第一圖像的掩膜,並將所述掩膜與所述第一圖像進行按位元與運算,獲得所述第一圖像的前景文字圖像;及利用高斯模糊技術對所述前景文字圖像進行柔化邊緣處理,獲得所述第二圖像。 The image processing method according to claim 1, wherein each of the characters The background of the first image is removed, and the second image of each character is obtained by method 1: use the Otsu algorithm to determine the first threshold of the first image, and obtain the first image according to the first threshold. and perform a bitwise AND operation on the mask and the first image to obtain a foreground text image of the first image; Soft edges are processed to obtain the second image. 如請求項1所述的影像處理方法,其中,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法二:利用傅裡葉變換去除所述第一圖像中的網點,對去除網點後的所述第一圖像進行二值化;及利用高斯模糊技術對二值化後的所述第一圖像進行柔化邊緣處理,獲得所述第二圖像。 The image processing method according to claim 1, wherein removing the background from the first image of each character to obtain the second image of each character includes method 2: removing the background by using Fourier transform For the dots in the first image, binarize the first image after removing the dots; and use Gaussian blur technology to soften the edge of the binarized first image to obtain the second image. 如請求項2所述的影像處理方法,其中,所述第一影像處理方法以及所述第二影像處理方法根據所述第一閾值進行圖像二值化,以及利用傅裡葉描述子演算法或不變矩演算法進行輪廓提取。 The image processing method according to claim 2, wherein the first image processing method and the second image processing method perform image binarization according to the first threshold, and use a Fourier descriptor algorithm Or invariant moment algorithm for contour extraction. 如請求項1所述的影像處理方法,其中,所述根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和所述N幅第五圖像一一對應,包括:對所述每個文字的第二圖像進行N次隨機抹除,獲得所述每個文字的N幅第四圖像;對所述每個文字的N幅第四圖像執行圖像二值化,獲得N幅黑白圖像;對所述N幅黑白圖像進行輪廓提取,獲得所述N幅第五圖像。 The image processing method according to claim 1, wherein the second image of each character is processed according to a preset second image processing method to obtain N fourth images and N images of each character The fifth image, the N fourth images of each character and the N fifth images are in one-to-one correspondence, including: randomly erasing the second image of each character N times, obtaining N fourth images of each character; performing image binarization on the N fourth images of each character to obtain N black-and-white images; performing image binarization on the N black-and-white images Contour extraction is performed to obtain the N fifth images. 如據請求項1所述的影像處理方法,其中,所述相似性度量是指所述每個文字的每幅第五圖像與所述每個文字的第三圖像之間的歐氏距離; 其中,所述根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值包括:根據每個所述相似性度量的值對應的所述第五圖像的圖像個數,製作所述相似性度量與所述圖像個數的折線關係圖;及將所述折線關係圖中所述相似性度量的第一個局部最小值作為所述瑕疵閾值。 The image processing method according to claim 1, wherein the similarity measure refers to the Euclidean distance between each fifth image of each character and the third image of each character ; Wherein, determining a defect threshold according to the N similarity measures corresponding to all the characters in the text area includes: the number of images of the fifth image corresponding to the value of each similarity measure, Making a polyline relationship graph of the similarity measure and the number of images; and taking the first local minimum value of the similarity measure in the polyline relationship map as the defect threshold. 如請求項1所述的影像處理方法,其中,所述對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像包括:對所截取的背景圖像進行多次明暗度調整,獲得多幅調整圖像,將所述多幅調整圖像分別與所述有瑕疵圖像進行合成處理,獲得多幅合成圖像。 The image processing method according to claim 1, wherein the intercepted background image is subjected to shading processing, and the defective image and the background image after shading processing are synthesized to obtain a composite image The image includes: performing multiple brightness adjustment on the intercepted background image to obtain multiple adjusted images, and synthesizing the multiple adjusted images with the defective image respectively to obtain multiple synthesized images . 一種電腦可讀儲存介質,其中,所述電腦可讀儲存介質儲存有至少一個指令,所述至少一個指令被處理器執行時實現如請求項1至7中任意一項所述的影像處理方法。 A computer-readable storage medium, wherein the computer-readable storage medium stores at least one instruction, and when the at least one instruction is executed by a processor, implements the image processing method according to any one of claim 1 to 7. 一種電腦裝置,其中,所述電腦裝置包括儲存器和至少一個處理器,所述儲存器中儲存有至少一個指令,所述至少一個指令被所述至少一個處理器執行時實現如請求項1至7中任意一項所述的影像處理方法。 A computer device, wherein the computer device includes a memory and at least one processor, the memory stores at least one instruction, and when the at least one instruction is executed by the at least one processor, the implementation of claim 1 to The image processing method according to any one of 7.
TW110128607A 2021-08-03 2021-08-03 Image processing method, computer device, and storage medium TWI778735B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
TW110128607A TWI778735B (en) 2021-08-03 2021-08-03 Image processing method, computer device, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
TW110128607A TWI778735B (en) 2021-08-03 2021-08-03 Image processing method, computer device, and storage medium

Publications (2)

Publication Number Publication Date
TWI778735B true TWI778735B (en) 2022-09-21
TW202307729A TW202307729A (en) 2023-02-16

Family

ID=84958185

Family Applications (1)

Application Number Title Priority Date Filing Date
TW110128607A TWI778735B (en) 2021-08-03 2021-08-03 Image processing method, computer device, and storage medium

Country Status (1)

Country Link
TW (1) TWI778735B (en)

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
期刊 Kitada, Shunsuke, Ryunosuke Kotani, and Hitoshi Iyatomi. "End-to-end text classification via image-based embedding using character-level networks." 2018 IEEE Applied Imagery Pattern Recognition Workshop (AIPR). 2018 IEEE 2018 pages1-4; *
期刊 Rehman, Arshia, Saeeda Naz, and Muhammad Imran Razzak. "Writer identification using machine learning approaches: a comprehensive review."Multimedia Tools and Applications 78.8 (2019) Springer 2019 pages10889-10931 *

Also Published As

Publication number Publication date
TW202307729A (en) 2023-02-16

Similar Documents

Publication Publication Date Title
CN107067003B (en) Region-of-interest boundary extraction method, device, equipment and computer storage medium
US20190139213A1 (en) Data generation apparatus, data generation method, and data generation program
CN111340796B (en) Defect detection method and device, electronic equipment and storage medium
CN114461986A (en) Method for training identification model and method and device for image identification
CN113490947A (en) Detection model training method and device, detection model using method and storage medium
TW202225682A (en) Circuit board checking method, electronic device, and storage medium
CN113836850A (en) Model obtaining method, system and device, medium and product defect detection method
CN114241432A (en) License plate recognition method, equipment and storage medium
CN112232354A (en) Character recognition method, device, equipment and storage medium
CN109508714B (en) Low-cost multi-channel real-time digital instrument panel visual identification method and system
TWI778735B (en) Image processing method, computer device, and storage medium
CN117173223A (en) Standard template generation method, device, equipment and medium for ammeter code-breaking screen
Wang et al. Insulator defect detection based on improved YOLOv5 algorithm
CN115546219A (en) Detection board type generation method, board card defect detection method, device and product
CN114841980A (en) Insulator defect detection method and system based on line patrol aerial image
CN111950356B (en) Seal text positioning method and device and electronic equipment
CN115705728A (en) Image processing method, computer device and storage medium
CN112861861A (en) Method and device for identifying nixie tube text and electronic equipment
CN110740231A (en) Video data labeling method and device, electronic equipment and medium
TWI786838B (en) Printing defect detection method, computer device, and storage medium
TWI807426B (en) Literal image defect detection method, computer device, and storage medium
CN117372510B (en) Map annotation identification method, terminal and medium based on computer vision model
US20230086131A1 (en) Text image defect detection method, computer device, and storage medium
TWI786837B (en) Text defect detection method, computer device, and storage medium
TWI770561B (en) Product defect detection method, computer device and storage medium

Legal Events

Date Code Title Description
GD4A Issue of patent certificate for granted invention patent