Rapid trapezoidal correction method for image of biological characteristic photoelectric scanning device
Technical Field
The invention belongs to the technical field of biological identification, and particularly relates to a rapid trapezoidal correction method for images of a biological characteristic photoelectric scanning device.
Background
The technology for automatically identifying and determining the identity of the person by collecting biological characteristics such as fingerprints, palmprints, faces, irises and the like in a photoelectric scanning mode has the advantages of convenient operation and no wound and is widely applied to the fields of security authentication, financial payment, attendance management, public security criminal investigation and the like, the biological identification is generally that an electronic device scans a specific part of a human body to obtain digitalized information data, the digitalized information data is sent to an upper computer to extract characteristic points, a sample library is searched, and each prestored sample is compared, so that the identity of the person is determined.
In the prior art, the biological characteristic optical scanning device mainly comprises an optical system, a photoelectric camera chip, a data processor, a memory and an upper computer interface, wherein the optical system consists of a series of optical lenses, a mechanical device is arranged in a light path of the acquisition device to image emergent rays of a human body scanning part to a light sensitive surface of the photoelectric camera chip, the processor caches image data output by the photoelectric chip into the memory and forwards the image data to the upper computer for characteristic recognition through the upper computer interface, and the output image always has drum distortion, pincushion distortion, trapezoidal distortion, rotation distortion and other conditions due to the existence of mechanical errors of the optical system, and various distortions can affect each other.
In use, the image digital correction technology is used for correcting the mechanical error of an original distorted image and improving the accuracy of the image, for example, the distorted image is multiplied by a correction matrix by a matrix method to realize the correction of the image, and because each pixel for generating the correction image needs to calculate the multiplication of the times of the product of the width and the height of the image and the addition of the times of the product of the width and the height of the image, a high-end processor with a hardware floating point multiplier is needed to be capable of working with huge calculation, the existing image quick correction methods capable of realizing low-cost devices mainly adopt a mode of extracting the nearest point pixel, the image quality output by the method is not high enough, the image can generate saw-tooth distortion in some areas, and even the image with some broken shapes is distorted, so the method for quickly correcting the trapezium of the image of the biological characteristic photoelectric scanning device is provided for the problems.
Disclosure of Invention
In order to overcome the defects of the prior art, the method for quickly rectifying the images of the low-cost device mainly adopts a mode of extracting the nearest point pixels, and the method has the advantages that the output image quality is not high enough, saw-tooth distortion can occur in some areas of the image, and even the image distortion with some fracture shapes can occur.
The invention solves the technical problems by adopting the technical scheme that the rapid trapezoidal correction method for the image of the biological characteristic photoelectric scanning device comprises the following steps:
The method comprises the steps of S1, setting a standard jig on a scanning device by a worker, displaying a scanning image of the jig by using a software real-time display photoelectric camera chip on a computer, manually adjusting mechanical parameters of a light path, preferentially reducing drum distortion, pincushion distortion and rotation distortion, and for trapezoidal distortion, not correcting the trapezoidal distortion too much, only clicking four corners of an edge trapezoid in a selected jig image by using a mouse manually to serve as four correction control points, and then sending coordinates of the correction control points to the scanning device for permanent storage;
S2, in the stage of generating correction control information, a processor in a scanning device calculates a group of data for correcting an image according to the stored coordinates of correction control points, the data is stored in a random memory, the group of image correction data is called as image correction information, the calculation amount is large when the image correction information is generated, but the calculation is only carried out once when the scanning device is reset and started, so that the actual use requirement can be met by using a low-cost processor, and the result data generated by the calculation, namely the image correction information, is required to be repeatedly and rapidly acquired in the stage of scanning image correction output, so that the correction information data is required to be stored in the random memory which can be rapidly read;
And S3, in the scanning image correction output stage, a processor in the scanning device calculates distorted image data of the photoelectric camera chip by utilizing image correction information, converts the distorted image data into an image with qualified error and outputs the image to a host computer or the processor, wherein the process is a main function execution process of the scanning device and is in a state of repeated and cyclic execution, and the process is required to have higher execution efficiency, so that excessive time-consuming complex calculation such as floating point division and the like cannot exist.
Preferably, in the production deviation correction setting stage, a scanning device is connected with a computer, a standard jig with the size equal to the size of a scanning window of equipment is placed on the scanning device, production test software is operated on the computer, and jig images obtained by shooting of a photoelectric camera chip are displayed in real time;
When the scanned image is distorted, the grid in the jig pattern can be used for visually observing the position of the distorted area of the scanning acquisition optical path, and prompting the direction of the fine adjustment machine when the distortion is used for correcting mechanical errors;
The production deviation correcting setting firstly adjusts the mechanical position of the optical train, although the image distortion is difficult to thoroughly eliminate, the mechanical position is adjusted as much as possible to reduce the distortion, the smaller the mechanical adjustment is, the more beneficial to improving the quality of the final output deviation correcting image, the drum distortion, the pincushion distortion and the rotation distortion are preferentially reduced, and the trapezoidal distortion does not need to be corrected excessively, and the adjustment is required to be carried out until all four vertexes of the rectangular jig are displayed in the scanned image.
Preferably, the four vertexes of the original jig are A, B, C and D respectively, the four vertexes E, F, G and H respectively correspond to the four vertexes of the original jig in a scanning image displayed on a computer through a scanning device, mechanical adjustment is required to enable EF lines and GH lines in the scanning image to be horizontal straight lines, EG lines and FH lines are not required to be vertical only to be straight lines, and thus an image formed by the vertexes E, F, G and H is any trapezoid with the upper bottom edge and the lower bottom edge in the horizontal direction;
and on the interface of the production test software, clicking four vertexes of the selected rectangular jig on the scanning image by using a mouse as deviation rectifying control points, and then transmitting coordinates of the four deviation rectifying control points on the jig scanning image to a scanning device by using the production test software, and permanently storing the coordinates in the device to finish production deviation rectifying setting.
Preferably, in the stage of generating the correction control information, the width of an original image acquired by the photoelectric camera chip is W 1, the height is H 1, the width of an output image after the original image is reduced and corrected is W 2, and the height is H 2;
the correction control information generation stage is to calculate a set of correction data by utilizing coordinates of four correction control points of a jig scanning image stored in a device in the production correction setting stage and store the correction data in a random memory of scanning equipment, wherein the correction data comprises three groups of information including top total loss data information, horizontal total loss line information and trapezoidal horizontal fusion line information;
The top total loss data information has only one numerical value, which is represented by GT and is equal to the number of pixels on the upper side of an EF line in a jig scanning chart, although mechanical adjustment is required to enable the EF line and GH of the jig scanning chart to be horizontal, errors exist in actual production, namely, the numerical values of E Y and F Y of an E point coordinate (E X,EY) and an F point coordinate (F X,FY) are different, so the calculation method of the top total loss data information is as follows:
Also, because of the machine model error, the values of G Y and H Y of the G point coordinate (G X,GY) and the H point coordinate (H X,HY) are different, and the method for calculating the trapezoid height LN is as follows;
The horizontal full-line-loss information comprises three data, namely a horizontal full-line-loss number TC, a horizontal full-line-loss number array TA and a horizontal full-line-loss marking array TS, wherein the horizontal full-line-loss number TC is a numerical value which represents the number of the horizontal lines reduced in the vertical reduction process of the image, the number of the definition elements is equal to H 1 minus the horizontal full-line-loss number array TA of H 2, and the number of the effective data actually stored is equal to TC;
The trapezoid horizontal fusion line information comprises a one-dimensional pixel coordinate array PS with the number of members equal to the width W 2 multiplied by the height H 2 and an array PL with the number of elements equal to H 2, wherein each element in the array PL is a data structure comprising two members, and the two members are respectively a line start coordinate SS and a line width WS.
Preferably, the specific execution steps of generating the deviation rectifying control information are as follows:
A1, setting all elements of a horizontal full-loss line marking array TS to be zero, setting the number TC of the horizontal full-loss line to be zero, calculating top full-loss data information GT and trapezoid height LN, defining a constant XN, wherein the larger the value of the XN is, the more beneficial to improving the precision, the overflow occurs if the binary bit number of a result obtained by XN is H 2 exceeds the bit width of a processor, and the precision is not obviously improved after the XN exceeds 16 times of the image width, so that the value of the XN must not be excessively large, for example, the XN can be set to be equal to 1000000 in a 32-bit processor;
a2, defining a variable LB, a variable LS and a variable yTar, and setting initial values to be equal to zero;
A3, defining a variable SP, and setting an initial value as XN;
a4, defining variables U, V and W, wherein the variables U, V and W are used for storing temporary calculation intermediate results;
A5, defining a variable STEP, and setting a numerical value as a numerical value;
a6, after adding STEP to the SP, if the value of the SP is larger than XN, executing the STEP A7, otherwise executing the STEP A11;
A7, shifting LS by four bits left, multiplying G X, saving the result in a variable U, shifting LN minus LS by four bits left, multiplying LN by E X, saving the result in a variable V, using yTar as an index of an array PL, representing PL [ yTar ], calculating the result of dividing LN by the variable U and adding variable V, and saving the result in a member SS of PL [ yTar ];
A8, shifting LS by four bits left, multiplying by H X, and storing the result in a variable U, shifting LN minus LS by four bits left, multiplying by F X, and storing the result in a variable V;
a9, taking yTar as an index of the array PL, and saving the numerical value of the member SS of the calculated variable W minus PL [ yTar ] to the member WS of the PL [ yTar ];
A10, subtracting XN from the SP, accumulating yTar to 1, and then executing A13;
A11, if yTar is greater than or equal to H 2, directly executing A12, otherwise, using yTar as an array TS of index, using TS [ yTar ] to indicate, and executing A12 after setting TS [ yTar ] to 1;
A12, taking TC as an array TA of an index, using TA [ TC ] to represent, calculating a variable LS, subtracting a value of a variable LB, and storing the value of the variable LS into the variable LB;
A13, comparing the sizes of the variables LS and LN, if LS is smaller than LN, executing the step A6, otherwise executing the step A14;
a14, setting a variable yTar to zero, defining a variable xTar;
a15, setting the value of the variable xTar to be zero;
A16, in the array PL with yTar as index, calculating the number value of member WS of PL [ yTar ] multiplied by variable xTar, dividing by W 2, adding the number value of member SS of PL [ yTar ] and storing in variable U;
A17, multiplying the calculated variable yTar by W 2, adding the numerical value of the variable xTar, and storing the numerical value in a variable V;
a18, the pixel coordinate array PS taking variable V as index is expressed by PS [ V ], and the value of PS [ V ] is set to be equal to variable U;
A19, accumulating the variables xTar to 1, if the value of the variable xTar is smaller than W 2, executing the step A16, otherwise executing the step A20;
A20, accumulating the variable yTar to 1, if the value of the variable yTar is smaller than H 2, executing the step A15, otherwise, completing the deviation rectifying control information stage.
Preferably, in the stage of correcting and outputting the scanned image, when the image data stream is processed, an original image is generated by a photoelectric chip in the scanning device, the original image enters a random memory RAM1 through a bus for temporary storage, the original image is changed into a corrected image after being processed by a processor, and then the corrected image is stored in a random memory RAM2 again and is sent to an upper computer interface by a bus output interface, the random memory RAM1 and the RAM2 can be two different memories or two different address spaces of the same memory, and the transmission of the original image and the corrected image is usually completed in a DMA mode;
The image speed adaptation of the original image and the deviation correcting image adopts the same strategy, the details of specific steps are different, the common point is that three image buffer areas are defined, only data are written in and data are read out for the operation of each buffer area at any moment, and three kinds of idle operation are realized, namely, the writing operation and the reading operation can not be simultaneously executed for one buffer area;
The photoelectric chip triggers the DMA1 to send original image data to the RAM1, the bus output interface triggers the DMA2 to send deviation correcting image data to the upper computer interface, the priority of the DMA1 is higher than that of the DMA2, when the DMA1 starts to transmit the last byte of an original image, the DMA1 is triggered to execute the interrupt 1 service processing step, when the DMA2 starts to transmit the last byte of a deviation correcting image, the DMA2 is triggered to execute the interrupt 2 service processing step, the priority of the interrupt 1 is set to be higher than that of the interrupt 2, thus the priority of the DMA and the interrupt is set to ensure that the situation that image splicing and breaking cannot occur even if the data processing or output speed is lower than the acquisition speed of the photoelectric chip;
The method comprises the steps of sending original image data of a photoelectric chip to a RAM1 through a DMA1, executing a data reading step in a main program loop of a processor, converting the original image data into deviation correcting image data by using the deviation correcting data, after storing the deviation correcting image data in the RAM2, executing a data sending step, sending the data to an upper interface by using the DMA2, and mainly dividing the three processes of original image speed adaptation, deviation correcting image output adaptation and deviation correcting processing.
Preferably, the original image speed adaptation usually adopts global variables as coordination to realize the process of the steps of RAM1, DMA1, interrupt 1 and data reading in a linkage way, specifically, a one-dimensional array BUF1 with three elements is defined, the three elements respectively store the initial addresses of three image cache areas in the RAM1 and are respectively represented by BUF1[0], BUF1[1] and BUF1[2 ];
The service processing step of the interrupt 1 is used for switching the original image buffer area, on one hand, the buffer area is prepared for the DMA1 to start to newly save an original image data, and on the other hand, the latest saved image data is prepared for the data reading step, and the specific steps are as follows;
b1, after accumulating the variable WR1 by 1, if the value of WR1 is larger than 2, setting WR1 to be zero;
b2, if the value of WR1 is equal to the value of RD1, executing the step B1, otherwise, executing the step B3 downwards;
B3, taking WR1 as an index of a plurality of groups of BUF1, and representing BUF1[ WR1], wherein the numerical value is the initial address of the original image buffer;
b4, sending the value of BUF1[ WR1] to the DMA1 controller, and after the DMA1 controller is started, exiting the interrupt 1 service to complete the service processing step of the interrupt 1;
the data reading step comprises the following steps of;
c1, comparing the values of the variables WR1 and RD1, if the values are equal, the original image data is not available for reading, so that the process directly exits, otherwise, executing the step C2;
c2, defining a variable R, and setting an initial value equal to WR1;
C3, subtracting one from the value of the variable R, and setting the value of R to be 2 if the value of R is smaller than zero;
C4, setting the value of the variable RD1 to be equal to the value of R;
C5, taking RD1 as an index of the array BUF1, and representing by BUF1[ RD1], wherein the numerical value is the starting address of the latest original image data and is sent to the correction processing process.
Preferably, the correction image speed adaptation usually adopts global variables as coordination to realize the process of the linkage operation of the steps of RAM2, DMA2, interrupt 2 and data transmission, specifically defining a one-dimensional array BUF2 with three elements, wherein the three elements respectively store the initial addresses of three image cache areas in the RAM2 and are respectively represented by BUF2[0], BUF2[1] and BUF2[2 ];
The service processing step of the interrupt 2 is used for switching the deviation correcting image buffer area, on one hand, preparing a buffer area for the DMA2 to newly send a deviation correcting image data, and on the other hand, preparing a buffer area for writing the deviation correcting image data into the safest buffer area in the data sending step, and the specific steps are as follows;
D1, after accumulating the values of the variables RD2 by 1, setting RD2 to be zero if the values of RD2 are larger than 2;
D2, if the value of RD2 is equal to the value of WR2, the result shows that the speed of the DMA2 is higher than the correction processing process, and no correction image data needs to be sent, the service processing of the interrupt 2 can be directly exited, otherwise, the step D3 is executed;
D3, taking RD2 as an index of the array BUF2, and representing by BUF2[ RD2], wherein the numerical value is the starting address of the latest correction image data and is sent to the DMA2 controller;
d4, exiting the interrupt 2 service after starting the DMA2 to start transmitting data, and completing the service processing step of the interrupt 2;
The data transmission step comprises the following steps of;
E1, taking WR2 as an index of an array BUF2, and representing with BUF2[ WR2], wherein the numerical value is a buffer initial address for storing correction data in the RAM 2;
E2, storing the latest deviation correcting image data into a buffer area corresponding to the BUF2 WR2 value;
E3, after the BUF2[ WR2] value is sent to the DMA2 controller, starting the DMA2 to start sending data;
e4, after accumulating the numerical value of the variable WR2 by 1, if the value of WR2 is larger than 2, setting the value of WR2 to be zero;
e5, comparing the values of the variable WR2 and the variable RD2, if the values are equal, executing the step E4, otherwise, completing data transmission;
Meanwhile, in the main program loop of the processor, correction processing needs to be executed, wherein the correction processing process is as follows:
F1, acquiring an original image from the RAM1 by using a data reading step, and re-executing the step F1 if a new image cannot be acquired;
f2, calculating correction data of the original image data to generate a correction image;
f3, after the deviation correction image is stored in the RAM2, executing a data transmission step;
f4, after the data transmission step is completed, the image data transmission is not required to be completed, and the step F1 is re-executed;
F1 to F4 are executed in an infinite loop, when the acquisition speed of the original image data is higher than the operation speed of the correction data, the original image speed is adapted to ensure that the original image data cannot be spliced and broken by new and old data, and when the interface speed of the upper computer is lower than the correction image speed, the correction image speed is adapted to ensure that the image data received by the upper computer cannot be spliced and broken by new and old data;
Calculating and generating a correction image by using correction data;
g1, defining a variable x and a variable y, and setting all the variables to zero;
g2, defining a variable TW and setting the value of TW to be equal to the top total loss data information GT;
g3, defining a variable TLE, a variable TLD, a variable TLU and a variable PUC, and adding TL to the initial address of the original image;
G4, taking the value of TL as an address in the RAM1 to obtain a horizontal full-missing line number, multiplying the horizontal full-missing line number by the width W 1 of the original image, adding the numerical value of the variable TW, and then storing the numerical value into the variable TW and the variable PUC again;
g5, adding the value of the variable TW to the width W 1 of the original image, and then saving the value of the variable TW to the variable TLE and the variable TLD;
g6, obtaining the value of the variable PUC as the address of the RAM1, and obtaining the pixel CA of the original image from the RAM 1;
G7, obtaining the value of the variable TLU as the address of the RAM1, obtaining the pixel CB of the original image from the RAM1, after calculating the average value CC of CA and CB, re-storing CC back to the TLU value as the storage address of the RAM 1;
G8, obtaining the value of the variable TLD as the address of the RAM1, obtaining the pixel CD of the original image from the RAM1, after calculating the average value CE of CA and CD, saving CE back to the TLD value as the storage address of the RAM 1;
After accumulating the variable PUC by 1, if the value of the variable PUC is smaller than the variable PLE, executing the step G6, otherwise executing the step G10;
G10, after accumulating the variable TL by 1, adding 1 to the value of the variable y, if the value of the variable y is smaller than the horizontal total loss line number TC, executing the step G4, otherwise, executing the step G11;
G11, defining a variable I, setting an initial value and the like to be zero, defining a variable PT, and setting the value of the variable PT to be equal to the initial address of the deviation correcting image data;
G12, defining a variable TX, and setting the value of the variable TX to be equal to the value of the initial address of the original image data plus the top total loss data information GT;
g13, setting the value of the variable y to be zero;
g14, using variable y as index of horizontal full-missing line mark array TS, using TS [ y ] to represent, if TS [ y ] value is not equal to zero, increasing the value stored by variable TX by W 1;
g15, setting the value of the variable x to zero;
g16, taking variable I as index of pixel coordinate array PS, using PS [ I ] to obtain value IX of PS [ I ], storing the value obtained by calculating that the binary lowest 4 bits of IX are all cleared as ILEFT, and storing the value obtained by calculating that the binary lowest 4 bits of IX are all 1 as IRIGHT;
G17, shift ILEFT to the right by 4 bits, add the value of variable TX, then use it as the address in RAM1 to obtain one pixel VL of the original image, shift IRIGHT to the right by 4 bits, add the value of variable TX, then use it as the address in RAM1 to obtain one pixel VR of the original image;
g18, after accumulating the values of the variable I by 1, calculating IX minus ILEFT to be XL, calculating IX minus IRIGHT to be XR, and calculating VAL;
VAL=VR*XL-VL*XR
G19, after the VAL is shifted to the right by 4 bits, storing the VAL in a deviation correcting image buffer area taking PT as an RAM2 address;
G20, adding 1 to the value of the variable x after accumulating 1 to the value of PT, if the value of the variable x is not more than the width W 2 of the correction image, executing the step G17, otherwise executing the step G18;
g21, after adding the value of the variable TX to the original image width W 1, saving the value in the variable TX again;
And G22, after accumulating the value of the variable y by 1, if the value of the variable y is smaller than the correction image H 2, executing the step G14, otherwise, completing the correction processing process, switching to executing the data transmission step, and transmitting the correction image to an upper computer interface.
The beneficial effects of the invention are as follows:
1. the invention provides a rapid trapezoid correction method for an image of a biological characteristic photoelectric scanning device, when the acquisition speed of original image data is higher than the calculation speed of correction data, the original image speed is adapted to ensure that the original image data cannot be spliced and broken by new and old data, and when the interface speed of an upper computer is lower than the correction image speed, the correction image speed is adapted to ensure that the image data received by the upper computer cannot be spliced and broken by new and old data.
2. The invention provides a rapid trapezoid correction method for images of a biological characteristic photoelectric scanning device, which comprises the steps of triggering an interrupt 2, switching to execute an interrupt 2 service processing step, setting the priority of the interrupt 1 to be higher than that of the interrupt 2, and setting the priority of DMA and the interrupt so as to ensure that the situation that the image is spliced and broken even if the data processing or output speed is lower than the acquisition speed of a photoelectric chip can be avoided.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this specification, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute a limitation on the application. In the drawings:
FIG. 1 is a flow chart of a method according to a first embodiment;
Fig. 2 is a scanning diagram of the jig according to the first embodiment.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
Example 1
Referring to fig. 1-2, the method for quickly correcting the trapezoid of the image of the biological feature photoelectric scanning device comprises the following steps:
The method comprises the steps of S1, setting a standard jig on a scanning device by a worker, displaying a scanning image of the jig by using a software real-time display photoelectric camera chip on a computer, manually adjusting mechanical parameters of a light path, preferentially reducing drum distortion, pincushion distortion and rotation distortion, and for trapezoidal distortion, not correcting the trapezoidal distortion too much, only clicking four corners of an edge trapezoid in a selected jig image by using a mouse manually to serve as four correction control points, and then sending coordinates of the correction control points to the scanning device for permanent storage;
S2, in the stage of generating correction control information, a processor in a scanning device calculates a group of data for correcting an image according to the stored coordinates of correction control points, the data is stored in a random memory, the group of image correction data is called as image correction information, the calculation amount is large when the image correction information is generated, but the calculation is only carried out once when the scanning device is reset and started, so that the actual use requirement can be met by using a low-cost processor, and the result data generated by the calculation, namely the image correction information, is required to be repeatedly and rapidly acquired in the stage of scanning image correction output, so that the correction information data is required to be stored in the random memory which can be rapidly read;
And S3, in the scanning image correction output stage, a processor in the scanning device calculates distorted image data of the photoelectric camera chip by utilizing image correction information, converts the distorted image data into an image with qualified error and outputs the image to a host computer or the processor, wherein the process is a main function execution process of the scanning device and is in a state of repeated and cyclic execution, and the process is required to have higher execution efficiency, so that excessive time-consuming complex calculation such as floating point division and the like cannot exist.
In the production deviation correcting setting stage, a scanning device is connected with a computer, a standard jig with the size equal to the size of a scanning window of equipment is placed on the scanning device, production test software is operated on the computer, and jig images obtained by shooting of a photoelectric camera chip are displayed in real time;
When the scanned image is distorted, the grid in the jig pattern can be used for visually observing the position of the distorted area of the scanning acquisition optical path, and prompting the direction of the fine adjustment machine when the distortion is used for correcting mechanical errors;
The production deviation correcting setting firstly adjusts the mechanical position of the optical train, although the image distortion is difficult to thoroughly eliminate, the mechanical position is adjusted as much as possible to reduce the distortion, the smaller the mechanical adjustment is, the more beneficial to improving the quality of the final output deviation correcting image, the drum distortion, the pincushion distortion and the rotation distortion are preferentially reduced, and the trapezoidal distortion does not need to be corrected excessively, and the adjustment is required to be carried out until all four vertexes of the rectangular jig are displayed in the scanned image.
The four vertexes of the original jig are A, B, C and D respectively, the four vertexes E, F, G and H respectively correspond to the four vertexes of the original jig in a scanning image displayed on a computer through a scanning device, mechanical adjustment is required to enable EF lines and GH lines in the scanning image to be horizontal straight lines, EG lines and FH lines are not required to be vertical only to be straight lines, and thus an image formed by the vertexes E, F, G and H is any trapezoid with the upper bottom edge and the lower bottom edge in the horizontal direction;
and on the interface of the production test software, clicking four vertexes of the selected rectangular jig on the scanning image by using a mouse as deviation rectifying control points, and then transmitting coordinates of the four deviation rectifying control points on the jig scanning image to a scanning device by using the production test software, and permanently storing the coordinates in the device to finish production deviation rectifying setting.
In the stage of generating correction control information, the width of an original image acquired by a photoelectric camera chip is W 1, the height of the original image is H 1, the width of an output image after the original image is reduced and corrected is W 2, and the height of the output image is H 2;
the correction control information generation stage is to calculate a set of correction data by utilizing coordinates of four correction control points of a jig scanning image stored in a device in the production correction setting stage and store the correction data in a random memory of scanning equipment, wherein the correction data comprises three groups of information including top total loss data information, horizontal total loss line information and trapezoidal horizontal fusion line information;
The top total loss data information has only one numerical value, which is represented by GT and is equal to the number of pixels on the upper side of an EF line in a jig scanning chart, although mechanical adjustment is required to enable the EF line and GH of the jig scanning chart to be horizontal, errors exist in actual production, namely, the numerical values of E Y and F Y of an E point coordinate (E X,EY) and an F point coordinate (F X,FY) are different, so the calculation method of the top total loss data information is as follows:
Also, because of the machine model error, the values of G Y and H Y of the G point coordinate (G X,GY) and the H point coordinate (H X,HY) are different, and the method for calculating the trapezoid height LN is as follows;
The horizontal full-line-loss information comprises three data, namely a horizontal full-line-loss number TC, a horizontal full-line-loss number array TA and a horizontal full-line-loss marking array TS, wherein the horizontal full-line-loss number TC is a numerical value which represents the number of the horizontal lines reduced in the vertical reduction process of the image, the number of the definition elements is equal to H 1 minus the horizontal full-line-loss number array TA of H 2, and the number of the effective data actually stored is equal to TC;
The trapezoid horizontal fusion line information comprises a one-dimensional pixel coordinate array PS with the number of members equal to the width W 2 multiplied by the height H 2 and an array PL with the number of elements equal to H 2, wherein each element in the array PL is a data structure comprising two members, and the two members are respectively a line start coordinate SS and a line width WS.
The specific implementation steps of generating the deviation rectifying control information are as follows:
A1, setting all elements of a horizontal full-loss line marking array TS to be zero, setting the number TC of the horizontal full-loss line to be zero, calculating top full-loss data information GT and trapezoid height LN, defining a constant XN, wherein the larger the value of the XN is, the more beneficial to improving the precision, the overflow occurs if the binary bit number of a result obtained by XN is H 2 exceeds the bit width of a processor, and the precision is not obviously improved after the XN exceeds 16 times of the image width, so that the value of the XN must not be excessively large, for example, the XN can be set to be equal to 1000000 in a 32-bit processor;
a2, defining a variable LB, a variable LS and a variable yTar, and setting initial values to be equal to zero;
A3, defining a variable SP, and setting an initial value as XN;
a4, defining variables U, V and W, wherein the variables U, V and W are used for storing temporary calculation intermediate results;
A5, defining a variable STEP, and setting a numerical value as a numerical value;
a6, after adding STEP to the SP, if the value of the SP is larger than XN, executing the STEP A7, otherwise executing the STEP A11;
A7, shifting LS by four bits left, multiplying G X, saving the result in a variable U, shifting LN minus LS by four bits left, multiplying LN by E X, saving the result in a variable V, using yTar as an index of an array PL, representing PL [ yTar ], calculating the result of dividing LN by the variable U and adding variable V, and saving the result in a member SS of PL [ yTar ];
A8, shifting LS by four bits left, multiplying by H X, and storing the result in a variable U, shifting LN minus LS by four bits left, multiplying by F X, and storing the result in a variable V;
a9, taking yTar as an index of the array PL, and saving the numerical value of the member SS of the calculated variable W minus PL [ yTar ] to the member WS of the PL [ yTar ];
A10, subtracting XN from the SP, accumulating yTar to 1, and then executing A13;
A11, if yTar is greater than or equal to H 2, directly executing A12, otherwise, using yTar as an array TS of index, using TS [ yTar ] to indicate, and executing A12 after setting TS [ yTar ] to 1;
A12, taking TC as an array TA of an index, using TA [ TC ] to represent, calculating a variable LS, subtracting a value of a variable LB, and storing the value of the variable LS into the variable LB;
A13, comparing the sizes of the variables LS and LN, if LS is smaller than LN, executing the step A6, otherwise executing the step A14;
a14, setting a variable yTar to zero, defining a variable xTar;
a15, setting the value of the variable xTar to be zero;
A16, in the array PL with yTar as index, calculating the number value of member WS of PL [ yTar ] multiplied by variable xTar, dividing by W 2, adding the number value of member SS of PL [ yTar ] and storing in variable U;
A17, multiplying the calculated variable yTar by W 2, adding the numerical value of the variable xTar, and storing the numerical value in a variable V;
a18, the pixel coordinate array PS taking variable V as index is expressed by PS [ V ], and the value of PS [ V ] is set to be equal to variable U;
A19, accumulating the variables xTar to 1, if the value of the variable xTar is smaller than W 2, executing the step A16, otherwise executing the step A20;
A20, accumulating the variable yTar to 1, if the value of the variable yTar is smaller than H 2, executing the step A15, otherwise, completing the deviation rectifying control information stage.
When the scanning image correction output stage faces to image data stream processing, an original image is generated by a photoelectric chip in the scanning device, the image data stream is temporarily stored in a random memory RAM1 through a bus, the original image is changed into a correction image after being processed by a processor, the correction image is stored in a random memory RAM2 again and then is sent to an upper computer interface by a bus output interface, the random memory RAM1 and the random memory RAM2 can be two different memories or two different address spaces of the same memory, and the transmission of the original image and the correction image is usually completed by adopting a DMA mode;
The image speed adaptation of the original image and the deviation correcting image adopts the same strategy, the details of specific steps are different, the common point is that three image buffer areas are defined, only data are written in and data are read out for the operation of each buffer area at any moment, and three kinds of idle operation are realized, namely, the writing operation and the reading operation can not be simultaneously executed for one buffer area;
The photoelectric chip triggers the DMA1 to send original image data to the RAM1, the bus output interface triggers the DMA2 to send deviation correcting image data to the upper computer interface, the priority of the DMA1 is higher than that of the DMA2, when the DMA1 starts to transmit the last byte of an original image, the DMA1 is triggered to execute the interrupt 1 service processing step, when the DMA2 starts to transmit the last byte of a deviation correcting image, the DMA2 is triggered to execute the interrupt 2 service processing step, the priority of the interrupt 1 is set to be higher than that of the interrupt 2, thus the priority of the DMA and the interrupt is set to ensure that the situation that image splicing and breaking cannot occur even if the data processing or output speed is lower than the acquisition speed of the photoelectric chip;
The method comprises the steps of sending original image data of a photoelectric chip to a RAM1 through a DMA1, executing a data reading step in a main program loop of a processor, converting the original image data into deviation correcting image data by using the deviation correcting data, after storing the deviation correcting image data in the RAM2, executing a data sending step, sending the data to an upper interface by using the DMA2, and mainly dividing the three processes of original image speed adaptation, deviation correcting image output adaptation and deviation correcting processing.
The method comprises the steps of starting the original image speed adaptation, namely defining a one-dimensional array BUF1 with three elements, wherein the three elements respectively store the initial addresses of three image cache areas in the RAM1, and the initial addresses are respectively represented by BUF1[0], BUF1[1] and BUF1[2 ];
The service processing step of the interrupt 1 is used for switching the original image buffer area, on one hand, the buffer area is prepared for the DMA1 to start to newly save an original image data, and on the other hand, the latest saved image data is prepared for the data reading step, and the specific steps are as follows;
b1, after accumulating the variable WR1 by 1, if the value of WR1 is larger than 2, setting WR1 to be zero;
b2, if the value of WR1 is equal to the value of RD1, executing the step B1, otherwise, executing the step B3 downwards;
B3, taking WR1 as an index of a plurality of groups of BUF1, and representing BUF1[ WR1], wherein the numerical value is the initial address of the original image buffer;
b4, sending the value of BUF1[ WR1] to the DMA1 controller, and after the DMA1 controller is started, exiting the interrupt 1 service to complete the service processing step of the interrupt 1;
the data reading step comprises the following steps of;
c1, comparing the values of the variables WR1 and RD1, if the values are equal, the original image data is not available for reading, so that the process directly exits, otherwise, executing the step C2;
c2, defining a variable R, and setting an initial value equal to WR1;
C3, subtracting one from the value of the variable R, and setting the value of R to be 2 if the value of R is smaller than zero;
C4, setting the value of the variable RD1 to be equal to the value of R;
C5, taking RD1 as an index of the array BUF1, and representing by BUF1[ RD1], wherein the numerical value is the starting address of the latest original image data and is sent to the correction processing process.
The correction image speed adaptation usually adopts global variables as coordination to realize the process of the linkage operation of the steps of RAM2, DMA2, interruption 2 and data transmission, specifically defines a one-dimensional array BUF2 with three elements, wherein the three elements respectively store the initial addresses of three image cache areas in the RAM2 and are respectively represented by BUF2[0], BUF2[1] and BUF2[2 ];
The service processing step of the interrupt 2 is used for switching the deviation correcting image buffer area, on one hand, preparing a buffer area for the DMA2 to newly send a deviation correcting image data, and on the other hand, preparing a buffer area for writing the deviation correcting image data into the safest buffer area in the data sending step, and the specific steps are as follows;
D1, after accumulating the values of the variables RD2 by 1, setting RD2 to be zero if the values of RD2 are larger than 2;
D2, if the value of RD2 is equal to the value of WR2, the result shows that the speed of the DMA2 is higher than the correction processing process, and no correction image data needs to be sent, the service processing of the interrupt 2 can be directly exited, otherwise, the step D3 is executed;
D3, taking RD2 as an index of the array BUF2, and representing by BUF2[ RD2], wherein the numerical value is the starting address of the latest correction image data and is sent to the DMA2 controller;
d4, exiting the interrupt 2 service after starting the DMA2 to start transmitting data, and completing the service processing step of the interrupt 2;
The data transmission step comprises the following steps of;
E1, taking WR2 as an index of an array BUF2, and representing with BUF2[ WR2], wherein the numerical value is a buffer initial address for storing correction data in the RAM 2;
E2, storing the latest deviation correcting image data into a buffer area corresponding to the BUF2 WR2 value;
E3, after the BUF2[ WR2] value is sent to the DMA2 controller, starting the DMA2 to start sending data;
e4, after accumulating the numerical value of the variable WR2 by 1, if the value of WR2 is larger than 2, setting the value of WR2 to be zero;
e5, comparing the values of the variable WR2 and the variable RD2, if the values are equal, executing the step E4, otherwise, completing data transmission;
Meanwhile, in the main program loop of the processor, correction processing needs to be executed, wherein the correction processing process is as follows:
F1, acquiring an original image from the RAM1 by using a data reading step, and re-executing the step F1 if a new image cannot be acquired;
f2, calculating correction data of the original image data to generate a correction image;
f3, after the deviation correction image is stored in the RAM2, executing a data transmission step;
f4, after the data transmission step is completed, the image data transmission is not required to be completed, and the step F1 is re-executed;
F1 to F4 are executed in an infinite loop, when the acquisition speed of the original image data is higher than the operation speed of the correction data, the original image speed is adapted to ensure that the original image data cannot be spliced and broken by new and old data, and when the interface speed of the upper computer is lower than the correction image speed, the correction image speed is adapted to ensure that the image data received by the upper computer cannot be spliced and broken by new and old data;
Calculating and generating a correction image by using correction data;
g1, defining a variable x and a variable y, and setting all the variables to zero;
g2, defining a variable TW and setting the value of TW to be equal to the top total loss data information GT;
g3, defining a variable TLE, a variable TLD, a variable TLU and a variable PUC, and adding TL to the initial address of the original image;
G4, taking the value of TL as an address in the RAM1 to obtain a horizontal full-missing line number, multiplying the horizontal full-missing line number by the width W 1 of the original image, adding the numerical value of the variable TW, and then storing the numerical value into the variable TW and the variable PUC again;
g5, adding the value of the variable TW to the width W 1 of the original image, and then saving the value of the variable TW to the variable TLE and the variable TLD;
g6, obtaining the value of the variable PUC as the address of the RAM1, and obtaining the pixel CA of the original image from the RAM 1;
G7, obtaining the value of the variable TLU as the address of the RAM1, obtaining the pixel CB of the original image from the RAM1, after calculating the average value CC of CA and CB, re-storing CC back to the TLU value as the storage address of the RAM 1;
G8, obtaining the value of the variable TLD as the address of the RAM1, obtaining the pixel CD of the original image from the RAM1, after calculating the average value CE of CA and CD, saving CE back to the TLD value as the storage address of the RAM 1;
After accumulating the variable PUC by 1, if the value of the variable PUC is smaller than the variable PLE, executing the step G6, otherwise executing the step G10;
G10, after accumulating the variable TL by 1, adding 1 to the value of the variable y, if the value of the variable y is smaller than the horizontal total loss line number TC, executing the step G4, otherwise, executing the step G11;
G11, defining a variable I, setting an initial value and the like to be zero, defining a variable PT, and setting the value of the variable PT to be equal to the initial address of the deviation correcting image data;
G12, defining a variable TX, and setting the value of the variable TX to be equal to the value of the initial address of the original image data plus the top total loss data information GT;
g13, setting the value of the variable y to be zero;
g14, using variable y as index of horizontal full-missing line mark array TS, using TS [ y ] to represent, if TS [ y ] value is not equal to zero, increasing the value stored by variable TX by W 1;
g15, setting the value of the variable x to zero;
g16, taking variable I as index of pixel coordinate array PS, using PS [ I ] to obtain value IX of PS [ I ], storing the value obtained by calculating that the binary lowest 4 bits of IX are all cleared as ILEFT, and storing the value obtained by calculating that the binary lowest 4 bits of IX are all 1 as IRIGHT;
G17, shift ILEFT to the right by 4 bits, add the value of variable TX, then use it as the address in RAM1 to obtain one pixel VL of the original image, shift IRIGHT to the right by 4 bits, add the value of variable TX, then use it as the address in RAM1 to obtain one pixel VR of the original image;
g18, after accumulating the values of the variable I by 1, calculating IX minus ILEFT to be XL, calculating IX minus IRIGHT to be XR, and calculating VAL;
VAL=VR*XL-VL*XR
G19, after the VAL is shifted to the right by 4 bits, storing the VAL in a deviation correcting image buffer area taking PT as an RAM2 address;
G20, adding 1 to the value of the variable x after accumulating 1 to the value of PT, if the value of the variable x is not more than the width W 2 of the correction image, executing the step G17, otherwise executing the step G18;
g21, after adding the value of the variable TX to the original image width W 1, saving the value in the variable TX again;
And G22, after accumulating the value of the variable y by 1, if the value of the variable y is smaller than the correction image H 2, executing the step G14, otherwise, completing the correction processing process, switching to executing the data transmission step, and transmitting the correction image to an upper computer interface.
In the description of the present specification, the descriptions of the terms "one embodiment," "example," "specific example," and the like, mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present invention. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
The foregoing has shown and described the basic principles, principal features and advantages of the invention. It will be understood by those skilled in the art that the present invention is not limited to the embodiments described above, and that the above embodiments and descriptions are merely illustrative of the principles of the present invention, and various changes and modifications may be made without departing from the spirit and scope of the invention, which is defined in the appended claims.