{'fraction_non_alphanumeric': 0.025389994620763853, 'fraction_numerical': 0.006024744486282948, 'mean_word_length': 4.724137931034483, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Device for optical monitoring of the level and volume of liquid in a tank

The article reviews theoretical base and practical implementation of device, that allows to perform optical control of level and volume of tank filling with liquid. The device implements a method, based on analysis of liquid’s mirror image. This image is shot with a camera, randomly installed in the tank. The method is also based on tank’s sectional areas data at various filling levels. Mathematical model presented in the article establishes relationship between parameters described and target values of tank level and volume. To confirm theoretical principles, there are presented results of experimental research. Experimental studies were carried out using a prototype device, monitoring level and volume of a cylindrical tank, with a diameter of 700 mm and a height of 1000 mm.


Introduction
Optical methods of measurement of the level and volume of liquid in a tank [1][2][3][4][5] have a number of advantages, in particular, being non-contact and providing high measurement speed. We have previously proposed a method of measurement [1] for measuring the volume of liquid in a tank, as well as automatically adjusting the tank geometry at its first filling with liquid. The objective of this study is to develop a method that would serve as a basis for creation of a complete non-contact optical device for measuring the level and volume of liquid in a tank.
There is a number of known devices for liquid level measurement [1][2][3], which use laser light sources to cast bright spots onto the surface of liquid and to detect their position with a camera. Knowing the geometric parameters of the optical system and the coordinates in pixels on the device light-sensitive matrix, it is possible to obtain the distance from the camera to the surface of the liquid: if the height of the camera above the tank bottom is known, calculation of the filling level becomes a trivial task.
The tank geometry must be known in order to measure the liquid volume. Typically, liquid volume is calculated using the known tank filling level by using a tank-specific calibration table where the volume for each known filling level is specified. Preparation of calibration tables is a time-consuming process that requires emptying and filling the tank completely using additional metering equipment. We have proposed [1,6] a method for measuring the volume of liquid in a tank that does not require any pre-made calibration tables, as calibration tables for the tank are created automatically upon the first filling with liquid. The method is based on the fact that the liquid forms a light-reflecting shape along the line of contact with the tank wall due to surface tension forces. This contact line between the liquid and the wall (liquid/wall contact line, LWCL) is visible regardless of the properties of the When developing a mathematical model, both for level and volume measurements, the parameters of the camera optics were considered to be known values. In actual practice, the focal length of the lens is subject to change. First of all, parameters of the optical system are affected by humidity and temperature. In addition, if there is a significant change in the liquid level, the system must be refocused to achieve the maximum image clarity, as it is high image clarity that makes it possible to obtain the maximum resolution of the system as a whole. Figure 1 shows the structural arrangement of the device. Laser beams create spots and LWCL on the liquid surface. They are clearly distinguishable in the image and are used for further calculations, for which the algorithms given in [2,7] can be used. Several laser light sources can be used to improve the accuracy of the liquid level measurement; this study employed a configuration with two lasers in order to improve accuracy. The filling volume is measured as follows. During the first filling, the device registers the liquid level after some time. The cross-sectional area formed by the liquid during the filling is determined by using the LWCL. In such a fashion, as the tank is progressively filled, a table with section areas for each level is automatically generated and stored in the device's memory. This table is used for calculating the total product volume. This approach has an advantage of automatic calibration of the tank. Such calibration is carried out in the system at each filling and emptying, which increases accuracy, and also makes it possible to monitor changes in the tank geometry during its operation. This tank geometry monitoring becomes particularly important in transportation of petroleum products and hazardous liquids, e.g. in railway tank cars and sea tankers.  In addition, reference pieces, which are reflectors of a special shape that can be easily distinguished from other objects, should be present in the camera field of view. The mathematical model being developed assumes that the reference pieces are located in a plane parallel to the ground. In order to determine the necessary parameters, at least 4 reference pieces R1...R4 are necessary.

Theoretical part
The origin of coordinates (indicated O in the figure) is the focal point of the camera, the optical axis of the camera is aligned with the axis z. It should be noted that the light sensitive matrix is for convenience positioned in front of the point O, which is true due to the similarity of triangles. The reference pieces R1-R4 with coordinates R1 ( To determine the three-dimensional coordinates of the reference pieces, it is necessary to solve the system (1). Taking into account the problem statement, the distance f, as well as three-dimensional coordinates of points R1-R4, are unknown values. It is also known that the reference pieces are positioned within one plane described by the equation Px · x+Py · y+Pz · z+1=0. It should be noted that the plane equation is also written in the camera-bound coordinate system, so Pz is also unknown. Taking into account the plane coefficients, 16 unknown values are obtained; therefore, the system contains 16 equations. Known values are the coordinates of the projections of all points onto the matrix and the distance between the reference pieces Lij, where i, j are sequential numbers of the reference pieces.
The first four equations represent the Pythagorean theorem in three-dimensional space, the next four lines represent eight equations from the similarity of triangles, the last four equations reflect the positioning of the reference pieces within the same plane. This system is easily reduced by substitutions to a system with four unknown values, which can be solved by numerical methods.
Next, the solution of the system determines the parameters of the plane Hx, Hy, Hz in which the liquid is located. The laser light source creates a parallel optical axis. Assume the beam shift along the x axis relative to the optical axis is known and is AX, the beam shift along the y axis offset is AY, the distance f and parameters PX, PY, PZ are known from the above system.
The unknown values in the system are the parameters HX, HY, HZ and AZ. Then, taking into account the known height of the installation of the reference pieces relative to the bottom hR and using the known formulas for finding the distance between parallel planes, the filling level h is found:  After determining the filling level, the current surface area of the liquid in the tank is determined. The LWCL is the perimeter of this area. In order to achieve this, an array of pixel coordinates is recognized in the image received from the camera Gn'(Gx,n',Gy,n'), then the system of equations is used to calculate the coordinates Gn (Gx, n, Gy, n, Gz, n) in three-dimensional space.
The next step is to determine the surface area of the liquid, for which the array of coordinates of recognized LWCL pixels Un'(Ux,n',Uy,n') on the image is converted into volume coordinates of points Un (Ux,n,Uy,n,Uz,n) (4) After determining the three-dimensional coordinates by summing the area of the triangles, the total surface area of the liquid is determined. Knowing the surface area Si at height i in increments Δh, the filling level is calculated by integrating:

Practical significance
In the course of practical experiments, a prototype model was created on the basis of a single-lens reflex camera with a matrix of 22.3 x 14.9 mm and a resolution of 18 megapixels, the focal length of the lens was f = 18 mm. The experiments performed made it possible for us to estimate the full-scale error of volume measurement, which, with a free positioned of the camera within the tank, was 0.5% for a cylindrical tank with a diameter of 700 mm and a height of 1000 mm.

Conclusion
The advantages of the proposed measurement method are not limited to automatic monitoring of liquid volume in the tank, but also include the possibility of detecting dangerous deformations of the geometry of the tanks, which can prevent accidents with filling with petroleum products. The developed mathematical model with an arbitrary position of the camera relative to the tank simplifies the initial system layout and also provides for the development of mobile measuring equipment that can be used for batch measurements with several tanks at once.