A kind of liquid level detection device and method thereof based on machine vision
Technical field
The present invention relates to a kind of liquid level detection device and method thereof based on machine vision.
Technical background
Level Detection is meant with certain method the height of liquid is measured.This technology is widely used in many aspects such as Energy Saving Control of daily life, commercial production, oil transportation, power house and urban sewage motor.
The water level detecting of present stage is broadly divided into contact and contactless two kinds of methods.The one, adopt float type level gauge, float type level gauge belongs to mechanical mode, easy break-down.The 2nd, adopt the pressure resistance type fluid level transmitter, liquid level is detected, this detection method is to leave the proportional principle of distance of liquid level and design according to the pressure in somewhere under the liquid level and its.That uses at present be imported product mostly, and price is high, and vulnerability to jamming is relatively poor, and the impurity in the non-linear and liquid of device influences very big to measuring accuracy, and when for example the clear water of sustained height and the water that contains silt being detected, testing result is different.Simultaneously because detecting device directly contacts with fluid to be measured, cause detection means itself by the objectionable impurities erosion, influenced accuracy of detection and serviceable life, thereby to a certain degree limit its range of application.
In contactless pick-up unit, ultrasound wave is arranged at present, infrared ray, laser liquid-level measuring device table etc.Wherein ultrasound wave is representative, and the ultrasonic liquid level measuring instrument has non-contacting characteristics, and dependable performance has practical value, thereby becomes a developing direction of Level Detection instrument, all obtains comparatively general and deep research and the application of light at home and abroad.But; Receive the restriction of factors such as own characteristic (as receive influence of temperature change is big, the analog quantity conversion accuracy is not enough, the influence of fluctuations of examined liquid level is bigger), the ultrasonic liquid level measuring instrument is difficult to reach high precision in the wide range scope; Installation requirement is high; Need the professional to install, and when the detection liquid level had suspension, foam, fluctuation, accuracy of detection significantly reduced.
Summary of the invention
The objective of the invention is to propose a kind of liquid level detection device and method thereof based on machine vision, should have noncontact based on the liquid level detection device and the method thereof of machine vision, vulnerability to jamming is strong, characteristics such as measuring accuracy height.
Technical solution of the present invention is following:
A kind of liquid-level detecting method based on machine vision may further comprise the steps:
Step 1: the measurement coordinate that camera is set; Measuring coordinate is a dimension coordinate of vertical direction;
Step 2: adopt master scale to demarcate to measuring coordinate;
Step 3: the image that includes background and liquid through camera collection;
Step 4: through Digital Image Processing, liquid in the image and background are separated, obtain the level value in the image;
Step 5: level value in the combining image and calibrated measurement coordinate finally obtain the actual liquid level value.
The concrete steps of step 2 are:
Steps A: the adjustment camera guarantees that the liquid level change direction is for measuring the axial of coordinate;
Step B: the maximum height of selecting liquid level change is for measuring the summit of coordinate; The summit of liquid level change is aimed in the upper end that will have the scale of master scale; Scale vertically is provided with;
Step C: measure scale to the place ahead of camera wheel measuring coordinate and adjustment, the scale on the measurement coordinate and the master scale of scale are promptly accomplished the demarcation of measuring coordinate on time, and at this moment, the angle θ of rotation of coordinate measured in record; Remove scale; Described rotational coordinates moves and rotating camera in perpendicular promptly;
The concrete steps of step 5 are following:
The position at camera place is O, and in the measurement coordinate before demarcation, the highs and lows of liquid level change is respectively A and B, in calibrated measurement coordinate, the corresponding B of B point ", A and B distinguish corresponding A ' and B ' point in the imaging plane of camera; " point is current liquid level point in the calibrated measurement coordinate to C, and AC " is the actual liquid level height; OC " intersects at C point and C ' point respectively with straight line AB and straight line A ' B '; Triangle OAB is an isosceles triangle, OA=OB;
AC=kA ' C ', wherein k is known constant for the imaging scale-up factor; A ' C ' is AC " to project to the pixels tall in the imaging plane, representes initial detecting value when A ' C ' is measuring liquid level with the number of pixel;
In the △ OAC, AO, AC, ∠ OAC are known, obtain ∠ OCA, "=180 °-∠ OCA so ∠ ACC according to the trigonometric function relation;
In △ ACC ', known ∠ ACC ", limit AC and ∠ CAC " is angle θ, then by formula AC "/sin (∠ ACC ")=AC/sin (180 °-θ-∠ ACC ") tries to achieve AC " value.
Described rotational coordinates moves and rotating camera in perpendicular promptly; Concrete principle is following:
Suppose camera vertically to the coordinate imaging, and liquid level is pressed the direction variation of coordinate, because camera can not immerse in the water; Measurement range has only the part (such as half the) of coordinate in the image, in order to enlarge measurement range, must on move camera; And make axial line (being the light path of the incident light of camera lens) and the surface level θ at an angle of camera lens of camera, and rotated the θ angle, this process also can regard as camera not moving axes be that fixed point is rotated an angle θ forward with the summit; The variation range 0-90 degree of θ is if we calculate coordinate from various rotation θ between the 0-90 degree in advance, when actual measurement; As long as know that actual liquid level changing value more than three is (such as mating with scale; A plurality of scales are arranged on the scale, mainly accomplish high-precision coupling-i.e. calibration), just can confirm θ; Also just confirmed actual liquid level change coordinate, and prepared for follow-up liquid level change value of trying to achieve reality provides technology.
In the detection every width of cloth original image at first being carried out distortion correction handles.
A kind of liquid level detection device based on machine vision, camera is connected with data processing module through A/D converter; Have the Digital Image Processing unit that is used for being partitioned into liquid level line in the data processing module, also have the computing unit that is used for calculating the actual liquid level value in the data processing module according to aforesaid liquid-level detecting method based on machine vision from digital picture.
Described camera is an infrared camera.
Described data processing module is the UT6410CV05 core board.
Beneficial effect:
Liquid level detection device and method thereof based on machine vision of the present invention, the on-the-spot liquid level picture that will obtain through infrared camera obtains the real-time elevation information of liquid level, thereby detects the instant height of liquid level through algorithm process.Five big algorithms of autonomous Design have been used for elevation information, this device that accurately, efficiently obtains liquid level: camera distortion correction algorithm, self-adapting detecting setting coordinate algorithm, liquid level line partitioning algorithm, data filtering and data pacing algorithm.
The maximum originality of the present invention be embodied in adopt dexterously rotation of coordinate (virtual rotation, be actually camera lens on move and rotate) mode of demarcating with coordinate (and be applied in camera tracing process to target the mode of coordinate demarcation) and combine basic geometrical principle to obtain the actual liquid level coordinate.
It is primary processor that this device adopts the ARM series monolithic, uses Color Liquid Crystal Display and touch-screen to be output input device, and that the interface section comprises is wired, wireless telecommunications control and video interface.This device computing is fast several times, real-time, and measuring accuracy is high, and volume is little, and Installation and Debugging are convenient, have good man computer interface.Owing to adopted the self-adaptation setting coordinate, this device not only is fit to open and/or enclosed Level Detection environment, also is applicable to plant equipment location and product counting, has very application prospects.
Liquid level detection device and method thereof based on machine vision of the present invention are considered the deficiency of traditional detection device and a kind of new detection technique that proposes just, have noncontact; Vulnerability to jamming is strong, and characteristics such as measuring accuracy height accomplish that a frame surveys more; Cost is low, simple installation, advantage such as failure rate is low.And, be convenient to selection because used equipment is general, the precision of detection is directly related with the computational accuracy of the pixel precision of selected video camera and algorithm, thereby can accuracy of detection as required cut the garment according to the figure, and saves cost.Particularly can be for having suspension, foam, liquid level that level fluctuation is strong to detect accurately.Can detect liquid level that flow, unglazed photograph, accomplish unmanned continual detection in 24 hours simultaneously.Can implement remote monitoring through wireless device detects; Like river, pond etc.; Alleviated monitor staff's workload, and can in flood-fighting, estimate water level, this is to commercial production, industrial detection, flood-fighting, urban sewage, urban water supply; Accurately detecting provides a kind of novel, stable and detection means efficiently, and the development of society is had major and immediate significance.
Description of drawings
Fig. 1 is the schematic diagram based on the liquid level detection device of machine vision of embodiment of the present invention.
Fig. 2 is coordinate calibration principle figure.
Embodiment
Below will combine accompanying drawing and specific embodiment that the present invention is explained further details:
Embodiment 1:
With reference to Fig. 1; This liquid level detection device based on machine vision is an embedded equipment; Comprise like the lower part: infrared camera or camera, embedded pick-up unit; Comprise liquid crystal display and touch-screen, wire-wireless communication interface and control interface etc., Level Detection is with reference to backboard, detected object.
In this instance, adopt embedded system, adopt (SuSE) Linux OS, ARM11 is a master chip, the data of processing collected in the system.Touch-screen, colour/black-and-white crystal display screen are adopted in embedded liquid level detection device man-machine interaction.Utilize touch-screen to set systematic parameters such as early warning liquid level.Utilize LCDs to show liquid level numerical value and liquid level change curve.Utilize wired and wireless module that the image information that collects is sent to system's memory module.Utilization has image distortion correction algorithm, self-adaptation setting coordinate algorithm, liquid level line partitioning algorithm and Position Tracking algorithm to collect the liquid level image information.Use data filtering algorithm, data pacing algorithm, background to suppress the exact position that algorithm is obtained the liquid level image.
The method of present embodiment has following applying step:
Image that camera is taken the photograph is carried out distortion correction:
1. choice criteria polychrome grid picture; Each uses camera or camera vertically forms images to normal pictures; Obtain distortion partial pixel point off-set value behind this camera or the camera imaging after relatively with normal pictures, form the distortion correction table, at first proofread and correct before every width of cloth liquid level picture processing in the detection.Distortion correction has guaranteed the authenticity of pending picture, has promptly guaranteed measuring accuracy
2. the structuring one-dimensional coordinate axially is the liquid level change direction, and scale is pixel n; The n value is (0,1,2; 3 ...) in arbitrary integer, the more for a short time coordinate precision that shows of numerical value is high more; When coordinate transform, can introduce round-off error but value is too little, according to the resolution of camera, n generally chooses 5-20 pixel; Actual pitch between every scale can be dwindled because of far and near proportional amplification of imaging picture, is that initial point forwards rotates the 0-90 degree to coordinate system with the axle upper end then, can obtain coordinate system such as figure one under the corresponding various angle).In the actual measurement process; At first adjust camera, guarantee that the liquid level change direction is the axial of coordinate, selecting the maximum height of liquid level change is the summit of coordinate; Put one contain the accurate scale of several case markers scale on the liquid level change top; Choosing of master scale is according to the user requirement of measuring accuracy to be set, and scale is measured in wheel measuring coordinate and adjustment then, when changes in coordinates is consistent with the master scale scale of setting; Just obtained the coordinate system of level gauging, can remove the master scale scale this moment.After camera is installed; The method of this rotation of coordinate coupling can obtain measuring liquid level change coordinate in the picture very soon; Overcome in the past according to pixel on-site proving manpower and materials that liquid level line will spend; If liquid level can not change from the peak to the minimum point fast, pixel on-site proving method is the calibration measurements coordinate immediately.Method of the present invention can be proofreaied and correct very soon when camera is moved.
3. liquid level line is cut apart: utilize the variation of gray-scale value and change in color that liquid level line is cut apart; When physical environment can not the stable segmentation liquid level line; Usually add a white detection backboard, make liquid and background that bigger gray value differences arranged, guarantee accurately cutting apart of liquid level line.
4. the image filtering of cutting apart is handled, calculating real-time liquid level h1 compares with the liquid level h2 that gathered last time; Obtain liquid level change rate v,, need to gather once again and calculate as v during greater than the maximum rate of change Vmax that sets; As satisfy condition, then collection result is effective, saving result.
Data communication and control: the liquid level testing result sends to host computer through wired or wireless mode, gets into control flow simultaneously, according to demand external device (ED) is controlled.This embedded equipment can be preserved calculating and the control result who surpasses 1,000,000 times, can be through touch screen query.
Concrete applying step is following:
Embedded-type ARM video liquid level detector is gathered the liquid level image by the infrared camera that is fixed on top, liquid level zone, through AV collection plate (being A/D converter) image is transferred to arm processor and handles.Treatment scheme is following: distortion is proofreaied and correct to camera; Set up converted coordinate; Images acquired, image pre-service (filtering is reduced), image segmentation, Image Edge-Detection, liquid level line extract then, calculate liquid level, estimate and proofread and correct liquid level, LCD shows liquid level.
Software is made up of camera distortion correction algorithm, self-adapting detecting setting coordinate algorithm, liquid level line partitioning algorithm, data filtering and data pacing algorithm.
It is following to set demarcation coordinate step:
A) structuring one-dimensional coordinate axially is the liquid level change direction, and scale is pixel n; The n value is (0,1,2; 3 ...) in arbitrary integer, the more for a short time coordinate precision that shows of numerical value is high more; When coordinate transform, can introduce round-off error but value is too little; According to the resolution of camera, n generally chooses 5-20 pixel, and the actual pitch between every scale can be dwindled because of far and near proportional amplification of imaging picture.
B) according to different measuring accuracy n is demarcated, scale carries out convergent-divergent in proportion; Actual pitch between every scale can be dwindled because of far and near proportional amplification of imaging picture
C) coordinate system is an initial point when forwards rotating 0-90 and spending with the axle upper end, obtains the coordinate system under the corresponding various angle.
The spotting scaming step is following:
A) adjustment camera guarantees that the liquid level change direction is the axial of coordinate;
B) selecting the maximum height of liquid level change is the summit of coordinate;
C) be provided with one contain the accurate scale of several case markers scale on the liquid level change top;
D) peak of a master scale in liquid level to be measured being set, is 1cm like the field requirement precision, and the scale of 20cm and the peak of liquid level to be measured are set; The wheel measuring coordinate when the variation of measuring coordinate is consistent with the 20cm variation of setting, shows that the anglec of rotation matees; And adjustment measurement scale, calculate the shared pixel of every 1cm spacing, when the changes in coordinates top is consistent with the 20cm master scale scale of setting; When 20 calibration points all one by one at once, just obtained the coordinate system of level gauging;
E) removable master scale scale;
F) adopt Position Tracking algorithm keeps track liquid level change;
Use photographing module to be input to system memory unit with different liquid level images of positions set collections and through communication module.
Use background to suppress algorithm and remove the disturbing factor in the background.Background suppresses algorithm and belongs to a kind of filtering algorithm; Being made up of dynamic and static filtering, mainly is stationary object and the moving object that filtering influences measurement result, like the teat of background or the thing that lands at random; The method of this filtering belongs to prior art, but uses all characteristic.
Suppress actual liquid level information and the Position Tracking algorithm that algorithm decomposites in conjunction with demarcation coordinate, background, calculate the actual liquid level height.Its ultimate principle is seen accompanying drawing 2.
As shown in Figure 2: the visual angle of video camera is ∠ AOB (is definite value, can be obtained by camera parameter), and AB is a scale, and the imaging plane A ' B ' of AB parallel vidicon.Suppose that A, B are the end points up and down of the plane of delineation, promptly AB is the imaging scope of camera, and OA=OB is arranged, so triangle OAB is an isosceles triangle, thus can obtain the value of ∠ OAB and ∠ OBA, and ∠ OBA=∠ OAB.In addition, behind angle θ of scale AB rotation, be designated as AB ", AB=AB is then arranged ".Set up an office on the C " for AB " more arbitrarily, some C ' be C " projection on imaging plane, some C is straight line OC " and the intersection point of AB.
Now target is to calculate AC according to A ' C ' and other known conditions and triangle relation " length.
Solution procedure is following:
Because ∠ AOB is known, AB also is known, and triangle OAB is isosceles triangle, thus can obtain OA, promptly
Therefore camera can obtain the true altitude of AC according to pixels tall A ' C ' perpendicular to plane AB again.(, can see linear) because the object image-forming distortion is less under the vertical condition
In the △ OAC, AO, AC, ∠ OAC are known, can obtain ∠ OCA, "=180 °-∠ OCA so ∠ ACC according to the trigonometric function relation.
In △ ACC ', known ∠ ACC ", limit AC, the true altitude that " is angle θ, then can calculates limit AC " like known ∠ CAC according to trigonometric function.By sine, AC "/sin (∠ ACC ")=AC/sin (180 °-θ-∠ ACC ") can be in the hope of AC " value.