Home > other >  Character segmentation pretreatment
Character segmentation pretreatment

Time:10-12


As shown in the picture, must carry on the pretreatment before character segmentation, how to get the preprocessing images with good effect, can find out the characters clearly outline?
Conglutination, segmentation is what should be?

CodePudding user response:

I use of halcon, for specific code below,

Read_image (Qq20191223160808, 'C:/Users/Administrator/Desktop/character segmentation practice/QQ screenshots 20191223160808. PNG')


Rgb1_to_gray (Qq20191223160808, GrayImage)

Gray_range_rect (GrayImage, ImageResult, 16, 16)

Threshold (ImageResult Regions2, 104, 207)

Connection (Regions2 ConnectedRegions2)

Select_shape (ConnectedRegions2 SelectedRegions, 'area', 'and', 58073.4, 100000)


Partition_dynamic (SelectedRegions, Partitioned1, 90, 10)

Sort_region (Partitioned1 SortedRegions1, 'character' and 'true', 'row')
Training * * * * * * * * * * * * * * * * *

Count_obj (Partitioned1, Number)
* to create training file * * * * * *

*
tags
Words:=[' U ', 'E', '5', '2', '6', '4', '4', '4']

TrainFile:='C:/Users/Administrator/Desktop/character segmentation practice/testWords. Agency'

Dev_set_check (' ~ give_error)

Delete_file (TrainFile)

Dev_set_check (' ~ give_error)

* generate training files

For I:=1 to the Number by 1

Select_obj (SortedRegions1, SingleWord I)

Append_ocr_trainf (SingleWord, GrayImage, words, [I - 1] TrainFile)

Endfor

* training file path

FontFile:='C:/Users/Administrator/Desktop/character segmentation practice/testWords. Forthcoming omc hair'

* reading training files

Read_ocr_trainf_names (TrainFile CharacterNames, CharacterCount)

NumHidden:=400

* create a neural network classifier

Create_ocr_class_mlp (10, 20, 'constant', 'default' CharacterNames, NumHidden, 'none', 10, 42, OCRHandle)

* here use halcon pre training model; The second and subsequent training to change the file name to FontFile first, the parameters of the call has been training continue training

* read_ocr_class_mlp (' DotPrint_0-9 a - Z_NoRej. Forthcoming omc hair, OCRHandle)

* training

Trainf_ocr_class_mlp (OCRHandle TrainFile, 200, 1, 0.01, the Error, the ErrorLog)

* save parameters to their file named

Write_ocr_class_mlp (OCRHandle FontFile)

* free memory

Clear_ocr_class_mlp (OCRHandle)

Stop ()


* identification codeDev_display (Qq20191223160808)

Rgb1_to_gray (Qq20191223160808, GrayImage)

Gray_range_rect (GrayImage, ImageResult, 16, 16)

Threshold (ImageResult Regions2, 104, 207)

Connection (Regions2 ConnectedRegions2)

Select_shape (ConnectedRegions2 SelectedRegions, 'area', 'and', 58073.4, 100000)


Partition_rectangle (SelectedRegions, Partitioned1, 90, 150)

Sort_region (Partitioned1 SortedRegions1, 'character' and 'true', 'row')
Training * * * * * * * * * * * * * * * * *

Count_obj (SortedRegions1, Number)

* to calculate each one character at a regional center

Area_center (SortedRegions1, Area, the Row, Column)

FontFile:='C:/Users/Administrator/Desktop/character segmentation practice/testWords. Forthcoming omc hair'


* read has trained parameters
Read_ocr_class_mlp (FontFile OCRHandle)

* identify

Do_ocr_multi_class_mlp (SortedRegions1, GrayImage, OCRHandle RecNum, Confidence)

Stop ()


* displayed on the screenDev_display (GrayImage)

Dev_disp_text (RecNum, 'Windows', Row, Column,' black '[], [])


  • Related