Image processing-based non-contact distance measuring method

文档序号:1534009 发布日期:2020-02-14 浏览:50次 中文

阅读说明:本技术 一种基于图像处理的非接触式测量间距的方法 (Image processing-based non-contact distance measuring method ) 是由 闵慧 艾米尔 强豪 张诚威 于 2019-11-18 设计创作,主要内容包括:本发明公开了一种基于图像处理的非接触式测量间距的方法,首先,激光扫描目标物体,将摄像头对准光线使物体出现在屏幕中间,抓拍图片image;对图片image进行图像预处理,得到光线图像gauss_gray;然后,削弱gauss_gray中的全部光线的强度,减少由于物体反射造成的误差,得到待处理的最亮光线图像narrow_img,去除图像中多余光线只留下测量间距的光线,用于计算缝隙实际距离;最后,通过图像X轴和Y轴的像素比计算所测间隙的像素值,与实际像素点代表的距离值进行公式换算,计算大于T的像素点数量,大于像素值的像素点视为缝隙所在位置。本发明无需搭建支撑固定摄像头与间距的距离,可以有效的测量出工业生产中的细小缝隙距离,提高了工业生产的工作效率,减少误差。(The invention discloses a non-contact distance measuring method based on image processing, which comprises the following steps of firstly, scanning a target object by laser, aligning a camera to light rays to enable the object to appear in the middle of a screen, and capturing a picture image; carrying out image preprocessing on the image to obtain a light ray image gauss _ gray; then, weakening the intensity of all light rays in the gauss _ gray, reducing errors caused by object reflection, obtaining a brightest light ray image narrow _ img to be processed, removing redundant light rays in the image, only leaving light rays at a measurement interval, and calculating the actual distance of the gap; and finally, calculating the pixel value of the measured gap according to the pixel ratio of the X axis and the Y axis of the image, performing formula conversion on the pixel value and the distance value represented by the actual pixel point, calculating the number of the pixel points larger than T, and regarding the pixel points larger than the pixel value as the positions of the gaps. According to the invention, the distance between the fixed camera and the interval is not required to be built, the distance of a small gap in industrial production can be effectively measured, the working efficiency of industrial production is improved, and the error is reduced.)

1. A method for measuring a distance in a non-contact mode based on image processing is characterized by comprising the following steps:

(1) scanning a target object by laser, aligning a camera with light rays to enable the object to appear in the middle of a screen, and capturing a picture image;

(2) carrying out image preprocessing on the image, and obtaining a ray image gauss _ gray by a gaussian filtering and gray processing method;

(3) performing image processing on the image gauss _ gray, weakening the intensity of all light rays in the gauss _ gray, reducing errors caused by object reflection, obtaining a brightest light ray image narrow _ img to be processed, removing redundant light rays in the image, only leaving light rays for measuring the distance, and calculating the actual distance of the gap;

(4) calculating the pixel value of the measured gap according to the pixel ratio of the X axis and the Y axis of the image, carrying out formula conversion on the pixel value and the distance value represented by the actual pixel point, defining the pixel value T, traversing and searching the pixels which are larger than T from the image along the positive direction and the negative direction of the X axis, traversing and searching the pixels which are larger than T along the positive direction and the negative direction of the Y axis, calculating the number of the pixels which are larger than T, and regarding the pixels which are larger than the pixel value as the position of the gap.

2. The image processing-based method for non-contact measurement of the distance according to claim 1, wherein the step (1) comprises the following steps:

(11) a green LED background lamp is used in the photographing process and is used for eliminating white noise and high-intensity laser beams under low illumination and increasing the laser line intensity under high illumination;

(12) the image is captured to enable a laser line to appear on a central viewpoint of the liquid crystal display, and the position of the laser on a target is positioned by a guide line and a circle;

(13) regulating the comfort level of human vision and image display by the gamma value, adjusting the image position, and capturing a circular image with the radius of 150mm by taking the center of the screen as the center of a circle.

3. The image processing-based method for measuring the distance in a non-contact manner according to claim 1, wherein the step (2) comprises the following steps:

(21) extracting a straight line from the Image as a horizontal line in a new Image, and defining the straight line as an X axis of the Image;

(22) generating a mask image through a numpy () function, generating a 640 × 480 matrix image through an np.zeros () function, filling the matrix image to 0 (black), and filling the image obtained in the step (1) in the ROI area to obtain an image out after mask processing;

(23) processing the image out through a GaussianBlur function to obtain a new _ frame of an image to be processed;

(24) processing the image new _ frame through a cvtColor function to obtain a gray level image gray to be processed;

(25) setting a threshold value through an inRange function to remove the background of the image gray, and obtaining a clear image mask _ white to be processed;

(26) and performing Gaussian filtering processing on the image mask _ white without the background through a Gaussian Blur function to obtain an image to be processed, namely, a gauss _ gray.

4. The image-processing-based method for non-contact measurement of the distance according to claim 1, wherein the step (3) comprises the steps of:

(31) defining a pixel value T, extracting a point of a light ray pixel value larger than T in the gauss _ gray image, changing the pixel value of the point lower than the threshold value into 0 (black), and obtaining an image narrow _ img;

(32) processing the image gauss _ gray through a Canny operator to obtain an image dst with straight light, and converting the image dst into an RGB image through a cvtColor () function;

(33) detecting the deformation of the straight line through a HoughLinesP () function, and finding out position points on two sides of the straight line before deformation;

(34) defining an angle between a position point and an X axis calculated by a function get _ angle (), and calculating radians of the position point and the X axis by an np.math.atan2() function;

(35) defining a function line _ angle () to call a function get _ angle () to determine the angle of the ray to the X-axis by calculating a position point;

(36) traversing along the X axis to find position points on two sides of the straight line, calculating the angle of the straight line, and deleting the straight line lower than 160 degrees in the image;

(37) counting the number of straight lines under the green background, and confirming two straight lines on the surface of the gap;

(38) and defining a function gap _ find () function to find two straight lines at the same angle, traversing pixel points of an X axis and a Y axis in the image, calculating the angle of the light, and finding two lights with the angle difference smaller than 10, namely the target light finally used for calculation.

5. The image-processing-based method for non-contact measurement of the distance according to claim 1, wherein the step (4) comprises the steps of:

(41) defining a function find _ gap _ middle () function to calculate the pixels of the gap, defining a pixel value T, traversing and searching pixel points which are larger than T from the midpoint of the image along the positive direction and the negative direction of an X axis, traversing and searching pixel points which are larger than T along the positive direction and the negative direction of a Y axis, and calculating the number of the pixel points which are larger than T;

(42) defining a function gap _ inside () to calculate the distance inside the gap;

(43) defining a function gap _ flush () to calculate the value of the gap depth;

(44) the value of the measure of the definition function excel () output is saved to the excel document.

Technical Field

The invention belongs to the technical field of laser ranging based on image processing, and particularly relates to a non-contact distance measuring method based on image processing.

Background

The traditional method for measuring the gap distance comprises the step of calculating the gap distance by measuring the capacitance or the current change, the traditional capacitance measuring method is used for measuring the capacitance formed by an insulated electrode and metal, the area where the capacitance changes is the gap distance to be measured, and the accurate gap distance is calculated by a time and speed formula. The method also comprises the steps of irradiating a measured object by two beams of laser with a certain included angle, acquiring a laser spot image reflected by the surface of the measured object by using an image sensor, obtaining the distance between two laser spots by analyzing and processing the image by an upper computer, and fitting the mathematical relationship between the distance between the light spots and the measured distance; the measuring mode is suitable for objects with large distance range, measured data can not be accurate to millimeter, error is about two centimeters, and the requirement for measuring small gaps can not be met. The traditional method has more influence factors on the measurement mode, can cause deviation of a final result, enhances the accuracy of distance calculation through processing a laser imaging graph, and effectively reduces errors in distance measurement through detecting the deformation of light.

Disclosure of Invention

The purpose of the invention is as follows: the invention provides a non-contact distance measuring method based on image processing, which enhances the precision and accuracy of gap measurement, improves the calculation speed by adding an image processing technology and weakens the influence of the external environment on the measurement result.

The technical scheme is as follows: the invention provides a non-contact distance measuring method based on image processing, which comprises the following steps:

(1) scanning a target object by laser, aligning a camera with light rays to enable the object to appear in the middle of a screen, and capturing a picture image;

(2) carrying out image preprocessing on the image, and obtaining a ray image gauss _ gray by a gaussian filtering and gray processing method;

(3) performing image processing on the image gauss _ gray, weakening the intensity of all light rays in the gauss _ gray, reducing errors caused by object reflection, obtaining a brightest light ray image narrow _ img to be processed, removing redundant light rays in the image, only leaving light rays for measuring the distance, and calculating the actual distance of the gap;

(4) calculating the pixel value of the measured gap according to the pixel ratio of the X axis and the Y axis of the image, carrying out formula conversion on the pixel value and the distance value represented by the actual pixel point, defining the pixel value T, traversing and searching the pixels which are larger than T from the image along the positive direction and the negative direction of the X axis, traversing and searching the pixels which are larger than T along the positive direction and the negative direction of the Y axis, calculating the number of the pixels which are larger than T, and regarding the pixels which are larger than the pixel value as the position of the gap.

Further, the step (1) includes the steps of:

(11) a green LED background lamp is used in the photographing process and is used for eliminating white noise and high-intensity laser beams under low illumination and increasing the laser line intensity under high illumination;

(12) the image is captured to enable a laser line to appear on a central viewpoint of the liquid crystal display, and the position of the laser on a target is positioned by a guide line and a circle;

(13) regulating the comfort level of human vision and image display by the gamma value, adjusting the image position, and capturing a circular image with the radius of 150mm by taking the center of the screen as the center of a circle.

Further, the step (2) comprises the steps of:

(21) extracting a straight line from the Image as a horizontal line in a new Image, and defining the straight line as an X axis of the Image;

(22) generating a mask image through a numpy () function, generating a 640 × 480 matrix image through an np.zeros () function, filling the matrix image to 0 (black), and filling the image obtained in the step (1) in the ROI area to obtain an image out after mask processing;

(23) processing the image out through a GaussianBlur function to obtain a new _ frame of an image to be processed;

(24) processing the image new _ frame through a cvtColor function to obtain a gray level image gray to be processed;

(25) setting a threshold value through an inRange function to remove the background of the image gray, and obtaining a clear image mask _ white to be processed;

(26) and performing Gaussian filtering processing on the image mask _ white without the background through a Gaussian Blur function to obtain an image to be processed, namely, a gauss _ gray.

Further, the step (3) includes the steps of:

(31) defining a pixel value T, extracting a point of a light ray pixel value larger than T in the gauss _ gray image, changing the pixel value of the point lower than the threshold value into 0 (black), and obtaining an image narrow _ img;

(32) processing the image gauss _ gray through a Canny operator to obtain an image dst with straight light, and converting the image dst into an RGB image through a cvtColor () function;

(33) detecting the deformation of the straight line through a HoughLinesP () function, and finding out position points on two sides of the straight line before deformation;

(34) defining an angle between a position point and an X axis calculated by a function get _ angle (), and calculating radians of the position point and the X axis by an np.math.atan2() function;

(35) defining a function line _ angle () to call a function get _ angle () to determine the angle of the ray to the X-axis by calculating a position point;

(36) traversing along the X axis to find position points on two sides of the straight line, calculating the angle of the straight line, and deleting the straight line lower than 160 degrees in the image;

(37) counting the number of straight lines under the green background, and confirming two straight lines on the surface of the gap;

(38) and defining a function gap _ find () function to find two straight lines at the same angle, traversing pixel points of an X axis and a Y axis in the image, calculating the angle of the light, and finding two lights with the angle difference smaller than 10, namely the target light finally used for calculation.

Further, the step (4) comprises the steps of:

(41) defining a function find _ gap _ middle () function to calculate the pixels of the gap, defining a pixel value T, traversing and searching pixel points which are larger than T from the midpoint of the image along the positive direction and the negative direction of an X axis, traversing and searching pixel points which are larger than T along the positive direction and the negative direction of a Y axis, and calculating the number of the pixel points which are larger than T;

(42) defining a function gap _ inside () to calculate the distance inside the gap;

(43) defining a function gap _ flush () to calculate the value of the gap depth;

(44) the value of the measure of the definition function excel () output is saved to the excel document.

Has the advantages that: compared with the prior art, the invention has the beneficial effects that: compared with the traditional laser ranging method, the method takes 0.79 seconds from the time of capturing a picture to the time of measuring the actual distance, can repeatedly measure for many times, and has the error of 0.01 mm.

Drawings

FIG. 1 is a flow chart of the present invention.

Detailed Description

The present invention is described in further detail below with reference to the attached drawings, it is to be understood that these examples are for the purpose of illustration only and are not intended to limit the scope of the invention, which is defined in the appended claims, and modifications thereof by those skilled in the art which are equivalent to the present invention will fall within the scope of the invention. As shown in fig. 1, the present invention comprises the steps of:

step 1: the laser scans a target object, the camera is aligned to light rays to enable the object to appear in the middle of the screen, and the image of the picture is captured.

Step 1.1: the green LED background light is used in the photographing process and used for eliminating white noise and high-intensity laser beams under low illumination and increasing the laser line intensity under high illumination.

Step 1.2: the snapshot image causes a laser line to appear on the central viewpoint of the liquid crystal screen, and the position of the laser on the target is positioned by using a guide line and a circle.

Step 1.3: regulating the comfort level of human vision and image display by the gamma value, adjusting the image position, and capturing a circular image with the radius of 150mm by taking the center of the screen as the center of a circle.

Step 2: and carrying out image preprocessing on the image, and obtaining a ray image gauss _ gray by a Gaussian filtering and gray processing method.

Step 2.1: a straight line is extracted from the Image as a horizontal line in the new Image, defined as the X-axis of the Image.

Step 2.2: a mask image is generated by a numpy () function, a 640 × 480 matrix image is generated by an np. zeros () function, and 0 (black) is filled in, and the image obtained in step 1 is filled in the ROI region, so that an image out after mask processing is obtained.

Step 2.3: and processing the image out through a GaussianBlur function to obtain a new _ frame of the image to be processed.

Step 2.4: and processing the image new _ frame through a cvtColor function to obtain a gray level image gray to be processed.

Step 2.5: and setting a threshold value through an inRange function to remove the background of the image gray, and obtaining the image mask _ white to be processed with clear light.

Step 2.6: and performing Gaussian filtering processing on the image mask _ white without the background through a Gaussian Blur function to obtain an image to be processed, namely, a gauss _ gray.

And step 3: and performing image processing on the image gauss _ gray, weakening the intensity of all light rays in the gauss _ gray, reducing errors caused by object reflection, obtaining a brightest light ray image narrow _ img to be processed, removing redundant light rays in the image, and only leaving light rays for measuring the distance for calculating the actual distance of the gap.

Step 3.1: defining a pixel value T, wherein T is 5, extracting a point of the gauss _ gray image with the light pixel value greater than 5, changing the pixel value of the point lower than the threshold value to 0 (black), and obtaining the laser image narrow _ img with weakened light brightness.

Step 3.2: the image gauss _ gray is processed through a Canny operator to obtain a straight-ray image dst, and the image dst is converted into an RGB image through a cvtColor () function.

Step 3.3: detecting the deformation of the straight line through a HoughLinesP () function, and finding out position points on two sides of the straight line before deformation; and finding out the position points on two sides of the straight line by taking 1 as a step length and pi/180 as an angle before deformation.

Step 3.4: defining a function get _ angle () to calculate the angle between the position point and the X-axis, and calculating the radian between the position point and the X-axis by np.

Step 3.5: defining a function line _ angle () calls a function get _ angle () to determine the angle of the ray to the X-axis by calculating the position point.

Step 3.6: and traversing along the X axis to find position points on two sides of the straight line, calculating the angle of the straight line, deleting the straight line below 160 degrees in the image, and considering the straight line as an invalid ray which cannot be used for target measurement.

Step 3.7: counting the number of straight lines under the green background, and confirming two straight lines on the surface of the gap; and (3) calculating the number of light rays in the final imaging, confirming whether two laser beams for ranging exist or not, returning to the step 3.3 if the detected number of the light rays is less than 2, and executing the next step if the number of the light rays is more than or equal to 2 and less than or equal to 4.

Step 3.8: and defining a function gap _ find () function to find two straight lines at the same angle, traversing pixel points of an X axis and a Y axis in the image, calculating the angle of the light, and finding two lights with the angle difference smaller than 10, namely the target light finally used for calculation.

And 4, step 4: and calculating the pixel value of the measured gap according to the pixel ratio of the X axis and the Y axis of the image, and performing formula conversion on the pixel value and the distance value represented by the actual pixel point to obtain real data of the measured distance.

Calculating the pixel value of the measured gap according to the pixel ratio of the X axis and the Y axis of the image, and performing formula conversion (1) and (2) on the pixel value and the distance value represented by the actual pixel point:

Figure BDA0002276903200000051

Figure BDA0002276903200000052

wherein x represents the gap distance, y represents the gap edge height difference, p represents the number of pixel points occupied by the gap, a represents the horizontal pixel value, n represents the horizontal pixel value, b represents the longitudinal pixel value, and m represents the longitudinal pixel value.

Step 4.1: defining a function find _ gap _ middle () function to calculate the pixels of the gap, defining a pixel value T, traversing from the midpoint of the image along the X axis in the positive direction and the negative direction to search for the pixels larger than T, traversing along the Y axis in the positive direction and the negative direction to search for the pixels larger than T, and calculating the number of the pixels larger than T. Defining a pixel value T to be 5, traversing 35 pixels along the positive direction and the negative direction of the X axis from the middle point (X/2, Y/2) of the image to search for pixels with pixel values larger than 5, traversing 25 pixels along the positive direction and the negative direction of the Y axis to search for pixels with pixel values larger than 5, and finally calculating the number of the pixels occupied by the pixels with pixel values larger than 5 in the transverse direction and the longitudinal direction.

Step 4.2: defining a function gap _ inside () to calculate the distance inside the gap, i.e. the number of pixels occupied laterally calculated in step 4.1.

Step 4.3: and defining a function gap _ flush () to calculate the value of the gap depth, namely the number of the pixel points longitudinally occupied by the function gap _ flush () calculated in the step 4.1.

Step 4.4: and defining a function excel () to output a measured value and storing the measured value into an excel document, and writing the measured data gap _ inside, gap _ flush and measured time into a self-defined excel table through a filename () function to realize data export.

Through 3568 times of actual measurement, the image processing effect of the laser under different background lights is improved by measuring the gaps on the surfaces of different materials and combining the effect data of the two experiments. The improved laser measurement method ensures the calculation speed and improves the accuracy of the measurement data, and the accuracy of the measurement data is 98% in actual detection.

9页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:相控阵雷达发射波形幅度加权方法及相控阵雷达

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!