CN110598832B - Character perspective correction method based on genetic optimization algorithm - Google Patents

Character perspective correction method based on genetic optimization algorithm Download PDF

Info

Publication number
CN110598832B
CN110598832B CN201910777441.5A CN201910777441A CN110598832B CN 110598832 B CN110598832 B CN 110598832B CN 201910777441 A CN201910777441 A CN 201910777441A CN 110598832 B CN110598832 B CN 110598832B
Authority
CN
China
Prior art keywords
img
population
image
chr
character
Prior art date
Legal status (The legal status 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 status listed.)
Active
Application number
CN201910777441.5A
Other languages
Chinese (zh)
Other versions
CN110598832A (en
Inventor
赵凡
张琳
杨林林
闻治泉
康晓兵
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Qingteng Culture Co ltd
Original Assignee
Beijing Qingteng Culture Co ltd
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 Beijing Qingteng Culture Co ltd filed Critical Beijing Qingteng Culture Co ltd
Priority to CN201910777441.5A priority Critical patent/CN110598832B/en
Publication of CN110598832A publication Critical patent/CN110598832A/en
Application granted granted Critical
Publication of CN110598832B publication Critical patent/CN110598832B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/004Artificial life, i.e. computing arrangements simulating life
    • G06N3/006Artificial life, i.e. computing arrangements simulating life based on simulated virtual individual or collective life forms, e.g. social simulations or particle swarm optimisation [PSO]
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/12Computing arrangements based on biological models using genetic models
    • G06N3/126Evolutionary algorithms, e.g. genetic algorithms or genetic programming
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/80Geometric correction
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/136Segmentation; Edge detection involving thresholding
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/155Segmentation; Edge detection involving morphological operators
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10024Color image

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Health & Medical Sciences (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Biophysics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Biomedical Technology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • General Health & Medical Sciences (AREA)
  • Molecular Biology (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • General Engineering & Computer Science (AREA)
  • Evolutionary Biology (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Genetics & Genomics (AREA)
  • Physiology (AREA)
  • Character Discrimination (AREA)

Abstract

The invention discloses a character perspective correction method based on a genetic optimization algorithm, which comprises the steps of preprocessing a scene image, detecting a character frame and extracting a character region image set; setting control parameters of a genetic algorithm, initializing a population and establishing a fitness function; entering a genetic algorithm, and iteratively executing genetic operation to find an optimal outer-wrapped quadrangle of the character area; and after the genetic algorithm is finished, carrying out perspective correction matrix solving by using the obtained optimal character wrapping quadrangle, and finally, correcting the character area by using the solved perspective correction matrix to obtain a corrected character image. The method can effectively correct the perspective distortion of the scene text shot in a non-frontal mode so as to improve the recognition rate of the corrected image.

Description

Character perspective correction method based on genetic optimization algorithm
Technical Field
The invention belongs to the technical field of image processing, and particularly relates to a character perspective correction method based on a genetic optimization algorithm.
Background
The robot for acquiring the character information in the natural scene has wide application prospect in the fields of blind person assisted navigation, visual positioning and the like. Due to the diversity of characters appearing in natural scenes in font, size, color, direction and position and the influence of blurring, pollution and shielding, the detection, positioning and identification of characters in natural scenes are very challenging problems. Due to the reason of non-positive shooting, the detected characters usually have certain geometric distortion, the perspective correction of the detected character area is the basis of character segmentation and identification, and the method has important significance and scientific value for the development of portable or wearable visual auxiliary navigation systems.
Since the camera is not always in a front view, perspective distortion becomes one of the main challenges in text recognition. In the case of non-frontal photographing, the shape of the character is a quadrangle, and accurate estimation of the position of the quadrangle is a prerequisite for performing perspective correction. In the prior art, the optimal quadrangle is usually found by adopting a method of estimating the position of each side of the quadrangle in the image, and the method has high computational complexity and is difficult to meet the real-time requirement.
Disclosure of Invention
The invention aims to provide a character perspective correction method based on a genetic optimization algorithm, which solves the problem of higher complexity in the existing optimal quadrilateral estimation technology.
The technical scheme adopted by the invention is that a character perspective correction method based on a genetic optimization algorithm is implemented according to the following steps:
step 1, opening a shot scene image Img;
step 2, preprocessing the Img, wherein the preprocessing comprises the following steps: binarization, morphological processing, text box detection and text image set extraction;
step 2.1, extracting edges of Img to obtain an edge image SImgTo SImgPerforming adaptive threshold binarization to obtain binary image BImgTo B, pairImgMorphological processing is carried out to obtain a processed image CImgDefault to CImgThe middle white point pixels are character pixels, and the black point pixels are background pixels;
step 2.2, to image CImgDetecting the character frame to obtainTo text box set RS ═ { R ═ Ri|i=1,2,…I};
Step 2.3, initializing a text frame number counter I to be 1, setting the total number of text frames to be I, and correcting the post text image set ImgRSetting the character region position set Rect as NULL, wherein NULL is an empty set;
step 2.4, to the character frame RiExtracting external box BriTo external box BriPerforming a-time scale expansion to obtain an expansion frame REiAt CImgExtract RE therefromiCorresponding region of interest image
Figure BDA0002175516730000021
In RiCorresponding four vertices are
Figure BDA0002175516730000022
Respectively correspond to RiIn that
Figure BDA0002175516730000023
A middle left upper corner point, a right lower corner point and a left lower corner point;
step 3, initializing a genetic algorithm, including control parameter setting, chromosome setting, population initialization and fitness function establishment;
and 4, iteratively executing a genetic algorithm Inter _ GenProcessing, stopping iteration when the total iteration frequency gen is reached, and obtaining the chromosome at the end of iteration as Chri best=(Pi best1,Pi best2,Pi best3,Pi best4),Chri bestThe quadrangle enclosed by four vertexes is
Figure BDA0002175516730000024
Step 5, calculating the quadrangle
Figure BDA0002175516730000025
Corresponding correction rectangle
Figure BDA0002175516730000026
And obtaining a perspective transformation matrix Hi(ii) a Computing
Figure BDA0002175516730000027
External box
Figure BDA0002175516730000028
At CImgIs prepared by
Figure BDA0002175516730000029
Corresponding region of interest image
Figure BDA0002175516730000031
To pair
Figure BDA0002175516730000032
In the middle do not belong to
Figure BDA0002175516730000033
Performing a 0 operation on the pixel; by matrix HiFor images
Figure BDA0002175516730000034
Correcting to obtain corrected character image
Figure BDA0002175516730000035
Step 6, updating the corrected image set ImgR
Figure BDA0002175516730000036
Updating text region location sets
Figure BDA0002175516730000037
Updating a character area number counter i, i being i + 1; if I is less than or equal to I, entering the step 2.4; if I > I, entering step 7;
step 7, outputting the character image set Img after the correction of the scene image ImgRAnd a corresponding set of locations Rect.
The invention is also characterized in that:
the step 2.1 specifically comprises the following steps: calling a plurality of open source OpenCV library functions, and preprocessing the image Img: using Img as input, calling a function cvtColor (), and calculating to obtain a gray level image GImg(ii) a Handle GImgAs input, call function GaussianBlur () to get smooth image GfImg(ii) a Gf (general formula)ImgAs input, calling a function Sobel (), and calculating to obtain an x-direction gradient image Gradx and a y-direction gradient image Grady; using Gradx and Grady as input, calling function addWeighted (), calculating to obtain combined edge image SImg(ii) a Handle SImgAs input, calling a function adaptiveThreshold (), and calculating to obtain a binary image BImg(ii) a Handle BImgCalling an expansion function dilate () as an input, and calculating to obtain a morphological-processed image C to be detectedImg
Step 2.2 text box detection is specifically implemented according to the following steps:
step 2.2.1, image CImgAs input, calling OpenCV library function findContours () of open source, and calculating to obtain extracted contour set Contours0={Con0 i|i=1,2,…N};
Step 2.2.2, combine each contour
Figure BDA0002175516730000038
Calling an open-source OpenCV library function contourArea () as an input, and calculating to obtain an outline Area AreaiArea of the stemiContour elimination less than or equal to 800 to obtain a retained contour set Contours ═ Coni|i=1,2,…I};
Step 2.2.3, associate each contour ConiCalling an open-source OpenCV library function approxPlyDP () as an input, and calculating to obtain ConiThe fitted polygon polyi(ii) a Poly (o) is reacted withiAs input, calling OpenCV library function minareaRect () of open source, and calculating to obtain polyiMinimum circumscribed rectangle frame R ofi;RiIs recorded as centeriSet of vertices as
Figure BDA0002175516730000041
Set of text boxes RS ═ Ri|i=1,2,…I}。
Step 2.4 text region extraction is specifically implemented according to the following steps:
step 2.4.1, according to the character frame RiCenter point centeriCoordinate, will Rpi 0The top points in the middle are arranged in the order of the upper left corner, the upper right corner, the lower right corner and the lower left corner
Figure BDA0002175516730000042
The arrangement method comprises the following steps:
if it is
Figure BDA0002175516730000043
And is
Figure BDA0002175516730000044
Then
Figure BDA0002175516730000045
If it is
Figure BDA0002175516730000046
And is
Figure BDA0002175516730000047
Then
Figure BDA0002175516730000048
If it is
Figure BDA0002175516730000049
And is
Figure BDA00021755167300000410
Then
Figure BDA00021755167300000411
If it is
Figure BDA00021755167300000412
And is
Figure BDA00021755167300000413
Then
Figure BDA00021755167300000414
Step 2.4.2, treating
Figure BDA00021755167300000415
As an input, calling an OpenCV library function bounngselect () of an open source, and calculating to obtain a text box RiExternal connection box Bri,BriSet of vertices as
Figure BDA00021755167300000416
External box BriPerforming a-time expansion to obtain an expansion frame REi,REiSet of vertices as
Figure BDA00021755167300000417
Wherein a is more than 0 and less than or equal to min (C)Img.w/REi.w,CImg.h/REiH), min () is the minimum function;
step 2.4.3, REi、CImgAs input, call OpenCV library function cvSetImageROI () from open source, at CImgExtract RE therefromiCorresponding region of interest image
Figure BDA00021755167300000418
RiFour vertexes
Figure BDA00021755167300000419
In that
Figure BDA00021755167300000420
Respectively corresponding spatial positions in
Figure BDA00021755167300000421
Step 3 is specifically implemented according to the following steps:
step 3.1, setting control parameters as follows: the population size popsize is 4, the coding bit number chroma is 40, the total iteration number gen is 100, the crossing rate pcross is 100%, and the variation rate pmutation is 2%;
step 3.2, respectively using RiFour vertices of
Figure BDA00021755167300000422
Is centered at
Figure BDA00021755167300000423
In extracting four square areas
Figure BDA00021755167300000424
Nδ(P) is represented as a neighborhood of size (2 δ +1) × (2 δ +1) centered on P, and the neighborhood set is denoted as
Figure BDA00021755167300000425
The chromosome extraction specifically comprises the following steps: respectively in each region of the neighborhood set
Figure BDA0002175516730000051
Randomly selecting a point PmAll of PmConstituting a chromosome chr, chr ═ (P)1,P2,P3,P4) (ii) a The chromosome code is specifically: will PmIn that
Figure BDA0002175516730000052
One-dimensional pixel coordinate of (1) is recorded as Lm,0≤Lm(2 delta +1) × (2 delta +1), 0-delta 15, for LmPerforming 10-bit binary coding to obtain code word CmThe 40-bit code word of the chromosome chr is: 230C1+220C2+210C3+C4
Step 3.3, the population initialization specifically comprises the following steps: according to the chromosome extraction method in step 3.2, in the neighborhood set
Figure BDA0002175516730000053
Co-extracting popsize chromosomes to form an initial population of genetic algorithm (chr)k1, …, popsize }, wherein
Figure BDA0002175516730000054
Coding each chromosome of the initial population according to the coding method in the step 3.2 to obtain a code word set { cs ] of the initial population k1, …, popsize }, wherein
Figure BDA0002175516730000055
Figure BDA0002175516730000056
Is that
Figure BDA0002175516730000057
The 10-bit binary code word;
step 3.4, defining fitness function
Figure BDA0002175516730000058
quad is the four vertices of chromosome chr
Figure BDA0002175516730000059
A quadrangle formed by the four corners, n is an image
Figure BDA00021755167300000510
The number of character pixels in the middle quadrangle quad (namely the number of white dot pixels) is s, and is the area of the quadrangle quad.
The genetic algorithm Inter _ GenProcessing in the step 4 is specifically implemented according to the following steps:
step 4.1, inputting: control parameter, chromosome inception population { chr k1, …, popsize }, fitness function, text region
Figure BDA00021755167300000511
Character frame Ri(ii) a Defining chromosome population variable set in genetic algorithm iteration process as oldtopi,oldpopi={oldchr i k1, …, popsize }, for oldchri kAssigning an initial value, oldchri k=chrk(ii) a Optimal chromosome Chr in genetic algorithm iterative processi bestInitialisation to NULL, Chri bestAdaptation value Chr ofi bestFitness is initialized to 0; defining an iteration variable as j, and initializing to 1;
step 4.2, calculating oldPopiOf each chromosome oldchri kCorresponding to the area s of the quadrangle, counting the number n of character pixel points in the area of the quadrangle, and calculating
Figure BDA00021755167300000512
oldchri kN and s as inputs, calling the fitness function
Figure BDA00021755167300000513
Calculated to obtain oldchri kIs of the fitness value oldchri k.fitness;
Step 4.3, according to Roulette selection method Roulette _ Choosing (), the cluster of the population oldhop is treatediThe individuals in the population are subjected to importance sampling to obtain a new population newporti={newchri k|k=1,…,popsize};
The specific execution process of Roulette _ Chooning () is as follows:
step 4.3.1, calculate individual oldchri kSelection probability P (oldchr)i k): for population oldtopiFitness oldchr of all individuals in Chinai kThe total fitness of the population is obtained by the fitness summation
Figure BDA0002175516730000061
P(oldchri k)=oldchri k.fitness/Fit;
Step 4.3.2, calculating population individual oldchri kAccumulated probability of (2)
Figure BDA0002175516730000062
Figure BDA0002175516730000063
4.3.3, performing popsize importance sampling on the individual, wherein the importance sampling process comprises the following steps: in the interval [0,1]In which a uniformly distributed random number r is generatediIf, if
Figure BDA0002175516730000064
Then the population individual oldchri 1Is selected; if it is
Figure BDA0002175516730000065
Then the population individual oldchri kAnd (6) selecting. New population newportiConsisting of sampled popsize individuals, i.e., newpotsi={newchri k|k=1,…,popsize};
Step 4.4, carrying out newport on the new population according to the cross rate pcrossiPerforming cross genetic operation on the individuals in the population, and updating the newport population by using all the individuals after the cross operationi
Step 4.4.1, in the newport of the populationiRandomly selecting popsize multiplied by pcross individuals to carry out pairwise genetic crossing operation, wherein the specific process of the cross genetic operation is as follows: 2 in two individual code words respectively39,238,…,230Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words29,228,…,220Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words19,218,…,210Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words9,28,…,20Randomly selecting 4 bits from the bits for exchange operation; updating the newport of the population by using individuals after cross operationi
4.4.2, error correction processing of illegal code words after cross genetic operation:
the population after cross genetic operation is newcropi={newchr i k1, …, popsize, each chromosome newchri kThe 40-bit code word is Cchri k,
Figure BDA0002175516730000071
Wherein
Figure BDA0002175516730000072
Is the mth 10-bit code word of the corresponding kth chromosome. For code word
Figure BDA0002175516730000073
And (3) carrying out illegal judgment and error correction: combining binary code words
Figure BDA0002175516730000074
Decimal number conversion to obtain
Figure BDA0002175516730000075
If it is not
Figure BDA0002175516730000076
Then it is considered that
Figure BDA0002175516730000077
For illegal code words, handle
Figure BDA0002175516730000078
Linear transformation to
Figure BDA0002175516730000079
Figure BDA00021755167300000710
Where int () is a rounding function,
Figure BDA00021755167300000711
the error-corrected code word is
Figure BDA00021755167300000712
A 10 bit binary number of;
step 4.5, carrying out newport on the populationiPerforming mutation genetic operation on each chromosome in the new crop plant, and performing newcrop plant operation on all the individuals after mutationiAnd (6) updating. Calculating the number of variation digits H according to the variation rate calculationbit, HbitPopsize × 40 × precipitation, population newport by number of mutationsiAll individuals in (a) were subjected to genetic variation manipulation. If the number of the mutation is less than 1, not carrying out mutation; otherwise, performing mutation operation. The mutation operation process comprises the following steps: in {239,238,…,20H is randomly selected between the digit numbersbitThe bits are varied, with a variation of 1 for a value of 0 and a variation of 0 for a value of 1;
according to the illegal code word error correction processing method in the step 4.4.2, the newport is processed to the populationiAll 10-bit code words under each chromosome are subjected to illegal judgment and error correction to obtain the population subjected to error correction
Figure BDA00021755167300000713
Step 4.6, updating population variable oldtopi,oldpopi=newpopi(ii) a At oldpostiSelecting individual pair population oldtop with maximum adaptabilityiOptimum chromosome Chr in (1)i maxThe value is assigned to the value to be assigned,
Figure BDA00021755167300000714
Figure BDA00021755167300000715
optimal chromosome Chr in iterative process of genetic algorithmi bestUpdating: if Chri max.fitness>Chri bestFitness, then Chri best=Chri max(ii) a If Chri max.fitness≤Chri bestFitness, no processing is done;
step 4.7, j equals j + 1; if J is less than or equal to J, entering the step 4.2; if J is larger than J, ending the iteration process, and entering the step 4.8;
step 4.8, chromosome Chri bestOptimal chromosome Chr found for the end of the Inter _ Genprocessing iteration of the genetic algorithmi best=(Pi best1,Pi best2,Pi best3,Pi best4),Chri bestThe quadrangle enclosed by four points is the best outer-packaging quadrangle of the character area and is marked as
Figure BDA0002175516730000081
Step 5, the perspective correction of the character area is implemented according to the following specific steps:
step 5.1, according to the quadrangle
Figure BDA0002175516730000082
Four vertices P ofi best1,Pi best2,Pi best3,Pi best4Calculating a corresponding correction rectangle
Figure BDA0002175516730000083
Wherein P isi best1、w+And h+Respectively correspond to
Figure BDA00021755167300000823
Top left vertex of (1), width and height;
w+,h+the calculation is as follows:
Figure BDA0002175516730000084
Figure BDA0002175516730000085
w+=max(hor0,hor1);
Figure BDA0002175516730000086
Figure BDA0002175516730000087
h+=max(ver0,ver1);
where max () is the function of the maximum;
handle
Figure BDA0002175516730000088
And
Figure BDA0002175516730000089
as input, calling open source OpenCV library function getPerfectTransform (), and calculating to obtain perspective transformation matrix Hi
Step 5.2, calculating
Figure BDA00021755167300000810
External box
Figure BDA00021755167300000811
Handle
Figure BDA00021755167300000812
And CImgAs input, calling the OpenCV library function cvSetImageROI () of open source to obtain CImgExtracted from
Figure BDA00021755167300000813
Corresponding region of interest image
Figure BDA00021755167300000814
To pair
Figure BDA00021755167300000815
In the middle do not belong to
Figure BDA00021755167300000816
The pixel value of (a) is subjected to a 0 operation,
Figure BDA00021755167300000817
the coordinates of the inner pixel points are marked as (x, y), the pixel values are marked as P (x, y), if
Figure BDA00021755167300000818
Then P (x, y) is 0;
step 5.3, define the corrected image variable as
Figure BDA00021755167300000819
Handle
Figure BDA00021755167300000820
And HiCalling openCV library function warp Perspective () of an open source as input, and calculating to obtain
Figure BDA00021755167300000821
Corrected image
Figure BDA00021755167300000822
The invention has the beneficial effects that:
the invention relates to a character perspective correction method based on a genetic optimization algorithm, which is mainly used for correcting the distortion of the perspective of a scene text shot in a non-frontal manner, so that the complexity is reduced and the recognition rate of characters is improved during the perspective correction of the characters in the scene.
Drawings
FIG. 1 is a flow chart of a text perspective correction method based on a genetic optimization algorithm according to the present invention;
FIG. 2 is a schematic diagram of neighborhood extraction of the text perspective correction method based on genetic optimization algorithm of the present invention;
FIG. 3 is a flow chart of a text box detection method of the text perspective correction method based on a genetic optimization algorithm according to the present invention;
FIG. 4 is a flow chart of a text region extraction method of the text perspective correction method based on the genetic optimization algorithm of the present invention;
FIG. 5 is a flow chart of the genetic algorithm of the character perspective correction method based on the genetic optimization algorithm.
Detailed Description
The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
The scene text correction method based on the genetic algorithm is implemented according to the following steps as shown in figure 1:
step 1, opening a shot scene image;
step 2, preparing before correction, as shown in fig. 2-4, specifically comprising the following steps:
recording a shot scene image as Img, calling a plurality of open source OpenCV library functions to carry out preprocessing operation on the Img to obtain a processed image CImgThe method is implemented by the following steps:
1) using Img as input, calling a function cvtColor (), and calculating to obtain a gray level image GImg(ii) a To reduce image noise, GImgAs input, a 3 × 3 gaussian kernel template is used, and the function GaussianBlur () is called to the grayscale image GImgPerforming Gaussian smoothing to obtain an image GfImg(ii) a Gf (general formula)ImgAs input, calling a function Sobel (), and calculating to obtain an x-direction gradient image Gradx and a y-direction gradient image Grady; using Gradx and Grady as input, calling function addWeighted (), calculating to obtain combined edge feature image SImg
2) Processing the edge feature image SImgAs input, calling an open source OpenCV library function adaptive threshold () to perform adaptive threshold binarization processing to obtain a binary image BImg(ii) a Handle BImgAs input, calling an expansion function dilate (), and calculating to obtain the morphologically processed image C to be detectedImgDefault to CImgThe middle white point pixels are character pixels, and the black point pixels are background pixels;
② to detect the image CImgThe detection of the image text box is realized by contour extraction, and the method is implemented according to the following steps:
1) image CImgAs input, call OpenCV library function findContours () extract C of open sourceImgObtaining the external contour of all the connected regions inside to obtain the extracted contour set Contours0={Con0 i|i=1,2,…N},N is the total number of the profiles;
2) each contour Con0 iAs input, calling OpenCV library function contourArea () of open source to calculate to obtain the outline area Con0 iArea of (1)i(ii) a If AreaiIf the Area of the outline is less than or equal to 800, the Area of the outline is judged to be too small, no research significance is realized, the outline is removed from the outline set, and if the Area is less than or equal to 800, the outline is removediIf the area of the contour is more than 800, the contour area meets the condition, and the contour is stored; the remaining contour set Contours ═ Con is obtained by the above area judgmenti|i=1,2,…I};
3) Each contour ConiEach contour Con consisting of a set of spatial points in the imageiUsing a point set composed of the space points as input, calling an open-source OpenCV library function approxColDP (), and calculating to obtain the outline ConiThe fitted polygon polyiThe polygon set corresponding to the contour set Contours is designated as Con _ poly ═ poly { (poly)i|i=1,2,…I};
4) Each polygon polyiAs input, calling OpenCV library function minareaRect () of open source, and calculating to obtain polyiMinimum circumscribed rectangle frame Ri;RiIs recorded as centeriSet of vertices as
Figure BDA0002175516730000111
Set of text boxes RS ═ Ri|i=1,2,…I};
Thirdly, initializing a frame number counter I equal to 1, setting the total number of the frames as I, and correcting the post-image set ImgRSetting the character region position set Rect as NULL, wherein NULL is an empty set;
r from the text box set RS ═ R i1,2, … I in binary image CImgUpper extraction of RiCorresponding region of interest image
Figure BDA0002175516730000112
And extracting the image
Figure BDA0002175516730000113
Lower RiCharacter(s)Frame vertex
Figure BDA0002175516730000114
The method is implemented by the following steps:
1) according to the character frame RiCenter point centeriCoordinate, will Rpi 0The top points in the middle are arranged in the order of the upper left corner, the upper right corner, the lower right corner and the lower left corner
Figure BDA0002175516730000115
The sorting method specifically comprises the following steps: according to RiFour vertices and center point centeriTo determine RiSpecific directions of the four vertices, if
Figure BDA0002175516730000116
And is
Figure BDA0002175516730000117
Then determine the top left corner point
Figure BDA0002175516730000118
If it is
Figure BDA0002175516730000119
And is
Figure BDA00021755167300001110
Then the upper right corner point is determined
Figure BDA00021755167300001111
If it is
Figure BDA00021755167300001112
And is
Figure BDA00021755167300001113
Then determine the lower right corner point
Figure BDA00021755167300001114
If it is
Figure BDA00021755167300001115
And is
Figure BDA00021755167300001116
Then determine the lower left corner point
Figure BDA00021755167300001117
Arranging according to the sequence of the upper left corner, the upper right corner, the lower right corner and the lower left corner to obtain Rpi 0Four vertices are
Figure BDA00021755167300001118
2) Handle
Figure BDA00021755167300001119
As an input, calling an OpenCV library function bounngselect () of an open source, and calculating to obtain a text box RiExternal connection box Bri,BriSet of vertices as
Figure BDA00021755167300001120
External box BriPerforming a-time expansion to obtain an expansion frame REi,REiSet of vertices as
Figure BDA00021755167300001121
Wherein a is more than 0 and less than or equal to min (C)Img.w/REi.w,CImg.h/REiH), min () is the minimum function;
extension frame REiThe four vertices of (a) are calculated as follows:
calculate the external box BriWide Br ofiW, high BriH, center point
Figure BDA0002175516730000121
Coordinates of the object
Figure BDA0002175516730000122
And
Figure BDA0002175516730000123
Figure BDA0002175516730000124
Figure BDA0002175516730000125
compute extension frame REiWide RE ofiW and high REi.h: REi.w=a×BriW and high REi.h=a×BriH; compute extension frame REiFour vertices of
Figure BDA0002175516730000126
The coordinates of (a):
Figure BDA0002175516730000127
Figure BDA0002175516730000128
Figure BDA0002175516730000129
Figure BDA00021755167300001210
REiand (3) processing beyond image boundary:
if it is
Figure BDA00021755167300001211
Then
Figure BDA00021755167300001212
If it is
Figure BDA00021755167300001213
Then
Figure BDA00021755167300001214
If it is
Figure BDA00021755167300001215
Then
Figure BDA00021755167300001216
If it is
Figure BDA00021755167300001217
Then
Figure BDA00021755167300001218
3) R (R) REi、CImgAs input, call OpenCV library function cvSetImageROI () from open source, at CImgExtract RE therefromiCorresponding region of interest image
Figure BDA00021755167300001219
In that
Figure BDA00021755167300001220
In RiThe corresponding vertex is
Figure BDA00021755167300001221
Step 3, preparing before genetic manipulation, specifically comprising the following steps:
setting control parameters of a genetic algorithm:
setting the population size of the genetic algorithm popsize to be 4, setting the encoding digit chrome to be 40, setting the total iteration number gen to be 100, setting the cross rate pcross to be 100 percent and setting the mutation rate pmutation to be 2 percent;
setting chromosomes: are each represented by RiFour vertexes
Figure BDA0002175516730000131
Is centered at
Figure BDA0002175516730000132
Extracting four square areas
Figure BDA0002175516730000133
Figure BDA0002175516730000134
Nδ(P) is represented as a neighborhood of size (2 δ +1) × (2 δ +1) centered on P, and the neighborhood set is denoted as
Figure BDA0002175516730000135
The chromosome extraction specifically comprises the following steps: respectively in each region of the neighborhood set
Figure BDA0002175516730000136
Randomly selecting a point PmAll of PmConstituting a chromosome chr, chr ═ (P)1,P2,P3,P4) (ii) a The chromosome code is specifically: will PmIn that
Figure BDA0002175516730000137
One-dimensional pixel coordinate of (1) is recorded as Lm,0≤Lm(2 δ +1) × (2 δ +1), δ 15; to LmCarry out 10-bit binary coding to obtain code word CmThe 40-bit code word of the chromosome chr is: 230C1+220C2+210C3+C4
The initialization of the population is specifically as follows: according to the chromosome extraction method in the step II, a neighborhood set is subjected to
Figure BDA0002175516730000138
Co-extracting popsize chromosomes to form an initial population of genetic algorithm (chr)k1, …, popsize }, wherein
Figure BDA0002175516730000139
Coding each chromosome of the initial population according to the coding method in the step II to obtain a code word set { cs ] of the initial population k1, …, popsize }, wherein
Figure BDA00021755167300001310
Figure BDA00021755167300001311
Is that
Figure BDA00021755167300001312
The 10-bit binary code word;
fourthly, defining a fitness function
Figure BDA00021755167300001313
quad is the four vertices of chromosome chr
Figure BDA00021755167300001314
A quadrangle formed by the four corners, n is an image
Figure BDA00021755167300001315
The number of character pixels counted in the middle quadrangle quad (namely the number of white dot pixels) is s, and is the area of the quadrangle quad;
and 4, iteratively executing a genetic algorithm Inter _ GenProcessing, finishing iteration when the total iteration number gen is reached, and obtaining the chromosome at the end of iteration as Chri best=(Pi best1,Pi best2,Pi best3,Pi best4),Chri bestFour vertexes forming a quadrangle
Figure BDA00021755167300001316
As shown in fig. 5, the genetic algorithm Inter _ GenProcessing specifically includes the following steps:
firstly, inputting: control parameter, chromosome inception population { chr k1, …, popsize }, fitness function, text region
Figure BDA0002175516730000141
And a text box Ri(ii) a Defining chromosome population variable set in genetic algorithm iteration process as oldtopi,oldpopi={oldchr i k1, …, popsize }, for oldchri kAssigning an initial value, oldchri k=chrk(ii) a Optimal chromosome Chr in genetic algorithm iteration processi bestInitialisation to NULL, Chri bestAdaptation value Chr ofi bestFitness is initialized to 0; defining an iteration variable as j, and initializing to 1;
② calculate oldPopiOf each chromosome oldchri kCounting the number n of character pixel points in the quadrilateral area corresponding to the quadrilateral area s, and counting
Figure BDA0002175516730000142
oldchri kN and s as inputs, calling the fitness function
Figure BDA0002175516730000143
Calculated to obtain oldchri kIs of the fitness value oldchri k.fitness;
③ according to Roulette selection method Roulette _ Choosing (), the cluster oldpops of the populationiThe individuals in the new population are subjected to important sampling to obtain a new population newporti={newchri k|k=1,…,popsize};
The Roulette _ sounding () method in the third embodiment is specifically implemented as follows:
computing population oldtopiThe total fitness of Fit of (1) is,
Figure BDA0002175516730000144
calculating individual oldchri kSelection probability P (oldchr)i k),
Figure BDA0002175516730000145
Calculating population individual oldchri kAccumulated probability of (2)
Figure BDA0002175516730000146
Figure BDA0002175516730000147
Performing popsize secondary importance sampling on the individual, wherein the primary importance sampling process comprises the following steps: in the interval [0,1]In which a uniformly distributed random number r is generatediIf, if
Figure BDA0002175516730000148
Then the population individual oldchri 1Selected as a new individual of the population; if it is
Figure BDA0002175516730000149
Then the population individual oldchri kSelected as new individuals of the population. New population newportiConsisting of sampled popsize individuals, i.e., newpotsi={newchri k|k=1,…,popsize};
Fourthly, carrying out cross genetic operation on the individuals in the new population according to the cross rate pcross, and updating the newport population by using all the individuals after the cross operationi(ii) a For new population newportiCarrying out illegal code word error correction processing on the individuals;
the crossing method in the fourth step specifically comprises the following steps:
in newport of populationiSelecting popsize X pcross individuals to carry out pairwise genetic cross operation, wherein the specific process of the cross genetic operation is as follows: 2 in two individual code words respectively39,238,…,230Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words29,228,…,220Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words19,218,…,210Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words9,28,…,20Randomly select 4 bits from the bits to perform the swap operation. Updating the newport of the population by using individuals after cross operationi
The illegal codeword error correction processing in the above fourth is specifically:
the population after cross genetic operation is newcropi={newchr i k1, …, popsize, each chromosome newchri kThe 40-bit code word is Cchri k,
Figure BDA0002175516730000151
Wherein
Figure BDA0002175516730000152
Is the mth 10-bit code word of the corresponding kth chromosome. For code word
Figure BDA0002175516730000153
And (3) carrying out illegal judgment and error correction: combining binary code words
Figure BDA0002175516730000154
Decimal number conversion to obtain
Figure BDA0002175516730000155
If it is not
Figure BDA0002175516730000156
Then it is considered that
Figure BDA0002175516730000157
For illegal code words, handle
Figure BDA0002175516730000158
Linear transformation to
Figure BDA0002175516730000159
Figure BDA00021755167300001510
Where int () is a rounding function,
Figure BDA00021755167300001511
the error-corrected code word is
Figure BDA00021755167300001512
A 10 bit binary number of;
fifth to newcropiPerforming mutation genetic operation on each chromosome in the new genome, and performing newport genetic operation on all the mutated chromosomesiUpdating is carried out; for the newcrop of the population after the genetic operation of the variationiThe individual in the system carries out illegal code word error correction processing;
the mutation operation in the fifth step is specifically implemented as follows:
calculating the number of mutation bits Hbit:HbitPopsize × 40 × precipitation, population newport by number of mutationsiPerforming genetic variation operation on all individuals in the group; if the number of the mutation is less than 1, not carrying out mutation; otherwise, carrying out mutation operation; the mutation operation process comprises the following steps: in {239,238,…,20H is randomly selected between the digit numbersbitThe bits are varied, with a variation of 1 for a value of 0 and a variation of 0 for a value of 1;
the illegal codeword error correction processing in the above fifth embodiment is as follows:
according to the illegal code word error correction processing method in the step (IV), the newport of the population is correctediAll 10-bit code words under each chromosome are subjected to illegal judgment and error correction to obtain a new population newport after error correctioni
Sixthly, updating the population variable oldtopi,oldpopi=newpopi(ii) a At oldpostiSelecting individual pair population oldtop with maximum fitnessiOptimum chromosome Chr in (1)i maxThe value is assigned to the value to be assigned,
Figure BDA0002175516730000161
Figure BDA0002175516730000162
optimal chromosome Chr in iterative process of genetic algorithmi bestUpdating: if Chri max.fitness>Chri bestFitness, then Chri best=Chri max(ii) a If Chri max.fitness≤Chri bestFitness, no processing is done;
seventhly, j is j + 1; if J is less than or equal to J, entering the step II; if J is more than J, ending the iterative process and entering the step (b);
' calculating optimal outsourcing quadrangle of character area
Figure BDA0002175516730000163
Is composed of optimal chromosome Chri best=(Pi best1,Pi best2,Pi best3,Pi best4) A quadrangle formed by four points;
step 5, aligning the best outsourcing quadrangle
Figure BDA0002175516730000164
Correcting the enclosed character area, specifically comprising the following steps:
according to the quadrangle
Figure BDA0002175516730000165
Four vertices P ofi best1,Pi best2,Pi best3,Pi best4Calculating a corresponding correction rectangle
Figure BDA0002175516730000166
Wherein P isi best1、w+And h+Respectively correspond to
Figure BDA0002175516730000167
Upper left vertex of (d), width and height:
w+,h+the calculations are shown as (5) and (6):
Figure BDA0002175516730000168
Figure BDA0002175516730000169
where max () is the function of the maximum.
② handle
Figure BDA00021755167300001610
And
Figure BDA00021755167300001611
as input, the open source OpenCV library function getPerfectTransform () is called to be calculated
Figure BDA0002175516730000171
And
Figure BDA0002175516730000172
inter-perspective transformation matrix Hi
Calculating
Figure BDA0002175516730000173
External box
Figure BDA0002175516730000174
Handle
Figure BDA0002175516730000175
And CImgAs input, calling the OpenCV library function cvSetImageROI () of open source to obtain CImgExtracted from
Figure BDA0002175516730000176
Corresponding region of interest image
Figure BDA0002175516730000177
To pair
Figure BDA0002175516730000178
In the middle do not belong to
Figure BDA0002175516730000179
The pixel value of (a) is subjected to a 0 operation,
Figure BDA00021755167300001710
the coordinates of the inner pixel points are marked as (x, y), the pixel values are marked as P (x, y), if
Figure BDA00021755167300001711
Then P (x, y) is 0; defining the rectified image variable as
Figure BDA00021755167300001712
Handle
Figure BDA00021755167300001713
And HiAs input, calling OpenCV library function warp perspective () of open source, and calculating to obtain
Figure BDA00021755167300001714
Corrected image
Figure BDA00021755167300001715
Step 6, updating the corrected image set ImgR
Figure BDA00021755167300001716
Updating text region location sets
Figure BDA00021755167300001717
Updating a character area number counter i, i being i + 1; if I is not more than I, entering the fourth step in the step 2; if I > I, entering step 7;
step 7, outputting the character image set Img after the correction of the scene image ImgRAnd a corresponding set of locations Rect.
The invention relates to a character perspective correction method based on a genetic optimization algorithm, which removes image noise by calling a fuzzy function in the preprocessing of an image; acquiring strong edge information of the characters by calling an edge extraction function; the binary segmentation of different scene images is realized by self-adaptive threshold binarization processing on the edge images; only relevant areas containing text contents are processed to reduce the operation complexity through contour extraction, region-of-interest extraction, text box expansion and expanded area extraction; by establishing an objective function of the ratio of the elevation to the number of white point pixels, the number of character pixels is maximized while the shape compactness of a character area is met; the importance sampling of the samples is carried out by using a roulette method, so that the high sampling rate of the samples with high fitness values can be met; by utilizing an optimization mechanism of a genetic algorithm, the time complexity for searching the optimal character outsourcing quadrangle can be reduced; the method realizes the perspective correction of the character area by utilizing the calculation of the optimal character outsourcing quadrangle, so that the method provided by the invention can reduce the complexity of the perspective correction of the characters in the scene and improve the recognition rate of the characters at the same time.

Claims (7)

1. A character perspective correction method based on a genetic optimization algorithm is characterized by comprising the following steps: the method is implemented according to the following steps:
step 1, opening a shot scene image Img;
step 2, preprocessing the Img, comprising: binarization and morphological processing, text box detection and text image set extraction:
step 2.1, extracting edges of Img to obtain an edge image SImgTo SImgPerforming adaptive threshold binarization to obtain binary image BImgTo B, pairImgMorphological processing is carried out to obtain a processed image CImgDefault to CImgThe middle white point pixels are character pixels, and the black point pixels are background pixels;
step 2.2, to image CImgPerforming text frame detection to obtain a text frame set RS ═ Ri|i=1,2,…I};
Step 2.3, initializing a text frame number counter I to be 1, setting the total number of the text frames to be I, and correcting the text image set ImgRSetting the character region position set Rect as NULL, wherein NULL is an empty set;
step 2.4, to the character frame RiExtracting external box BriTo external box BriPerforming a-time scale expansion to obtain an expansion frame REiAt CImgExtract RE therefromiCorresponding region of interest image
Figure FDA0003393361060000011
In RiCorresponding four vertices are
Figure FDA0003393361060000012
Respectively correspond to RiIn that
Figure FDA0003393361060000013
A middle left upper corner point, a right lower corner point and a left lower corner point;
step 3, initializing a genetic algorithm, including control parameter setting, chromosome setting, population initialization and fitness function establishment;
and 4, iteratively executing a genetic algorithm Inter _ GenProcessing, stopping iteration when the total iteration frequency gen is reached, and obtaining the chromosome at the end of iteration as Chri best=(Pi best1,Pi best2,Pi best3,Pi best4),Chri bestThe quadrangle enclosed by four vertexes is
Figure FDA0003393361060000014
Step 5, calculating the quadrangle
Figure FDA0003393361060000021
Corresponding correction rectangle
Figure FDA00033933610600000213
And obtaining a perspective transformation matrix Hi(ii) a Computing
Figure FDA0003393361060000022
External box
Figure FDA0003393361060000023
At CImgIs prepared by
Figure FDA0003393361060000024
Corresponding region of interest image
Figure FDA0003393361060000025
To pair
Figure FDA0003393361060000026
In the middle do not belong to
Figure FDA0003393361060000027
Performing a 0 operation on the pixel; by matrix HiFor images
Figure FDA0003393361060000028
Correcting to obtain corrected character image
Figure FDA0003393361060000029
Step 6, updating the corrected image set ImgR
Figure FDA00033933610600000210
Updating text region location sets
Figure FDA00033933610600000211
Updating a character area number counter i, i being i + 1; if I is less than or equal to I, entering the step 2.4; if i>I, entering a step 7;
step 7, outputting the character image set Img after the correction of the scene image ImgRAnd a corresponding set of locations Rect.
2. The character perspective correction method based on the genetic optimization algorithm according to claim 1, wherein the step 2.1 is specifically as follows: calling a plurality of open source OpenCV library functions, and preprocessing the image Img: using Img as input, calling a function cvtColor (), and calculating to obtain a gray level image GImg(ii) a Handle GImgAs input, calling the function GaussianBlur () to get a smooth graphLike GfImg(ii) a Gf (general formula)ImgAs input, calling a function Sobel (), and calculating to obtain an x-direction gradient image Gradx and a y-direction gradient image Grady; using Gradx and Grady as input, calling function addWeighted (), calculating to obtain combined edge image SImg(ii) a Handle SImgAs input, calling a function adaptiveThreshold (), and calculating to obtain a binary image BImg(ii) a Handle BImgCalling an expansion function dilate () as an input, and calculating to obtain a morphological-processed image C to be detectedImg
3. The character perspective correction method based on the genetic optimization algorithm as claimed in claim 1, wherein the step 2.2 is implemented according to the following steps:
step 2.2.1, image CImgAs input, calling OpenCV library function findContours () of open source, and calculating to obtain extracted contour set Contours0={Con0 i|i=1,2,…N};
Step 2.2.2, combine each contour
Figure FDA00033933610600000212
Calling an open-source OpenCV library function contourArea () as an input, and calculating to obtain an outline Area AreaiArea of the stemiContour elimination less than or equal to 800 to obtain a retained contour set Contours ═ Coni|i=1,2,…I};
Step 2.2.3, associate each contour ConiCalling an open-source OpenCV library function approxPlyDP () as an input, and calculating to obtain ConiThe fitted polygon polyi(ii) a Poly (o) is reacted withiAs input, calling OpenCV library function minareaRect () of open source, and calculating to obtain polyiMinimum circumscribed rectangle frame R ofi;RiIs recorded as centeriSet of vertices as
Figure FDA0003393361060000031
Set of text boxes RS ═ Ri|i=1,2,…I}。
4. The character perspective correction method based on the genetic optimization algorithm as claimed in claim 3, wherein the step 2.4 is implemented according to the following steps:
step 2.4.1, according to the character frame RiCenter point centeriCoordinate, will Rpi 0The top points in the middle are arranged in the order of the upper left corner, the upper right corner, the lower right corner and the lower left corner
Figure FDA0003393361060000032
The arrangement method comprises the following steps:
if it is
Figure FDA0003393361060000033
And is
Figure FDA0003393361060000034
Then
Figure FDA0003393361060000035
If it is
Figure FDA0003393361060000036
And is
Figure FDA0003393361060000037
Then
Figure FDA0003393361060000038
If it is
Figure FDA0003393361060000039
And is
Figure FDA00033933610600000310
Then
Figure FDA00033933610600000311
If it is
Figure FDA00033933610600000312
And is
Figure FDA00033933610600000313
Then
Figure FDA00033933610600000314
Step 2.4.2, treating
Figure FDA00033933610600000315
As an input, calling an OpenCV library function bounngselect () of an open source, and calculating to obtain a text box RiExternal connection box Bri,BriSet of vertices as
Figure FDA00033933610600000316
External box BriPerforming a-time expansion to obtain an expansion frame REi,REiSet of vertices as
Figure FDA00033933610600000317
Wherein 0<a≤min(CImg.w/REi.w,CImg.h/REiH), min () is the minimum function;
step 2.4.3, REi、CImgAs input, call OpenCV library function cvSetImageROI () from open source, at CImgExtract RE therefromiCorresponding region of interest image
Figure FDA00033933610600000318
RiFour vertexes
Figure FDA00033933610600000319
In that
Figure FDA00033933610600000320
Respectively corresponding spatial positions in
Figure FDA00033933610600000321
5. The character perspective correction method based on the genetic optimization algorithm as claimed in claim 1, wherein the step 3 is implemented by the following steps:
step 3.1, setting control parameters as follows: the population size popsize is 4, the coding bit number chroma is 40, the total iteration number gen is 100, the crossing rate pcross is 100%, and the variation rate pmutation is 2%;
step 3.2, respectively using RiFour vertices of
Figure FDA0003393361060000041
Is centered at
Figure FDA0003393361060000042
Extracting four square areas
Figure FDA0003393361060000043
Nδ(P) is represented as a neighborhood of size (2 δ +1) × (2 δ +1) centered on P, and the neighborhood set is denoted as
Figure FDA0003393361060000044
The chromosome extraction specifically comprises the following steps: respectively in each region of the neighborhood set
Figure FDA0003393361060000045
Randomly selecting a point PmAll of PmConstituting a chromosome chr, chr ═ (P)1,P2,P3,P4) (ii) a The chromosome code is specifically: will PmIn that
Figure FDA0003393361060000046
One-dimensional pixel coordinate of (1) is recorded as Lm,0≤Lm<(2 delta +1) × (2 delta +1), 0. ltoreq. delta. ltoreq.15, for LmCarry out 10-bit binary coding to obtain code word CmThe 40-bit code word of the chromosome chr is: 230C1+220C2+210C3+C4
Step 3.3, the population initialization specifically comprises the following steps: according to the chromosome extraction method in step 3.2, in the neighborhood set
Figure FDA0003393361060000047
Co-extracting popsize chromosomes to form an initial population of genetic algorithm (chr)k1, …, popsize }, wherein
Figure FDA0003393361060000048
Coding each chromosome of the initial population according to the coding method in the step 3.2 to obtain a code word set { cs ] of the initial populationk1, …, popsize }, wherein
Figure FDA0003393361060000049
Figure FDA00033933610600000410
Is that
Figure FDA00033933610600000411
10 bit binary code word;
step 3.4, defining fitness function
Figure FDA00033933610600000412
quad is the four vertices of chromosome chr
Figure FDA00033933610600000413
A quadrangle formed by the four corners, n is an image
Figure FDA00033933610600000414
The number of character pixels in the middle quadrangle quad, namely the number of white point pixels; s is the area of the quadrilateral quad.
6. The method for correcting character perspective based on genetic optimization algorithm as claimed in claim 1, wherein the genetic algorithm Inter _ gen processing in step 4 is specifically implemented according to the following steps:
step 4.1, inputting: control parameter, chromosome inception population { chrk1, …, popsize }, fitness function, text region
Figure FDA0003393361060000051
Character frame Ri(ii) a Defining chromosome population variable set in genetic algorithm iteration process as oldtopi,oldpopi={oldchri k1, …, popsize }, for oldchri kAssigning an initial value, oldchri k=chrk(ii) a Optimal chromosome Chr in genetic algorithm iterative processi bestInitialisation to NULL, Chri bestAdaptation value Chr ofi bestFitness is initialized to 0; defining an iteration variable as j, and initializing to 1;
step 4.2, calculating oldPopiOf each chromosome
Figure FDA0003393361060000052
Counting the number n of character pixel points in the quadrilateral area corresponding to the quadrilateral area s, and counting
Figure FDA0003393361060000053
oldchri kN and s as inputs, calling the fitness function
Figure FDA0003393361060000054
Calculated to obtain oldchri kIs of the fitness value oldchri k.fitness;
Step 4.3, according to Roulette selection method Roulette _ Choosing (), the cluster of the population oldhop is treatediThe individuals in the population are subjected to importance sampling to obtain a new population newporti={newchri k|k=1,…,popsize};
The specific execution process of Roulette _ Chooning () is as follows:
step 4.3.1, calculate individual oldchri kSelection probability P (oldchr)i k): for population oldtopiFitness oldchr of all individuals in Chinai kThe total fitness of the population is obtained by the fitness summation
Figure FDA0003393361060000055
P(oldchri k)=oldchri k.fitness/Fit;
Step 4.3.2, calculating population individual oldchri kAccumulated probability of (2)
Figure FDA0003393361060000056
Figure FDA0003393361060000057
4.3.3, performing popsize importance sampling on the individual, wherein the importance sampling process comprises the following steps: in the interval [0,1]In which a uniformly distributed random number r is generatediIf, if
Figure FDA0003393361060000058
Then the population individual oldchri 1Selecting the selected plants; if it is
Figure FDA0003393361060000059
Then the population individual oldchri kSelected, new population newportiConsisting of sampled popsize individuals, i.e., newpotsi={newchri k|k=1,…,popsize};
Step 4.4, carrying out newport on the new population according to the cross rate pcrossiPerforming cross genetic operation on the individuals in the population, and updating the newport population by using all the individuals after the cross genetic operationi
Step 4.4.1, in the newport of the populationiRandomly selecting popsize multiplied by pcross individuals to carry out pairwise genetic cross operation, wherein the cross genetic operation comprises the following specific processes: respectively in two individuals2 in the code word39,238,…,230Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words29,228,…,220Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words19,218,…,210Randomly selecting 4 bits from the bits for exchange operation, and respectively carrying out {2 ] operation in two individual code words9,28,…,20Randomly selecting 4 bits from the bits for exchange operation; updating the newport of the population by using individuals after cross operationi
4.4.2, error correction processing of illegal code words after cross genetic operation:
the population after cross genetic operation is newcropi={newchri k1, …, popsize, each chromosome newchri kThe 40-bit code word is Cchri k,
Figure FDA0003393361060000061
Wherein
Figure FDA0003393361060000062
Is the mth 10-bit code word of the corresponding kth chromosome; for code word
Figure FDA0003393361060000063
And (3) carrying out illegal judgment and error correction: combining binary code words
Figure FDA0003393361060000064
Decimal number conversion to obtain
Figure FDA0003393361060000065
If it is not
Figure FDA0003393361060000066
Then it is considered that
Figure FDA0003393361060000067
Is notA normal code word, a
Figure FDA0003393361060000068
Linear transformation to
Figure FDA0003393361060000069
Figure FDA00033933610600000610
Where int () is a rounding function,
Figure FDA00033933610600000611
the error-corrected code word is
Figure FDA00033933610600000612
A 10 bit binary number of;
step 4.5, carrying out newport on the populationiPerforming mutation genetic operation on each chromosome in the new crop plant, and performing newcrop plant operation on all the individuals after mutationiUpdating is carried out; calculating the number of variation digits H according to the variation rate calculationbit,HbitPopsize × 40 × precipitation, population newport by number of mutationsiPerforming genetic variation operation on all individuals in the group; if the number of the mutation is less than 1, not carrying out mutation; otherwise, carrying out mutation operation; the mutation operation process comprises the following steps: in {239,238,…,20H is randomly selected between the digit numbersbitThe bits are varied, with a variation of 1 for a value of 0 and a variation of 0 for a value of 1;
according to the illegal code word error correction processing method in the step 4.4.2, the newport is processed to the populationiAll 10-bit code words under each chromosome are subjected to illegal judgment and error correction to obtain an error-corrected population
Figure FDA00033933610600000613
Step 4.6, updating population variable oldtopi,oldpopi=newpopi(ii) a At oldpostiSelecting individual pair population oldtop with maximum fitnessiOptimum chromosome Chr in (1)i maxThe value is assigned to the value to be assigned,
Figure FDA00033933610600000614
Figure FDA0003393361060000071
optimal chromosome Chr in iterative process of genetic algorithmi bestUpdating: if Chri max.fitness>Chri bestFitness, then Chri best=Chri max(ii) a If Chri max.fitness≤Chri bestFitness, no processing is done;
step 4.7, j equals j + 1; if J is less than or equal to J, entering the step 4.2; if J is larger than J, ending the iteration process, and entering a step 4.8;
step 4.8, chromosome Chri bestOptimal chromosome Chr found for the end of the Inter _ GenProcessing iteration of the genetic algorithmi best=(Pi best1,Pi best2,Pi best3,Pi best4),Chri bestThe quadrangle enclosed by four points is the best outer-packaging quadrangle of the character area and is marked as
Figure FDA0003393361060000072
7. The character perspective correction method based on the genetic optimization algorithm as claimed in claim 1, wherein the step 5 of character region perspective correction is implemented according to the following specific steps:
step 5.1, according to the quadrangle
Figure FDA0003393361060000073
Four vertices P ofi best1,Pi best2,Pi best3,Pi best4Calculating a corresponding correction rectangle
Figure FDA0003393361060000074
Wherein P isi best1、w+And h+Respectively correspond to
Figure FDA0003393361060000075
Top left vertex of (1), width and height;
w+,h+the calculation is as follows:
Figure FDA0003393361060000076
Figure FDA0003393361060000077
w+=max(hor0,hor1);
Figure FDA0003393361060000078
Figure FDA0003393361060000079
h+=max(ver0,ver1);
where max () is a maximum function;
handle
Figure FDA00033933610600000710
And
Figure FDA00033933610600000711
as input, calling open source OpenCV library function getPerfectTransform (), and calculating to obtain perspective transformation matrix Hi
Step 5.2, calculating
Figure FDA0003393361060000081
External box
Figure FDA0003393361060000082
Handle
Figure FDA0003393361060000083
And CImgAs input, calling the OpenCV library function cvSetImageROI () of open source to obtain CImgExtracted from
Figure FDA0003393361060000084
Corresponding region of interest image
Figure FDA0003393361060000085
To pair
Figure FDA0003393361060000086
In the middle do not belong to
Figure FDA0003393361060000087
The pixel value of (a) is subjected to a 0 operation,
Figure FDA0003393361060000088
the coordinates of the inner pixel points are marked as (x, y), the pixel values are marked as P (x, y), if
Figure FDA0003393361060000089
Then P (x, y) is 0;
step 5.3, define the corrected image variable as
Figure FDA00033933610600000810
Handle
Figure FDA00033933610600000811
Figure FDA00033933610600000812
And HiCalling openCV library function warp Perspective () of an open source as input, and calculating to obtain
Figure FDA00033933610600000813
Corrected image
Figure FDA00033933610600000814
CN201910777441.5A 2019-08-22 2019-08-22 Character perspective correction method based on genetic optimization algorithm Active CN110598832B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910777441.5A CN110598832B (en) 2019-08-22 2019-08-22 Character perspective correction method based on genetic optimization algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910777441.5A CN110598832B (en) 2019-08-22 2019-08-22 Character perspective correction method based on genetic optimization algorithm

Publications (2)

Publication Number Publication Date
CN110598832A CN110598832A (en) 2019-12-20
CN110598832B true CN110598832B (en) 2022-05-03

Family

ID=68855287

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910777441.5A Active CN110598832B (en) 2019-08-22 2019-08-22 Character perspective correction method based on genetic optimization algorithm

Country Status (1)

Country Link
CN (1) CN110598832B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111103801B (en) * 2019-12-31 2022-05-17 芜湖哈特机器人产业技术研究院有限公司 Mobile robot repositioning method based on genetic algorithm and mobile robot
CN112200181B (en) * 2020-08-19 2023-10-10 西安理工大学 Character shape approximation method based on particle swarm optimization algorithm
CN112465809B (en) * 2020-12-15 2023-05-05 北京市计算中心有限公司 Mold defect detection method based on image recognition, computer readable storage medium and device

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102375982A (en) * 2011-10-18 2012-03-14 华中科技大学 Multi-character characteristic fused license plate positioning method
US8539349B1 (en) * 2006-10-31 2013-09-17 Hewlett-Packard Development Company, L.P. Methods and systems for splitting a chinese character sequence into word segments
CN103914996A (en) * 2014-04-24 2014-07-09 广东小天才科技有限公司 Method and device for acquiring character learning data from picture
CN104899852A (en) * 2014-03-03 2015-09-09 西南科技大学 Miniature particle detection system calibration method based on genetic algorithm and support vector machine
CN106407883A (en) * 2016-08-10 2017-02-15 北京工业大学 Complex table and method for identifying handwritten numbers in complex table
CN106446896A (en) * 2015-08-04 2017-02-22 阿里巴巴集团控股有限公司 Character segmentation method and device and electronic equipment
CN109359656A (en) * 2018-10-10 2019-02-19 甘肃万维信息技术有限责任公司 A kind of licence plate recognition method based on particle swarm algorithm optimization neural network
CN109800746A (en) * 2018-12-05 2019-05-24 天津大学 A kind of hand-written English document recognition methods based on CNN

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6957200B2 (en) * 2001-04-06 2005-10-18 Honeywell International, Inc. Genotic algorithm optimization method and network

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8539349B1 (en) * 2006-10-31 2013-09-17 Hewlett-Packard Development Company, L.P. Methods and systems for splitting a chinese character sequence into word segments
CN102375982A (en) * 2011-10-18 2012-03-14 华中科技大学 Multi-character characteristic fused license plate positioning method
CN104899852A (en) * 2014-03-03 2015-09-09 西南科技大学 Miniature particle detection system calibration method based on genetic algorithm and support vector machine
CN103914996A (en) * 2014-04-24 2014-07-09 广东小天才科技有限公司 Method and device for acquiring character learning data from picture
CN106446896A (en) * 2015-08-04 2017-02-22 阿里巴巴集团控股有限公司 Character segmentation method and device and electronic equipment
CN106407883A (en) * 2016-08-10 2017-02-15 北京工业大学 Complex table and method for identifying handwritten numbers in complex table
CN109359656A (en) * 2018-10-10 2019-02-19 甘肃万维信息技术有限责任公司 A kind of licence plate recognition method based on particle swarm algorithm optimization neural network
CN109800746A (en) * 2018-12-05 2019-05-24 天津大学 A kind of hand-written English document recognition methods based on CNN

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Perspective rectification of document images using fuzzy set and morphological operations;Shijian Lu 等;《Image and Vision Computing》;20050101;第23卷(第5期);第541-553页 *
Text recognition from image using artificial neural network and genetic algorithm;Mohit Agarwal等;《ICGCIoT》;20160114;第1610-1617页 *
自然场景中文字识别关键技术研究;何树有;《中国硕士学位论文全文数据库 信息科技辑》;20181015;第2018年卷(第10期);I138-841 *

Also Published As

Publication number Publication date
CN110598832A (en) 2019-12-20

Similar Documents

Publication Publication Date Title
CN110598832B (en) Character perspective correction method based on genetic optimization algorithm
CN111784747B (en) Multi-target vehicle tracking system and method based on key point detection and correction
CN108596197B (en) Seal matching method and device
CN109657612B (en) Quality sorting system based on facial image features and application method thereof
CN108133216B (en) Nixie tube reading identification method capable of realizing decimal point reading based on machine vision
CN110110608B (en) Forklift speed monitoring method and system based on vision under panoramic monitoring
CN107516316A (en) It is a kind of that the method that focus mechanism is split to static human image is introduced in FCN
CN114359998B (en) Identification method of face mask in wearing state
CN109190625B (en) Large-angle perspective deformation container number identification method
CN105405138B (en) Waterborne target tracking based on conspicuousness detection
CN104463814A (en) Image enhancement method based on local texture directionality
CN109781737A (en) A kind of detection method and its detection system of hose surface defect
CN114529925A (en) Method for identifying table structure of whole line table
CN111783773A (en) Correction method for angle-oriented inclined wire pole signboard
CN115641615A (en) Extraction method of closed palm interested region under complex background
CN107038432A (en) Fingerprint image orientation extracting method based on frequency information
CN114387592A (en) Character positioning and identifying method under complex background
CN113807180A (en) Face recognition method based on LBPH and feature points
CN106934395B (en) Rigid body target tracking method adopting combination of SURF (speeded Up robust features) and color features
CN112633070A (en) High-resolution remote sensing image building extraction method and system
Han et al. Locally adaptive contrast enhancement using convolutional neural network
CN110197184A (en) A kind of rapid image SIFT extracting method based on Fourier transformation
CN113159027B (en) Seven-segment digital display instrument identification method based on minimum external rectangular variant
CN110060243B (en) Dam surface crack framework extraction method
CN112183650A (en) Digital detection and identification method under camera out-of-focus condition

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right

Effective date of registration: 20220414

Address after: Room 102, building 4 [8-3], courtyard 4, Sanjianfang Nanli, Chaoyang District, Beijing 100020

Applicant after: Beijing Qingteng Culture Co.,Ltd.

Address before: 710048 Shaanxi province Xi'an Beilin District Jinhua Road No. 5

Applicant before: XI'AN University OF TECHNOLOGY

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant
PE01 Entry into force of the registration of the contract for pledge of patent right

Denomination of invention: A text perspective correction method based on genetic optimization algorithm

Effective date of registration: 20220628

Granted publication date: 20220503

Pledgee: Beijing first financing Company limited by guarantee

Pledgor: Beijing Qingteng Culture Co.,Ltd.

Registration number: Y2022110000141

PE01 Entry into force of the registration of the contract for pledge of patent right