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

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

Info

Publication number
TW202307729A
TW202307729A TW110128607A TW110128607A TW202307729A TW 202307729 A TW202307729 A TW 202307729A TW 110128607 A TW110128607 A TW 110128607A TW 110128607 A TW110128607 A TW 110128607A TW 202307729 A TW202307729 A TW 202307729A
Authority
TW
Taiwan
Prior art keywords
image
character
images
processing method
background
Prior art date
Application number
TW110128607A
Other languages
Chinese (zh)
Other versions
TWI778735B (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

  • Processing Or Creating Images (AREA)
  • Image Analysis (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 invention relates to the field of image processing, 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 artificially synthesizing flawed samples requires manually marking the flawed data after generating the simulated data, or training another deep learning model to classify, which consumes a lot of manpower and time, and manual marking Errors and omissions are also prone to occur in the process. How to efficiently solve the problem of insufficient training data on 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 printed 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 character area and a background area of the flawless image, and determining the position of each character in the character area; Segment the text area to obtain the first image of each text; remove the background from the first image of each text to obtain the second image of each text; process according to the preset first image processing method The second image of each character is obtained by obtaining the third image of each character; the second image of each character is processed according to the preset second image processing method to obtain N pieces of the first image of each character Four images and N fifth images, the N fourth images of each character are in one-to-one correspondence with the N fifth images, and N is a positive integer greater than 1; calculate each character The similarity measures between each fifth image in the N fifth images and the third image of each character are obtained, and N similarity measures corresponding to each character are obtained, and each character N pieces of the fifth image are respectively associated with the N similarity measures corresponding to each character, and a flaw threshold is determined according to the N similarity measures corresponding to all characters in the character area; compare the corresponding The size of each similarity measure in the N similarity measures and the defect threshold, wherein, when any similarity measure corresponding to any text is greater than the defect threshold, it is determined to be associated with the arbitrary similarity measure The fourth image corresponding to the fifth image is a flawed image; when any one of the fourth images is determined to be a flawed image, a background image is intercepted from the background area, and the interception The size of the background 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 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 The first threshold obtains a mask of the first image, and performs 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 performing softening and edge processing on the foreground character image by using a Gaussian blur technique.

可選地,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法二:利用傅裡葉變換去除所述第一圖像中的網點,對去除網點後的所述第一圖像進行二值化;及利用高斯模糊技術對二值化後的所述第一圖像進行柔化邊緣處理,獲得所述第二圖像。Optionally, removing the background from the first image of each character, and obtaining the second image of each character includes method two: using Fourier transform to remove the dots in the first image, and performing binarization on the first image after removing the dots; and performing edge softening processing on the binarized first image by using a Gaussian blur technique 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 use Fourier descriptor algorithm or invariant moment algorithm to perform contour extraction .

可選地,所述根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的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, and each The N fourth images of the characters are in one-to-one correspondence with the N fifth images, including: performing N times of random erasing on the second images of each character to obtain N fourth images of each character. image; performing image binarization on the N fourth images of each character to obtain N black and white images; performing 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; wherein, according to the character region Determining a blemish threshold for N similarity measures corresponding to all the characters respectively includes: according to the number of images of the fifth image corresponding to each value of the similarity measure, making the similarity measure and the a line relationship diagram of the number of images; and using the first local minimum value of the similarity measure in the line relationship diagram as the blemish threshold.

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

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

所述電腦裝置包括儲存器和至少一個處理器,所述儲存器中儲存有至少一個指令,所述至少一個指令被所述至少一個處理器執行時實現所述影像處理方法。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 conventional technology, the image processing method, computer device and storage medium can automatically generate a large number of defective printed images, and can automatically mark the training samples without training an additional deep learning model, reducing the The cost of artificial synthesis and labelling.

為了能夠更清楚地理解本申請的上述目的、特徵和優點,下面結合附圖和具體實施例對本申請進行詳細描述。需要說明的是,在不衝突的情況下,本申請的實施例及實施例中的特徵可以相互組合。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 in conjunction with the accompanying drawings and specific embodiments. It should be noted that, in the case of no conflict, the embodiments of the present application and the features in the embodiments can be combined with each other.

在下面的描述中闡述了很多具體細節以便於充分理解本申請,所描述的實施例僅僅是本申請一部分實施例,而不是全部的實施例。基於本申請中的實施例,本領域普通技術人員在沒有做出創造性勞動前提下所獲得的所有其他實施例,都屬於本申請保護的範圍。A lot of specific details are set forth in the following description to facilitate a full understanding of the application, and the described embodiments are only a part of the embodiments of the application, rather than all the embodiments. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without making creative efforts belong to the scope of protection of this 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. The terms used herein in the specification of the application are only for the purpose of describing specific embodiments, and are not intended to limit the application.

參閱圖1所示,為本申請較佳實施例的影像處理方法的流程圖。Referring to FIG. 1 , it is a flowchart of an image processing method in 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 (such as the computer device 3 shown in FIG. 2 ). For a computer device that needs to perform image processing, the computer device can directly integrate the method described in this application. The functions provided 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 flow chart can be changed, and some steps can be omitted.

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

在一個實施例中,電腦裝置可以回應用戶輸入獲取一幅無瑕疵圖像。所述無瑕疵圖像還可以預先儲存在電腦裝置的儲存器中,或者預先儲存在與電腦裝置通訊連接的其他設備中。本實施例中,所述無瑕疵圖像可以是工廠生產的印刷品的標準樣本(Golden Sample)圖像,所述無瑕疵圖像中包含文字(例如,漢字、數位、英文字母等)。需要說明的是,標準樣本圖像的位置不需要校正,其中文字的排列方向也不需要校正。In one embodiment, the computerized device may capture a flawless image in response to user input. The flawless image can also be pre-stored in the storage of the computer device, or in other devices connected in communication with the computer device. In this embodiment, the defect-free image may be a standard sample (Golden Sample) image of a printed matter produced by a factory, and the defect-free image includes text (for example, 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 (Optical Character Recognition, OCR) technology to recognize the text of the flawless image, and then confirm the text area and the background area of the flawless image, and determine the Describe the position of each text in the text area. The text area refers to the area containing the text, and the computer device can use the region of interest (Region Of Interest, ROI) technology to outline the text area, such as shown in Figure 3, along the direction of the text arrangement with the surrounding large rectangles 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 shaded area shown in FIG. 3 .

步驟S2,電腦裝置根據所述每個文字的位置對所述文字區進行分割,獲得每個文字的第一圖像。Step S2, the computer device divides the character area according to the position of each character, and obtains the 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, and the text of each text. The first image contains an image of the full text outline of the text. For example, the large rectangular frame (solid line) in Figure 3 can be segmented, and the rectangular image of the area where the text "0" is located can be segmented according to the small rectangular frame (solid line) in Figure 3, as shown in Figure 4 In the first image 3B1 of the text "0" shown in , 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 from 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, and obtaining the second image of each character includes Method 1: a computer device uses Otsu algorithm (OTSU Thresholding) to determine the first The first threshold of the image, obtaining the mask (mask) of the first image according to the first threshold, and performing a bitwise AND (Bitwise AND) operation on the mask and the first image , obtaining a foreground text image of the first image; and performing Soft Edge processing on the foreground text image by using a Gaussian Blur technique (Gaussian Blur), to obtain the second image.

在一個實施例中,所述方法一適用於背景複雜度較低的所述第一圖像的,例如,所述第一圖像為絲網印刷(Silk Screen Process Printing)圖像。所述大津演算法可以確定所述第一圖像的所述第一閾值,所述第一閾值包括所述第一圖像的圖像二值化(Thresholding)最佳分割閾值(例如,30);並按照所述第一閾值對所述第一圖像進行二值化,獲得所述第一圖像的所述掩膜。例如圖4中,利用大津演算法獲得第一圖像3B1的掩膜圖像3B2。In one embodiment, the first method is applicable to the first image with a relatively low background complexity, for example, the first image is a silk screen process 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 performing binarization on 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 can separate the foreground text outline image in the first image from the background that does not contain the text outline, so as to obtain the foreground text image and the background of the first image image, 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, Gaussian blur technology can be used to soften the edges, and the obtained first The second image is shown as the second image 3B5 in FIG. 4 .

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

在一個實施例中,所述方法二適用於含有網點(例如,方形網點、圓形網點等)的背景複雜度較高的所述第一圖像,例如,所述第一圖像為套色印刷圖像。所述傅裡葉變換可以改變所述第一圖像的頻率(Frequency),從而達到去除網點的效果;對去除網點後的所述第一圖像進行的所述二值化可以是所述方法一中的所述大津演算法;所述高斯模糊技術與所述方法一中所使用的技術相同。In one embodiment, the second method is suitable for the first image with a relatively complex background containing screen dots (for example, square screen dots, circular screen dots, etc.), for example, the first image is process printing image. The Fourier transform can change the frequency (Frequency) of the first image, so as to achieve the effect of removing dots; the binarization of the first image after removing dots can be the method The Otsu algorithm in method one; the Gaussian blur 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 a 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 Threshold, binarize the primitive at any position to 255; when the primitive value at any position in the second image is less than the first threshold, turn the image at any position Element binarized to 0. For example, as shown in FIG. 5 , an image 4A1 is obtained after image binarization is performed on the second image 3B5 .

在一個實施例中,電腦裝置利用傅裡葉描述子(Fourier Descriptors)演算法或不變矩(Invariant Moments)演算法,對圖像二值化後的所述第二圖像中的文字進行輪廓提取;所述傅裡葉描述子演算法可以識別圖像二值化後的所述第二圖像中文字輪廓的閉合邊緣,並對其進行重建,從而提取所述文字輪廓;所述不變矩演算法利用平移不變形、比例不變性和旋轉不變性等性質,描述圖像二值化後的所述第二圖像的整體特徵,從而提取圖像二值化後的所述第二圖像中的文字輪廓。例如圖5所示,對圖像4A1進行輪廓提取後得到文字“0”的第三圖像4A2。需要說明的是,所述無瑕疵圖像中每個文字都有與之一一對應的第三圖像,當所述無瑕疵圖像中包含M個文字時,共獲得M幅所述第三圖像,其中M表示大於0的正整數。In one embodiment, the computer device uses the Fourier Descriptors algorithm or the Invariant Moments algorithm to outline the text in the second image after image binarization Extraction; the Fourier descriptor algorithm can identify the closed edge of the character contour in the second image after image binarization, and reconstruct it, thereby extracting the character contour; the invariant The moment algorithm uses properties such as translation invariance, scale invariance, and rotation invariance to describe the overall characteristics of the second image after image binarization, thereby extracting the second image after image binarization The outline of the text in the image. For example, as shown in FIG. 5 , the third image 4A2 of the character “0” is obtained after contour extraction is performed on the image 4A1 . 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, and each character N pieces of fourth images correspond to N pieces of fifth images one by one, 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 can use an image erasing tool (for example, an eraser tool in Photoshop) to perform N times of random erasing on the second image of each character to obtain N frames of each character For the fourth image, as shown in Figure 5, for example, after the second image 3B5 of the word "0" is randomly erased twice, two fourth images of the word "0" are obtained: the fourth image 4B1 and the second image 4B1. 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 , an image 4B2 is obtained after image binarization is performed on the fourth image 4B1 , and an 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, the contour extraction is the same as the method used in step S4, as shown in Figure 5, for example, The fifth image 4B3 of the character "0" is obtained after the contour extraction of the image 4B2; the fifth image 4C3 of the character "0" is obtained after the contour extraction of the image 4C2.

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

步驟S6,電腦裝置計算所述每個文字的N幅第五圖像中的每幅第五圖像與所述每個文字的第三圖像之間的相似性度量(Similarity Measurement),獲得每個文字對應的N個相似性度量,並將每個文字的N幅第五圖像與所述每個文字對應的N個相似性度量分別建立關聯,根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值。Step S6, the computer device calculates the similarity measurement (Similarity Measurement) between each of the N fifth images of each character and the third image of each character, and obtains N similarity measures corresponding to each character, and the N fifth images of each character are respectively associated with the N similarity measures corresponding to each character, according to the corresponding values of all characters in the character area N similarity measures determine a blemish 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 a 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 fifth image of each character and the third image of each character, thereby obtaining each fifth image of each character The value of the corresponding similarity measure. For example, as shown in FIG. 5, for the character "0" having two fifth images, the Euclidean distance between the fifth image 4B3 of the character "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 obtaining N fourth images of each character, a total of M*N fourth images of all characters are obtained, and the M*N fifth images, and then obtain M*N similarity measure values.

在一個實施例中,所述根據所述文字區的所有文字分別對應的N個相似性度量確定一個瑕疵閾值包括:根據每個所述相似性度量的值對應的所述第五圖像的圖像個數,製作所述相似性度量與所述圖像個數的折線關係圖。In one embodiment, the determining a blemish threshold according to the N similarity measures corresponding to all the characters in the text area includes: according to the image of the fifth image corresponding to each value of the similarity measure As for the number of images, a broken-line relationship graph of 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 the computer device obtains the values of M*N similarity measures, it will count the number of fifth images corresponding to the value of each similarity measure. number, and taking the similarity measure as the horizontal axis, and the number of the fifth image as the vertical axis, to make the broken line relationship diagram. For example, the number of the fifth image corresponding to the value of the similarity measure 0.01 is 36, the number of the fifth image corresponding to the value of the similarity measure 0.35 is 0, and the value of the similarity measure is 0.82 The number of corresponding fifth images is 52, etc., and the obtained broken-line relationship diagram is shown in FIG. 6 .

在一個實施例中,電腦裝置將所述折線關係圖中所述相似性度量的第一個局部最小值(Local Minimum)作為所述瑕疵閾值。舉例而言,如圖6所示,所述折線關係圖中所述相似性度量的第一個局部最小值為0.35,那麼所述瑕疵閾值為0.35,需要說明的是,圖6中的虛線僅用於示例第一個局部最小值為0.35。In one embodiment, the computer device uses the first local minimum value (Local Minimum) of the similarity measure in the broken line graph as the flaw threshold. For example, as shown in FIG. 6, the first local minimum value of the similarity measure in the broken-line relationship diagram 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 each of the N similarity measures corresponding to each character with the defect threshold, and when any similarity measure corresponding to any character is less than or equal to the defect threshold, Step S8 is executed, and when any similarity measure corresponding to any character is greater than the blemish threshold, step S9 is executed.

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

舉例而言,文字“0”的第五圖像4C3與第三圖像4A2之間的歐式距離為0.23,小於所述瑕疵閾值0.35,電腦裝置可以將第四圖像4C1標記為無瑕疵圖像。For example, the Euclidean distance between the fifth image 4C3 of the word "0" and the third image 4A2 is 0.23, which is smaller than the blemish threshold 0.35, and the computer device can mark the fourth image 4C1 as a blemish-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 measures is a flawed image; when any one of the fourth images is determined to be flawed When drawing an image, intercept a background image from the background area, the size of the intercepted background image is equal to the size of the defective image; and perform shading processing on the intercepted background image, and synthesize The flawed image and the background image after shading processing are used to obtain a composite image.

舉例而言,如圖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 word "0" and the third image 4A2 is 0.76, which is greater than the blemish threshold of 0.35, and the computer device can convert the fourth image 4B1 Labeled as flawed image 4B1.

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

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

在一個實施例中,當所述無瑕疵圖像中包含M個文字時,電腦裝置獲得每個文字的N幅第四圖像後,共獲得M*N幅第四圖像;電腦裝置確定M*N幅第四圖像中的K幅第四圖像為有瑕疵圖像,並從所述背景區中截取K幅與每幅所述有瑕疵圖像一一對應的背景圖像;電腦裝置對每幅圖像進行L次明暗度調整,再將每幅明暗度調整後的背景圖像和與之對應的有瑕疵圖像進行合成,獲得K*L幅合成圖像,其中,K是小於M*N的正整數,L是大於一的正整數。In one embodiment, when the defect-free image contains 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 in the N fourth images are flawed images, and K background images corresponding to each of the flawed images are intercepted from the background area; computer device Perform L times of shading adjustment on each image, and then synthesize each shading-adjusted background image and the corresponding defective image to obtain K*L synthetic images, where K is less than A positive integer of M*N, L is a positive integer greater than one.

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

在一個實施例中,所述預設的第二閾值可以是100000。In an 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 introduces the image processing method of the present application in detail. The hardware device architecture for implementing the image processing method will be introduced below in conjunction with FIG. 2 .

應該瞭解,所述實施例僅為說明之用,在專利申請範圍上並不受此結構的限制。It should be understood that the embodiments are only for illustration, and are not limited by the structure in terms of 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 provided by 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 Figure 2 does not constitute a limitation of the embodiment of the present application, it can be a bus-type structure or a star structure, and the computer device 3 can also include a ratio More or less other hardware or software, or different arrangements of components are illustrated.

在一些實施例中,所述電腦裝置3包括一種能夠按照事先設定或儲存的指令,自動進行數值計算和/或資訊處理的終端,其硬體包括但不限於微處理器、專用積體電路、可程式設計閘陣列、數位訊號處理器及嵌入式設備等。In some embodiments, the computer device 3 includes a terminal capable of automatically performing numerical calculations and/or information processing according to preset or stored instructions, and its hardware includes but 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 that can be adapted to this application should also be included in the scope of protection of this application and included here 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 program codes 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 realize high-speed, automatic completion of programs or access to data. The storage 31 includes a read-only memory (Read-Only Memory, ROM), a programmable read-only memory (Programmable Read-Only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read -Only Memory, EPROM), One-time Programmable Read-Only Memory (OTPROM), Electrically-Erasable Programmable Read-Only Memory (EEPROM) , CD-ROM (Compact Disc Read-Only Memory, CD-ROM) or other optical disk storage, disk storage, 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 multiple integrated circuits with the same function or different functions. , including one or more central processing units (Central Processing unit, CPU), 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, which connects various components of the entire computer device 3 through various interfaces and lines, and runs or executes programs stored in the memory 31 or module, and call the data stored in the memory 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 on the computer device 3 . The image processing system 30 may include a plurality of functional modules composed of program code segments. The program codes 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 functions shown in FIG. 1 .

本實施例中,所述影像處理系統30根據其所執行的功能,可以被劃分為多個功能模組。本申請所稱的模組是指一種能夠被至少一個處理器所執行並且能夠完成固定功能的一系列電腦程式段,其儲存在儲存器中。In this embodiment, the image processing system 30 can be divided into multiple functional modules according to the functions it performs. 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 complete 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 supply (such as a battery) for supplying power to each component. Preferably, the power supply may be logically connected to the at least one processor 32 through a power management device, thereby realizing Manage functions such as charging, discharging, and power management. The power supply may also include one or more DC or AC power sources, recharging devices, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components. The computer device 3 may also include various sensors, Bluetooth modules, Wi-Fi modules, etc., which will not be repeated here.

應該瞭解,所述實施例僅為說明之用,在專利申請範圍上並不受此結構的限制。It should be understood that the embodiments are only for illustration, and are not limited by the structure in terms of 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 enabling a computer device (which may be a server, a personal computer, etc.) or a processor (processor) to execute part of the method described in each embodiment 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 applications (such as the image processing system 30), program codes, etc., For example, the various modules mentioned above.

所述儲存器31中儲存有程式碼,且所述至少一個處理器32可調用所述儲存器31中儲存的程式碼以執行相關的功能。儲存在所述儲存器31中的程式碼可以由所述至少一個處理器32所執行,從而實現所述各個模組的功能以達到影像處理的目的。Program codes are stored in the storage 31 , 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 memory 31 can be executed by the at least one processor 32 to implement 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 (that is, 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 Purpose of processing.

在本申請所提供的幾個實施例中,應該理解到,所揭露的裝置和方法,可以透過其它的方式實現。例如,以上所描述的裝置實施例僅僅是示意性的,例如,所述模組的劃分,僅僅為一種邏輯功能劃分,實際實現時可以有另外的劃分方式。In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the division of the modules is only a logical function division, and there may be other division methods 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 may be located in one place, or may also be distributed to multiple networks on the unit. Part or all of the modules can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

另外,在本申請各個實施例中的各功能模組可以集成在一個處理單元中,也可以是各個單元單獨物理存在,也可以兩個或兩個以上單元集成在一個單元中。上述集成的單元既可以採用硬體的形式實現,也可以採用硬體加軟體功能模組的形式實現。In addition, each functional module in each embodiment of the present application may be integrated into one processing unit, each unit may exist separately physically, or two or more units may be integrated into one unit. The above-mentioned integrated units can be implemented not only in the form of hardware, but also 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 exemplary embodiments described above, but that the present application can be implemented in other specific forms without departing from the spirit or essential characteristics of the present application. Therefore, no matter from any point of view, the embodiments should be regarded as exemplary and non-restrictive, and the scope of the application is defined by the appended claims rather than the above description, so it is intended to All changes within the meaning and range of equivalents of the elements are embraced 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 elements or the singular does not exclude the plural. A plurality of units or devices stated in the device claim may also be implemented by one unit or device through software or hardware. The words first, second, etc. are used to denote names and do not imply any particular order.

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

3:電腦裝置 30:影像處理系統 31:儲存器 32:處理器 S1~S11:步驟 3: Computer device 30: Image processing system 31: Storage 32: Processor 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 accompanying drawings that need to be used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the accompanying drawings in the following description are only It is an embodiment of the present application, and those skilled in the art can also obtain other drawings according to the provided drawings without creative work.

圖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 the embodiment of the present application.

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

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

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

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

S1~S11:步驟 S1~S11: Steps

Claims (10)

一種影像處理方法,其中,所述方法包括: 獲取無瑕疵圖像,確定所述無瑕疵圖像的文字區與背景區,並確定所述文字區中每個文字的位置; 根據所述每個文字的位置對所述文字區進行分割,獲得每個文字的第一圖像; 對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像; 根據預設的第一影像處理方法處理所述每個文字的第二圖像,獲得每個文字的第三圖像; 根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的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; Segmenting the character area according to the position of each character to obtain a first image of each character; removing the background from the first image of each character to obtain a second image of each character; processing the second image of each character according to a preset first image processing method to obtain a third image of each character; According to the preset second image processing method, the second image of each character is processed to obtain N fourth images and N fifth images of each character, and the N fourth images of each character The image is in one-to-one correspondence with N fifth images, and N is a positive integer greater than 1; Calculate the similarity measure between each fifth image in the N fifth images of each character and the third image of each character, and obtain N similarity measures corresponding to each character , and the N fifth images of each character are respectively associated with the N similarity measures corresponding to each character, and one is determined according to the N similarity measures corresponding to all characters in the character area blemish threshold; Comparing the size of each similarity measure in the N similarity measures corresponding to each character with the defect threshold, wherein, when any similarity measure corresponding to any character is greater than the defect threshold, it is determined that it is different from the defect threshold. The fourth image corresponding to the fifth image associated with a similarity measure is a flawed image; When any one of the fourth images is determined to be a defective image, intercepting a background image from the background area, the size of the intercepted background image is equal to the size of the defective 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 the first image processing method includes image binarization and contour extraction; the second image processing method includes erasure processing, image binarization, and contour extraction . 如請求項2所述的影像處理方法,其中,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法一: 利用大津演算法確定所述第一圖像的第一閾值,根據所述第一閾值獲取所述第一圖像的掩膜,並將所述掩膜與所述第一圖像進行按位元與運算,獲得所述第一圖像的前景文字圖像;及 利用高斯模糊技術對所述前景文字圖像進行柔化邊緣處理,獲得所述第二圖像。 The image processing method according to claim 2, wherein 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 a first threshold of the first image, obtain a mask of the first image according to the first threshold, and perform a bit-by-bit comparison of the mask and the first image AND operation to obtain the foreground text image of the first image; and The second image is obtained by performing softening and edge processing on the foreground character image by using a Gaussian blur technique. 如請求項2所述的影像處理方法,其中,所述對所述每個文字的第一圖像去除背景,獲得每個文字的第二圖像包括方法二: 利用傅裡葉變換去除所述第一圖像中的網點,對去除網點後的所述第一圖像進行二值化;及 利用高斯模糊技術對二值化後的所述第一圖像進行柔化邊緣處理,獲得所述第二圖像。 The image processing method according to claim 2, wherein removing the background from the first image of each character and obtaining the second image of each character includes method two: Using Fourier transform to remove the dots in the first image, and binarize the first image after the dots are removed; and The second image is obtained by performing edge softening processing on the binarized first image by using a Gaussian blur technique. 如請求項3所述的影像處理方法,其中,所述第一影像處理方法以及所述第二影像處理方法根據所述第一閾值進行圖像二值化,以及利用傅裡葉描述子演算法或不變矩演算法進行輪廓提取。The image processing method according to claim 3, wherein the first image processing method and the second image processing method perform image binarization according to the first threshold, and use the Fourier descriptor algorithm Or invariant moment algorithm for contour extraction. 如請求項2所述的影像處理方法,其中,所述根據預設的第二影像處理方法處理所述每個文字的第二圖像,獲得每個文字的N幅第四圖像和N幅第五圖像,所述每個文字的N幅第四圖像和所述N幅第五圖像一一對應,包括: 對所述每個文字的第二圖像進行N次隨機抹除,獲得所述每個文字的N幅第四圖像; 對所述每個文字的N幅第四圖像執行圖像二值化,獲得N幅黑白圖像; 對所述N幅黑白圖像進行輪廓提取,獲得所述N幅第五圖像。 The image processing method according to claim 2, wherein, according to the preset second image processing method, the second image of each character is processed to obtain N fourth images and N fourth images of each character The fifth image, the N fourth images of each character correspond one-to-one to the N fifth images, including: Perform N times of random erasing on the second image of each character to obtain N fourth images of each character; Perform image binarization on the N fourth images of each character to obtain N black and white images; Contour extraction is performed on the N pieces of black and white images to obtain the N pieces of 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, said determining a defect threshold according to the N similarity measures corresponding to all the characters in the text area includes: According to the number of images of the fifth image corresponding to each value of the similarity measure, make a broken-line relationship diagram between the similarity measure and the number of images; and The first local minimum value of the similarity measure in the broken-line relationship graph is used as the flaw threshold. 如請求項1所述的影像處理方法,其中,所述對所截取的背景圖像進行明暗度處理,合成所述有瑕疵圖像和經過明暗度處理後的所述背景圖像,獲得合成圖像包括: 對所截取的背景圖像進行多次明暗度調整,獲得多幅調整圖像,將所述多幅調整圖像分別與所述有瑕疵圖像進行合成處理,獲得多幅合成圖像。 The image processing method according to claim 1, wherein the intercepted background image is subjected to shading processing, and the flawed image and the background image after shading processing are synthesized to obtain a composite image Like include: Perform multiple lightness adjustments on the intercepted background image to obtain multiple adjusted images, and perform composite processing on the multiple adjusted images and the defective image respectively to obtain multiple composite images. 一種電腦可讀儲存介質,其中,所述電腦可讀儲存介質儲存有至少一個指令,所述至少一個指令被處理器執行時實現如請求項1至8中任意一項所述的影像處理方法。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, the image processing method according to any one of claims 1 to 8 is realized. 一種電腦裝置,其中,所述電腦裝置包括儲存器和至少一個處理器,所述儲存器中儲存有至少一個指令,所述至少一個指令被所述至少一個處理器執行時實現如請求項1至8中任意一項所述的影像處理方法。A computer device, wherein, the computer device includes a storage and at least one processor, at least one instruction is stored in the storage, and when the at least one instruction is executed by the at least one processor, the requirements of items 1 to 1 are implemented. The image processing method described in any one of 8.
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 TWI778735B (en) 2022-09-21
TW202307729A true 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)

Also Published As

Publication number Publication date
TWI778735B (en) 2022-09-21

Similar Documents

Publication Publication Date Title
CN106529537B (en) A kind of digital instrument reading image-recognizing method
US20190139213A1 (en) Data generation apparatus, data generation method, and data generation program
CN110287963B (en) OCR recognition method for comprehensive performance test
WO2019072181A1 (en) Bone marrow cell marking method and system
CN111340796B (en) Defect detection method and device, electronic equipment and storage medium
CN104881665A (en) Chip character identification and verification method and apparatus
US20220036115A1 (en) Method and apparatus for recognizing imaged information-bearing medium, computer device and medium
CN113033543B (en) Curve text recognition method, device, equipment and medium
CN114461986B (en) Method for training recognition identification model, and method and device for image recognition
CN111967313A (en) Unmanned aerial vehicle image annotation method assisted by deep learning target detection algorithm
CN111027538A (en) Container detection method based on instance segmentation model
WO2024002187A1 (en) Defect detection method, defect detection device, and storage medium
CN112232354A (en) Character recognition method, device, equipment and storage medium
TWI671686B (en) Image data retrieving method and image data retrieving device
TW202307729A (en) Image processing method, computer device, and storage medium
CN117173223A (en) Standard template generation method, device, equipment and medium for ammeter code-breaking screen
CN112597940A (en) Certificate image recognition method and device and storage medium
Wang et al. Insulator defect detection based on improved YOLOv5 algorithm
CN114066788B (en) Balanced instance segmentation data synthesis method
US11481577B2 (en) Machine learning (ML) quality assurance for data curation
CN115376137A (en) Optical character recognition processing and text recognition model training method and device
CN115705728A (en) Image processing method, computer device and storage medium
TWI786838B (en) Printing defect detection method, computer device, and storage medium
KR20230028050A (en) Method And Apparatus for Detecting Defect Based on Cascade Pass-Fail Determination
TWI807426B (en) Literal image defect detection method, computer device, and storage medium

Legal Events

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