CN103226814B - A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification - Google Patents
A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification Download PDFInfo
- Publication number
- CN103226814B CN103226814B CN201310113316.7A CN201310113316A CN103226814B CN 103226814 B CN103226814 B CN 103226814B CN 201310113316 A CN201310113316 A CN 201310113316A CN 103226814 B CN103226814 B CN 103226814B
- Authority
- CN
- China
- Prior art keywords
- image
- avg
- medicine bottle
- imager
- template
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 239000003814 drug Substances 0.000 title claims abstract description 66
- 238000000034 method Methods 0.000 title claims abstract description 47
- 238000001514 detection method Methods 0.000 title claims abstract description 31
- 230000000007 visual effect Effects 0.000 title abstract description 3
- 238000012937 correction Methods 0.000 claims abstract description 16
- 238000003702 image correction Methods 0.000 claims abstract description 9
- 238000005070 sampling Methods 0.000 claims description 34
- 230000009466 transformation Effects 0.000 claims description 25
- 238000012545 processing Methods 0.000 claims description 22
- 238000013519 translation Methods 0.000 claims description 21
- 239000011159 matrix material Substances 0.000 claims description 19
- 238000003384 imaging method Methods 0.000 claims description 13
- 230000005484 gravity Effects 0.000 claims description 9
- 238000004364 calculation method Methods 0.000 claims description 6
- 238000007405 data analysis Methods 0.000 claims description 6
- 238000006073 displacement reaction Methods 0.000 claims description 5
- 230000002950 deficient Effects 0.000 claims description 3
- 238000007781 pre-processing Methods 0.000 claims description 3
- 238000003672 processing method Methods 0.000 claims description 3
- 230000011218 segmentation Effects 0.000 claims description 3
- 239000007787 solid Substances 0.000 claims description 3
- 238000007689 inspection Methods 0.000 claims 1
- 239000007788 liquid Substances 0.000 abstract description 5
- 238000001802 infusion Methods 0.000 abstract description 3
- 238000012797 qualification Methods 0.000 abstract description 2
- 230000001629 suppression Effects 0.000 abstract 1
- 239000011521 glass Substances 0.000 description 6
- 238000010586 diagram Methods 0.000 description 5
- 230000000694 effects Effects 0.000 description 4
- 238000000605 extraction Methods 0.000 description 2
- 239000000835 fiber Substances 0.000 description 2
- 238000010606 normalization Methods 0.000 description 2
- 238000011179 visual inspection Methods 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
- 230000001788 irregular Effects 0.000 description 1
- 239000002245 particle Substances 0.000 description 1
Landscapes
- Image Analysis (AREA)
Abstract
本发明公开了一种基于医药视觉检测机器人图像校正的药瓶异物检测方法,通过基于药瓶特征的确定,准确计算出药瓶的旋转角度和水平偏移量,基于模板匹配方法,以最大匹配度的方式确定纵向偏移量,实现图像的精密校正,然后再通过差分、二值化、叠加等操作,实现医药异物的合格性判断。能够在机械防抖抑制不足的环境下使用的序列图像高精密配准方法,有效的弥补了硬件的不足,适用于安瓿、大输液、口服液、软袋等医药异物视觉检测机器人的高速高精度检测。
The invention discloses a medicine bottle foreign object detection method based on medical vision detection robot image correction. By determining the characteristics of the medicine bottle, the rotation angle and horizontal offset of the medicine bottle can be accurately calculated. Based on the template matching method, the maximum matching The vertical offset is determined by the method of degree, and the precise correction of the image is realized, and then the qualification judgment of the medical foreign body is realized through operations such as difference, binarization, and superposition. The high-precision registration method of sequential images that can be used in an environment with insufficient mechanical anti-shake suppression effectively makes up for the lack of hardware, and is suitable for high-speed and high-precision visual detection robots for medical foreign objects such as ampoules, large infusions, oral liquids, and soft bags. detection.
Description
技术领域technical field
本发明涉及一种基于医药视觉检测机器人图像校正的药瓶异物检测方法。The invention relates to a method for detecting foreign objects in medicine bottles based on image correction of a medical vision detection robot.
背景技术Background technique
目前,现有医药异物视觉检测机器人(安瓿、大输液、口服液等)多采用序列帧差分处理的方法来检测异物,其原理在于通过相邻帧差分消除静态背景,凸显运动目标,然后对运动目标进行特征提取与识别判断,该方法简单、快速、有效。但对机械本体的抗抖能力要求极高,轻微的抖动将使目标在图像中偏移几个像素,而50微米医药异物颗粒在图像中的成像也仅有几个像素,致使异物目标特征与背景干扰特征比较接近,极大增加了高速高精度视觉检测机器人的开发难度,区分尺度不大。因此,必须解决机器人高速运行过程中图像发生旋转与偏移难题,才能实现微弱异物的高精度检测。At present, the existing medical foreign body visual detection robots (ampoules, large infusions, oral liquids, etc.) mostly use the method of sequential frame difference processing to detect foreign bodies. The method is simple, fast and effective for feature extraction and recognition judgment of the target. However, the anti-shake ability of the mechanical body is extremely high. A slight shake will cause the target to shift a few pixels in the image, and the imaging of 50-micron pharmaceutical foreign particles in the image is only a few pixels, resulting in the characteristics of the foreign object being different from the image. The background interference features are relatively close, which greatly increases the difficulty of developing high-speed and high-precision visual inspection robots, and the scale of distinction is not large. Therefore, it is necessary to solve the problem of image rotation and offset during the high-speed operation of the robot in order to achieve high-precision detection of faint foreign objects.
发明内容Contents of the invention
本发明提出一种基于医药视觉检测机器人图像校正的药瓶异物检测方法,其的目的在于克服现有技术中检测药瓶异物时,未对已经发生偏移的药瓶进行校正与匹配,造成异物检测精度较低的不足。The present invention proposes a method for detecting foreign objects in medicine bottles based on the image correction of medical vision detection robots. The detection accuracy is low.
本发明采用的技术方案如下:The technical scheme that the present invention adopts is as follows:
一种基于医药视觉检测机器人图像校正的药瓶异物检测方法,包括以下步骤:A method for detecting foreign matter in medicine bottles based on image correction of a medical vision detection robot, comprising the following steps:
步骤1:图像采集;Step 1: Image acquisition;
连续采集N帧医药序列图像Image={Image0,Image1…ImageN-1};Continuously collect N frames of medical sequence images Image={Image 0 , Image 1 ... Image N-1 };
其中,采集的帧数N根据医药异物检测过程中的实际需求而定;采集模式为单次触发采集多帧的方式,集中采集异物高速旋转时间段的图像信息。Among them, the number of frames N to be collected is determined according to the actual needs in the detection process of medical foreign matter; the acquisition mode is a single-trigger acquisition of multiple frames, and the image information of the high-speed rotation period of the foreign matter is collected intensively.
步骤2:对序列图像进行预处理,得到每帧图像的感兴趣区域;Step 2: Preprocessing the sequence images to obtain the region of interest of each frame image;
依次对序列图像Image的每帧图像进行图像处理,得到所有图像中药瓶区域的序列图像ImageReduced,对每帧图像的具体处理方法如下:Image processing is performed on each frame of the sequence image Image in turn to obtain the sequence image ImageReduced of the medicine bottle area in all images. The specific processing method for each frame of image is as follows:
1)令i=0,i表示序列图像中的第i帧,取值范围是0~(N-1);1) let i=0, i represents the i-th frame in the sequence image, and the value range is 0~(N-1);
2)对图像Imagei进行二值化处理,生成二值图像BinImagei,二值化处理中的阈值设为Ti,保证二值图像BinImagei中瓶体对象与背景完全分离;2) Carry out binarization processing to image Image i , generate binary image BinImage i , the threshold value in the binarization processing is set to T i , guarantees that the bottle body object in binary image BinImage i is completely separated from the background;
3)对二值图像BinImagei进行连通域搜寻操作,生成连通域Connectionsi[m],m为每帧图像的连通域个数;3) Perform connected domain search operation on the binary image BinImage i to generate connected domain Connections i [m], where m is the number of connected domains in each frame of image;
4)计算图像BinImagei中的每个连通域的面积Areas[m],连通域Connectionsi[m]的面积为连通域内所有像素点Pm的总数,其中,{Pm|Pm∈Connectionsi[m]};4) Calculate the area Areas[m] of each connected domain in the image BinImage i , the area of the connected domain Connections i [m] is the total number of all pixels P m in the connected domain, where {P m |P m ∈ Connections i [m]};
5)选取图像BinImagei中面积最大的连通域Connectionsi[Areasmax],作为待处理的药瓶特征,其中Areasmax为Connectionsi[m]中面积最大值的连通域对应的连通域标号m;5) Select the connected domain Connections i [Areas max ] with the largest area in the image BinImage i as the feature of the medicine bottle to be processed, where Areas max is the connected domain label m corresponding to the connected domain with the largest area in Connections i [m];
6)对面积最大连通域Connectionsi[Areasmax]进行填充处理,保证该连通域为实心连通域,然后以9×9的矩形膨胀因子对填充后的连通域进行膨胀,将膨胀后得到的连通域作为当前图像中药瓶的感兴趣区域ROI(Region Of Interest),即当前图像中药瓶区域图像ImageReducedi;步骤3:依次定位药瓶在每帧图像ImageReducedi中的位置,计算每帧图像ImageReducedi中药瓶的倾斜角度,获得每帧图像ImageReducedi中定位药瓶位置的所需数据,步骤如下:6) Fill the connected domain Connections i [Areas max ] with the largest area to ensure that the connected domain is a solid connected domain, and then expand the filled connected domain with a rectangular expansion factor of 9×9, and the expanded connected domain domain as the region of interest ROI (Region Of Interest) of the medicine bottle in the current image, that is, the image ImageReduced i of the medicine bottle area in the current image; Step 3: sequentially locate the position of the medicine bottle in each frame of image ImageReduced i , and calculate each frame of image ImageReduced i Obtain the data needed to locate the position of the medicine bottle in each frame of image ImageReduced i by the tilt angle of the traditional Chinese medicine bottle. The steps are as follows:
1)计算每帧图像ImageReducedi中面积最大的连通域Connectionsi[Areasmax]的重心P(x0,y0),计算公式为:1) Calculate the center of gravity P(x 0 ,y 0 ) of the connected domain Connections i [Areas max ] with the largest area in ImageReduced i of each frame, and the calculation formula is:
其中,M为连通域Connectionsi[Areasmax]的像素总数,0≤i≤M-1;Among them, M is the total number of pixels in the connected domain Connections i [Areas max ], 0≤i≤M-1;
2)经过重心P(x0,y0)作与药瓶两瓶壁边缘相交的线段,并计算线段的斜率,最短线段的斜率对应的角度即为瓶体的定位倾斜角度θmin;2) Through the center of gravity P(x 0 , y 0 ), make a line segment that intersects the edges of the two walls of the medicine bottle, and calculate the slope of the line segment, and the angle corresponding to the slope of the shortest line segment is the positioning inclination angle θ min of the bottle;
3)以重心P(x0,y0)为原点,作与2)得到的最短线段平行等距的采样线l1…ln,相邻两采样线之间的距离为d,然后,分别以所有采样线与药瓶边缘的交点作为中心点,从图像ImageReducedi中选取大小为30×30的采样窗口R1…Rn,L1…Ln,n为正整数,n≥2,药瓶定位的数据为采样窗口中的数据;3) With the center of gravity P(x 0 , y 0 ) as the origin, make a sampling line l 1 ...l n parallel and equidistant to the shortest line segment obtained in 2), the distance between two adjacent sampling lines is d, and then, respectively Take the intersection of all sampling lines and the edge of the medicine bottle as the center point, select a sampling window R1...Rn, L1...Ln with a size of 30×30 from the image ImageReduced i , n is a positive integer, n≥2, and the data of the medicine bottle positioning is the data in the sampling window;
步骤4:对步骤3所得的药瓶采样窗口中的数据,利用亚像素级图像阈值分割和hough变换方法,确定药瓶的水平位移和旋转角度,具体操作过程如下;Step 4: For the data in the sampling window of the medicine bottle obtained in step 3, the horizontal displacement and rotation angle of the medicine bottle are determined by using sub-pixel image threshold segmentation and hough transform method, and the specific operation process is as follows;
1)采用canny算子对采样窗口中瓶壁边缘进行检测,得到采样窗口中瓶壁的边缘像素点点集,瓶壁左侧边缘上采样窗口中的边缘像素点点集为Pl1 *…Pln *和瓶壁右侧边缘上采集窗口的边缘像素点点集为Pr1 *…Prn *;1) Use the canny operator to detect the edge of the bottle wall in the sampling window, and obtain the edge pixel point set of the bottle wall in the sampling window. The edge pixel point set in the sampling window on the left edge of the bottle wall is P l1 * ... P ln * and the edge pixel point set of the acquisition window on the right edge of the bottle wall is P r1 * ... P rn * ;
2)依次对瓶壁左侧边缘与采样窗口相交的像素点点集Pli *进行hough变换,计算出左边缘拟合直线y=kli·x+bli,其中1<i<n,并根据hough变换中的累加器数组,确定数组中最大值所对应的像素点点集L* i,作为左边缘最相关点集合;2) Perform hough transformation on the pixel point set P li * where the left edge of the bottle wall intersects with the sampling window in turn, and calculate the fitting straight line y=k li x+b li on the left edge, where 1<i<n, and according to The accumulator array in the hough transform determines the pixel point set L * i corresponding to the maximum value in the array as the most relevant point set on the left edge;
依次对瓶壁右侧边缘与采样窗口相交的像素点点集Pri *进行hough变换,计算右侧边缘拟合直线y=kri·x+bri,其中1<i<n,并根据hough变换中的累加器数组,确定数组中最大值所对应的像素点点集R* i,作为右侧边缘最相关点集合;Perform hough transformation on the pixel point set P ri * where the right edge of the bottle wall intersects with the sampling window in turn, and calculate the right edge fitting straight line y=k ri x+b ri , where 1<i<n, and according to the hough transformation The accumulator array in determines the pixel point set R * i corresponding to the maximum value in the array as the most relevant point set on the right edge;
3)对左侧边缘相关点集合L* i和拟合直线y=kli·x+bli进行数据分析,计算出左侧边缘最佳拟合直线;3) Carry out data analysis to the set of relevant points L * i on the left edge and the fitting straight line y=k li x+b li , and calculate the best fitting straight line on the left edge;
分别对拟合直线序列中斜率参数kli(0≤i≤n)和截距参数bli(0≤i≤n)进行排序,求取拟合直线中kli和bli的均值AvgKl、Avgbl,方差SKl、Sbl,最大值maxKl、maxbl和最小值minKl、minbl,对左侧边缘最佳拟合直线y=kL *·x+bL *进行迭代计算:a)若SKl≤ε且Sbl≤ξ,ε和ξ均为设定阈值,则左侧边缘最佳拟合直线的方程为y=AvgKl·x+Avgbl;Respectively sort the slope parameter k li (0≤i≤n) and the intercept parameter b li (0≤i≤n) in the fitted straight line sequence, and calculate the mean values Avg Kl and b li of k li and b li in the fitted straight line Avg bl , variance S Kl , S bl , maximum value max Kl , max bl and minimum value min Kl , min bl , iteratively calculate the best fitting straight line y=k L * x+b L * on the left edge: a) If S Kl ≤ ε and S bl ≤ ξ, ε and ξ are both set thresholds, then the equation of the best fitting straight line on the left edge is y=Avg Kl x+Avg bl ;
b)若SKl>ε或Sbl>ξ,ε、ξ为设定阈值,则比较{|maxKl-AvgKl|,|minKl-AvgKl|}或{|maxbl-Avgbl|,|minbl-Avgbl|}的大小,并从左侧边缘相关点集合L*中除去偏离平均值AvgKl或Avgbl最大的边缘最相关点集L* i;然后重新执行3);b) If S Kl >ε or S bl >ξ, ε, ξ are the set thresholds, then compare {|max Kl -Avg Kl |, |min Kl -Avg Kl |} or {|max bl -Avg bl |, The size of |min bl -Avg bl |}, and remove the edge most relevant point set L * i that deviates from the mean value Avg Kl or Avg bl maximum from the left side edge related point set L * ; then re-execute 3);
若左侧边缘相关点集合L*仅包含2组采集窗口数据集合时,停止迭代,然后对所有左侧边缘点集集合Pl1 *…Pln *进行hough变换,生成最佳拟合曲线y=kL *′·x+bL *′;否则,则返回3),获取左侧最佳边缘拟合直线;If the left edge related point set L * only contains 2 sets of acquisition window data sets, stop the iteration, and then perform hough transformation on all left edge point sets P l1 * ... P ln * to generate the best fitting curve y= k L *′ x+b L *′ ; otherwise, return to 3) to obtain the best edge fitting straight line on the left;
4)对右侧边缘相关点集合R* i和拟合直线y=kri·x+bri进行数据分析,计算出右侧边缘最佳拟合直线;4) Carry out data analysis to the right side edge related point set R * i and the fitting straight line y=k ri ·x+b ri , calculate the best fitting straight line of the right side edge;
分别对拟合直线序列中斜率参数kri(0≤i≤n)和截距参数bri(0≤i≤n)进行排序,求取拟合直线中kri和bri的均值AvgKr、Avgbr,方差SKr、Sbr,最大值maxKr、maxbr和最小值minKr、minbr,对右侧边缘最佳拟合直线y=kR *·x+bR *进行迭代计算:Sorting the slope parameter k ri (0≤i≤n) and the intercept parameter b ri (0≤i≤n) in the fitted straight line sequence respectively, and calculating the mean values Avg Kr and b ri of k ri and b ri in the fitted straight line Avg br , variance S Kr , S br , maximum value max Kr , max br and minimum value min Kr , min br , iteratively calculate the best fitting straight line y=k R * x+b R * on the right edge:
a)若SKr≤ε且Sbr≤ξ,ε和ξ均为设定阈值,则右侧边缘最佳拟合直线的方程为y=AvgKr·x+Avgbr;a) If S Kr ≤ ε and S br ≤ ξ, ε and ξ are both set thresholds, then the equation of the best fitting straight line on the right edge is y=Avg Kr x+Avg br ;
b)若SKr>ε或Sbr>ξ,ε、ξ为设定阈值,则比较{|maxKr-AvgKr|,|minKr-AvgKr|}或{|maxbr-Avgbr|,|minbr-Avgbr|}的大小,并从右侧边缘相关点集合R*中除去偏离平均值AvgKr或Avgbr最大的边缘最相关点集R* i;然后重新执行4);b) If S Kr >ε or S br >ξ, ε, ξ are the set thresholds, then compare {|max Kr -Avg Kr |, |min Kr -Avg Kr |} or {|max br -Avg br |, The size of |min br -Avg br |}, and remove the edge most relevant point set R * i that deviates from the mean Avg Kr or Avg br maximum from the right edge related point set R * ; then re-execute 4);
若右侧边缘相关点集合R*仅包含2组采集窗口数据集合时,停止迭代,然后对所有右侧边缘点集集合Pr1 *…Prn *进行hough变换,生成最佳拟合曲线y=kR *′·x+bR *′;否则,则返回4),获取右侧最佳边缘拟合直线;If the right edge related point set R * only contains two sets of acquisition window data sets, stop the iteration, and then perform hough transformation on all the right edge point set P r1 * ... P rn * to generate the best fitting curve y= k R *′ x+b R *′ ; otherwise, return to 4) to obtain the best edge fitting straight line on the right;
5)计算药瓶的旋转角度θ*和水平平移量X*;5) calculate the angle of rotation θ * of the medicine bottle and the amount of horizontal translation X * ;
通过3)和4)得到药瓶两瓶壁边缘的拟合直线,将两拟合直线的角平分线作为衡量药瓶倾斜程度的倾斜标准线,则有:
步骤5:依次对序列图像Image的每帧图像进行第一次校正;Step 5: Perform the first correction on each frame of the sequence image Image in turn;
按照水平平移量X*进行平移,并按照药瓶倾斜角θ*进行旋转变换,平移与旋转变换过程中采用二次插值算法,变换矩阵为Rxi:Translate according to the horizontal translation amount X * , and perform rotation transformation according to the tilt angle θ * of the medicine bottle. During the translation and rotation transformation process, the quadratic interpolation algorithm is used, and the transformation matrix is R xi :
经过旋转与水平平移后,生成新的序列图像ImageRi,i为小于N的整数;After rotation and horizontal translation, a new sequence image ImageR i is generated, where i is an integer less than N;
步骤6:采用模板匹配,获取相邻帧图像的纵向偏移量,对图像进行第二次校正;Step 6: Use template matching to obtain the vertical offset of the adjacent frame image, and perform a second correction on the image;
1)选取两帧相邻的图像ImageRi和ImageRi+1,分别在两帧图像中的点P′(x0′,y0′)处建立用户坐标系UCS,其中,x0′=ImageWidth/2,y0′=ImageHeight/10,ImageHeight为图像高度;1) Select two adjacent frames of images ImageR i and ImageR i+1 , and establish the user coordinate system UCS at the point P′(x 0 ′, y 0 ′) in the two frames of images respectively, where x 0 ′=ImageWidth /2, y 0 '=ImageHeight/10, ImageHeight is the image height;
2)在用户坐标系UCS中设置n个模版对[Pj,Pj+1],j的取值范围为1~n,n为正整数,模板对必须满足以下条件:2) Set n template pairs [P j , P j+1 ] in the user coordinate system UCS, the value range of j is 1~n, n is a positive integer, and the template pairs must meet the following conditions:
(1)模板对在用户坐标系中关于y轴对称分布,模板对间距离为10~30像素距离;(1) Template pairs are distributed symmetrically about the y-axis in the user coordinate system, and the distance between template pairs is 10 to 30 pixels;
限制模版对距离的主要原因为,异物旋转到瓶体中间位置时,运动速度方向平行于摄像机成像平面,因此,相对于其他位置,单位时间内在像素间的位移最大,故异物进入模版矩阵的概率最小;The main reason for limiting the distance between the template pair is that when the foreign object rotates to the middle position of the bottle body, the moving speed direction is parallel to the imaging plane of the camera. Therefore, compared with other positions, the displacement between pixels per unit time is the largest, so the probability of foreign objects entering the template matrix minimum;
(2)模版对在用户坐标系中的竖直方向均匀分布且布满大部分感兴趣区域;可增大明显特征进入模版的概率;(2) Template pairs are evenly distributed in the vertical direction in the user coordinate system and cover most of the region of interest; the probability of obvious features entering the template can be increased;
(3)模板窗口中的模板窗口为15-25个像素的正方形;(3) The template window in the template window is a square of 15-25 pixels;
若太大,则降低图像处理速度,太小,则影响匹配准确度,一般选取20个像素值的正方形,具体根据图像的分辨率、抖动振幅和处理速度需求而定。If it is too large, the image processing speed will be reduced; if it is too small, the matching accuracy will be affected. Generally, a square of 20 pixel values is selected, depending on the image resolution, jitter amplitude, and processing speed requirements.
3)通过灰度直方图方法对图像ImageRi和ImageRi+1选取最优匹配模板;3) Select the optimal matching template for the images ImageR i and ImageR i+1 by the gray histogram method;
分别对图像ImageRi、ImageRi+1中的对应模板进行灰度直方图统计,得到灰度直方图矩阵i为图像帧序列编号,j为模板匹配序列编号;For the corresponding templates in ImageR i and ImageR i+1 respectively Perform grayscale histogram statistics to obtain grayscale histogram matrix i is the image frame sequence number, j is the template matching sequence number;
分别计算和的方差并对进行排序,选取排列在前三的方差对应的3个模板窗口作为初步匹配模板窗口,然后,比较这3个初步匹配模板分别对应的的大小,选取最小所对应的模版设为最优匹配模板窗口Ppm;Calculate separately and Variance and to Sort, select the three template windows corresponding to the variances arranged in the first three as the preliminary matching template windows, and then compare the corresponding size, choose the smallest The corresponding template is set as the optimal matching template window P pm ;
在初步匹配模板选取过程中,方差值越大,说明模板图像中的特征信息越明显,匹配操作完成后,得到的匹配精度越高,但在匹配过程中,应选择比较小的模板,这样可以避免因异物进入匹配模板内,而导致的模板匹配失败。In the process of preliminary matching template selection, the larger the variance value, the more obvious the feature information in the template image, and the higher the matching accuracy after the matching operation is completed, but in the matching process, it should be selected A relatively small template can avoid template matching failure caused by foreign matter entering the matching template.
4)采用去均值归一化相关法进行模板匹配,对图像进行纵坐标校正;4) Template matching is carried out by using the de-average normalized correlation method, and the vertical coordinates of the image are corrected;
取最优匹配模板Ppm的中心坐标(xpm,ypm),然后,将Ppm与图像ImageRi+1中的图像窗口Gq进行匹配,其中,ImageRi+1中的图像窗口Gq的中心坐标为(xpm,ypm+q),q为纵向偏移向量,取值范围是(-10,10)的整数,且Gq长和宽分别与最优匹配模板Ppm长和宽相等;Take the center coordinates (x pm , y pm ) of the optimal matching template P pm , and then match P pm with the image window G q in the image ImageR i+1 , where the image window G q in ImageR i+1 The center coordinates of G are (x pm , y pm +q), q is the longitudinal offset vector, the value range is an integer of (-10,10), and the length and width of G q are respectively the length and width of the optimal matching template P pm equal in width;
通过采用去均值归一化相关法计算模板窗口匹配度系数ρ(Gq)进行模板与图像窗口的匹配:The template and the image window are matched by calculating the template window matching coefficient ρ(G q ) by using the mean value normalized correlation method:
其中,Gq(a,b)为在图像窗口Gq中坐标(a,b)处的灰度值,Ppm(a,b)为在最优匹配模板中坐标(a,b)处的灰度值,分别为Gq和Ppm的灰度均值,最优匹配模板和图像窗口中均包含S个像素点,均以左下角为起点坐标;Among them, G q (a, b) is the gray value at the coordinates (a, b) in the image window G q , and P pm (a, b) is the gray value at the coordinates (a, b) in the optimal matching template. grayscale value, are the gray mean values of G q and P pm respectively, both the optimal matching template and the image window contain S pixels, and both take the lower left corner as the starting point coordinates;
即
(3)比较模板匹配度系数ρ(Gq),选取最大值ρmax(Gq)作为最优匹配度,ρmax(Gq)中的q值作为ImageRi+1相对于ImageRi的纵向偏移为Mρmax,依次计算出图像序列中所有图像与前一帧图像的纵向偏移,记为Mi。(3) Compare the template matching degree coefficient ρ(G q ), select the maximum value ρ max (G q ) as the optimal matching degree, and the q value in ρ max (G q ) as the longitudinal direction of ImageR i+1 relative to ImageR i The offset is M ρmax , and the vertical offset between all the images in the image sequence and the previous frame image is calculated sequentially, which is denoted as M i .
(4)对图像ImageRi+1进行纵向平移变换得到图像ImageR′i+1,平移矩阵为Ry(i+1),完成机械抖动引起的纵向偏移纠正;平移矩阵Ry(i+1)为:(4) Perform vertical translation transformation on the image ImageR i+1 to obtain the image ImageR′ i+1 , and the translation matrix is R y(i+1) to complete the vertical offset correction caused by mechanical shaking; the translation matrix R y(i+1 ) is:
其中,i为小于N的整数;Wherein, i is an integer less than N;
步骤7:对完成纵向偏移纠正后的序列图像进行绝对差分处理,完成医药异物的检测。Step 7: Absolute difference processing is performed on the sequence images after longitudinal offset correction to complete the detection of medical foreign objects.
经过精确抖动消除后的图像,瓶壁中某一污迹或玻斑在序列帧图像中的成像位置基本相同,偏差不会很大,因此,在两帧相邻图像绝对差分过程中,将会被消除,对图像中的微弱异物目标影响较小。In the image after precise jitter removal, the imaging position of a certain stain or glass spot on the bottle wall in the sequence frame images is basically the same, and the deviation will not be large. Therefore, in the process of absolute difference between two adjacent images, there will be It is eliminated, and has little influence on the faint foreign objects in the image.
所述步骤7的具体实现步骤为:The concrete implementation steps of described step 7 are:
(1)对相邻两帧图像Im ageRi′和Im ageR′i+1进行绝对差分处理,得到差分图像(1) Perform absolute difference processing on two adjacent frames of images ImageR i ' and ImageR' i+1 to obtain a difference image
Sub Im ageRi=|Im ageRi′-Im ageR′i+1|,i∈[1,N-1]且i∈Z;Sub ImageR i =|Im ageR i ′-Im ageR′ i+1 |, i∈[1,N-1] and i∈Z;
相邻帧图像的精确配准操作,能够保证一次差分操作能够消除图像的背景信息(包括瓶壁污迹、玻包、瓶体裂痕等),而不影响液体中运动的异物成像特征。The precise registration operation of adjacent frame images can ensure that a differential operation can eliminate the background information of the image (including bottle wall stains, glass bags, bottle cracks, etc.), without affecting the imaging characteristics of foreign objects moving in the liquid.
(2)对一次差分图像进行给定阈值T的二值化处理,得到二值化图像Bin Im ageRi,T取值的是根据检测对象的特征确定,一般玻璃屑的成像灰度值较大,阈值T也较大,毛发、纤维等细长物体,灰度值与背景相差不大,阈值T选取较小;(2) Binarize the primary difference image with a given threshold T to obtain the binarized image Bin ImageR i , the value of T is determined according to the characteristics of the detection object, and the imaging gray value of glass shavings is generally larger , the threshold T is also relatively large, and for slender objects such as hair and fibers, the gray value is not much different from the background, and the threshold T is selected to be small;
(3)对序列帧二值图像Bin Im ageRi进行叠加操作:(3) Perform superposition operation on sequence frame binary image Bin ImageR i :
Im agemax=MAX{Bin Im ageR1,…Bin Im ageRN-1},N为序列帧总数Image max =MAX{Bin ImageR 1 ,...Bin ImageR N-1 }, N is the total number of sequence frames
(4)求取Im agemax的连通域,统计连通域的个数Numtotal,连通域面积总和Areatotal及面积大于给定值的连通域个数(为异物最小成像面积);(4) Find the connected domain of Image max , count the number of connected domains Num total , the sum of the area of the connected domain Area total and the area is greater than the given The number of connected domains of the value ( is the minimum imaging area of foreign matter);
(5)根据计算的连通域的个数Numtotal,判断医药质量是否合格,产品质量θ为(5) According to the calculated number of connected domains Num total , judge whether the quality of the medicine is qualified, and the product quality θ is
α和β分别为产品质量正品和次品阈值。α and β are the genuine and defective product quality thresholds, respectively.
所述步骤2中对二值图像BinImagei进行连通域搜寻操作,采用8邻域连通法则对图像进行连通域搜寻操作。In the step 2, the connected domain search operation is performed on the binary image BinImage i , and the connected domain search operation is performed on the image by using the 8-neighborhood connectivity rule.
有益效果Beneficial effect
本发明提供了一种基于医药视觉检测机器人图像校正的药瓶异物检测方法,通过基于药瓶特征的确定,准确计算出药瓶的旋转角度和水平偏移量,基于模板匹配方法,以最大匹配度的方式确定纵向偏移量,实现图像的精密校正,然后再通过差分、二值化、叠加等操作,实现医药异物的合格性判断。与现有技术相比,其检测精度高,本方法选取了特征最突出、对比度最高的瓶壁边缘作为定位的基准,又采用亚像素边缘提取和多点集hough变化方法,实现了旋转角度和水平偏移量精确定位,在纵坐标定位过程中,采用了高区分度特征去均值归一化相关模板匹配方法,取得了纵向坐标的高精度定位;稳定性强,在匹配过程中,采用了多种评价标准,满足了复杂环境下不同状况下的需求,降低了图像配准失败引起的检测误判,降低了误检率;计算速度快,一方面,在匹配过程中使用采样矩阵替代全局数据,并采用特征点集替代像素操作,计算速度快,效果显著;另一方面,采用多次定位,保证缩小定位范围,提高定位质量,效率高;本发明是一种能够在机械防抖抑制不足的环境下使用的序列图像高精密配准方法,有效的拟补了硬件的不足,适用于安瓿、大输液、口服液、软袋等医药异物视觉检测机器人的高速高精度检测。The invention provides a medicine bottle foreign object detection method based on the image correction of the medical vision detection robot. By determining the characteristics of the medicine bottle, the rotation angle and horizontal offset of the medicine bottle can be accurately calculated. Based on the template matching method, the maximum matching The vertical offset is determined by the method of degree, and the precise correction of the image is realized, and then the qualification judgment of the medical foreign body is realized through operations such as difference, binarization, and superposition. Compared with the existing technology, its detection accuracy is high. This method selects the edge of the bottle wall with the most prominent features and the highest contrast as the positioning reference, and uses sub-pixel edge extraction and multi-point set hough change method to realize the rotation angle and Accurate positioning of the horizontal offset. In the process of positioning the vertical coordinates, the high-discrimination feature demeaning normalization correlation template matching method is used to achieve high-precision positioning of the vertical coordinates. The stability is strong. During the matching process, the A variety of evaluation standards meet the needs of different situations in complex environments, reduce the detection misjudgment caused by image registration failure, and reduce the false detection rate; the calculation speed is fast. On the one hand, the sampling matrix is used in the matching process to replace the global Data, and use the feature point set to replace the pixel operation, the calculation speed is fast, and the effect is remarkable; on the other hand, multiple positioning is used to ensure the narrowing of the positioning range, improve the positioning quality, and high efficiency; The high-precision registration method of sequential images used in insufficient environments can effectively make up for the lack of hardware, and is suitable for high-speed and high-precision detection of medical foreign body vision detection robots such as ampoules, large infusions, oral liquids, and soft bags.
附图说明Description of drawings
图1为本发明的流程图;Fig. 1 is a flowchart of the present invention;
图2为在图中建立用户坐标系UCS示意图;Fig. 2 is a schematic diagram of establishing a user coordinate system UCS in the figure;
图3为在图中绘制等距平行采样线示意图;Fig. 3 is a schematic diagram of drawing equidistant parallel sampling lines in the figure;
图4为图像进行CANNY算子处理后得到的瓶壁效果图;Figure 4 is the bottle wall effect diagram obtained after the image is processed by the CANNY operator;
图5为对图像进行旋转和平移后的效果图;Figure 5 is an effect diagram after the image is rotated and translated;
图6为对图像进行纵坐标校正后效果图。Fig. 6 is an effect diagram after the vertical coordinate correction is performed on the image.
具体实施方式Detailed ways
下面将结合附图对本发明做进一步的说明。The present invention will be further described below in conjunction with the accompanying drawings.
如图1所示,为本发明的流程图,一种基于医药视觉检测机器人图像校正的药瓶异物检测方法,本实例中,采用130万baumer千兆网相机,8mm镜头、物距为10cm,厂家异物检出尺寸要求为50um,即超过50um的异物需要被检测出来,包括以下步骤:As shown in Figure 1, it is a flow chart of the present invention, a method for detecting foreign matter in a medicine bottle based on image correction of a medical visual inspection robot. In this example, a 1.3 million Baumer Gigabit camera, an 8mm lens, and an object distance of 10cm are used. The manufacturer’s foreign matter detection size requirement is 50um, that is, foreign matter exceeding 50um needs to be detected, including the following steps:
步骤1:图像采集;Step 1: Image acquisition;
连续采集N帧医药序列图像Image={Image0,Image1…ImageN-1};Continuously collect N frames of medical sequence images Image={Image 0 , Image 1 ... Image N-1 };
其中,采集的帧数N根据医药异物检测过程中的实际需求而定;采集模式为单次触发采集多帧的方式,集中采集异物高速旋转时间段的图像信息。步骤2:对序列图像进行预处理,得到每帧图像的感兴趣区域;Among them, the number of frames N to be collected is determined according to the actual needs in the detection process of medical foreign matter; the acquisition mode is a single-trigger acquisition of multiple frames, and the image information of the high-speed rotation period of the foreign matter is collected intensively. Step 2: Preprocessing the sequence images to obtain the region of interest of each frame image;
依次对序列图像Image的每帧图像进行图像处理,得到所有图像中药瓶区域的序列图像ImageReduced,对每帧图像的具体处理方法如下:Image processing is performed on each frame of the sequence image Image in turn to obtain the sequence image ImageReduced of the medicine bottle area in all images. The specific processing method for each frame of image is as follows:
1)令i=0,i表示序列图像中的第i帧,取值范围是0~(N-1);1) let i=0, i represents the i-th frame in the sequence image, and the value range is 0~(N-1);
2)对图像Imagei进行二值化处理,生成二值图像BinImagei,二值化处理中的阈值设为Ti,保证二值图像BinImagei中瓶体对象与背景完全分离;2) Carry out binarization processing to image Image i , generate binary image BinImage i , the threshold value in the binarization processing is set to T i , guarantees that the bottle body object in binary image BinImage i is completely separated from the background;
3)对二值图像BinImagei进行连通域搜寻操作,生成连通域Connectionsi[m],m为每帧图像的连通域个数;3) Perform connected domain search operation on the binary image BinImage i to generate connected domain Connections i [m], where m is the number of connected domains in each frame of image;
对二值图像BinImagei进行连通域搜寻操作,采用8邻域连通法则对图像进行连通域搜寻操作。The connected domain search operation is performed on the binary image BinImage i , and the connected domain search operation is performed on the image by using the 8-neighborhood connectivity rule.
4)计算图像BinImagei中的每个连通域的面积Areas[m],连通域Connectionsi[m]的面积为连通域内所有像素点Pm的总数,其中,{Pm|Pm∈Connectionsi[m]};4) Calculate the area Areas[m] of each connected domain in the image BinImage i , the area of the connected domain Connections i [m] is the total number of all pixels P m in the connected domain, where {P m |P m ∈ Connections i [m]};
5)选取图像BinImagei中面积最大的连通域Connectionsi[Areasmax],作为待处理的药瓶特征,其中Areasmax为Connectionsi[m]中面积最大值的连通域对应的连通域标号m;5) Select the connected domain Connections i [Areas max ] with the largest area in the image BinImage i as the feature of the medicine bottle to be processed, where Areas max is the connected domain label m corresponding to the connected domain with the largest area in Connections i [m];
6)对面积最大连通域Connectionsi[Areasmax]进行填充处理,保证该连通域为实心连通域,然后以9×9的矩形膨胀因子对填充后的连通域进行膨胀,将膨胀后得到的连通域作为当前图像中药瓶的感兴趣区域ROI(Region Of Interest),即当前图像中药瓶区域图像ImageReducedi;6) Fill the connected domain Connections i [Areas max ] with the largest area to ensure that the connected domain is a solid connected domain, and then expand the filled connected domain with a rectangular expansion factor of 9×9, and the expanded connected domain domain as the region of interest ROI (Region Of Interest) of the medicine bottle in the current image, that is, the image ImageReduced i of the medicine bottle region in the current image;
步骤3:依次定位药瓶在每帧图像ImageReducedi中的位置,计算每帧图像ImageReducedi中药瓶的倾斜角度,获得每帧图像ImageReducedi中定位药瓶位置的所需数据,具体操作步骤如下:Step 3: Locate the position of the medicine bottle in each frame of image ImageReduced i sequentially, calculate the inclination angle of the medicine bottle in each frame of image ImageReduced i , and obtain the required data for locating the position of the medicine bottle in each frame of image ImageReduced i , the specific operation steps are as follows:
1)计算每帧图像ImageReducedi中面积最大的连通域Connectionsi[Areasmax]的重心P(x0,y0),计算公式为:1) Calculate the center of gravity P(x 0 ,y 0 ) of the connected domain Connections i [Areas max ] with the largest area in ImageReduced i of each frame, and the calculation formula is:
其中,M为连通域Connectionsi[Areasmax]的像素总数,0≤i≤M-1;Among them, M is the total number of pixels in the connected domain Connections i [Areas max ], 0≤i≤M-1;
2)经过重心P(x0,y0)作与药瓶两瓶壁边缘相交的线段,并计算线段的斜率,最短线段的斜率对应的角度即为瓶体的定位倾斜角度θmin;2) Through the center of gravity P(x 0 , y 0 ), make a line segment that intersects the edges of the two walls of the medicine bottle, and calculate the slope of the line segment, and the angle corresponding to the slope of the shortest line segment is the positioning inclination angle θ min of the bottle;
首先建立用户坐标系UCS,如图2所示,其原点为P(x0,y0),x轴为图像行方向,y轴为图像列方向。建立一条通过原点P(x0,y0)的直y=tan(θ)·x,n为整数,且-450<n<450,然后,求取直线y与连通域的交点(Xn1,Yn1)和(Xn2,Yn2),并求取对应两点之间的距离最后,对两点之间距离Dn进行排序,寻找出最小值Dmin,求出最短线段对应的直线与x轴的夹角θmin,计算的θmin既为瓶体的倾斜角度。Firstly, the user coordinate system UCS is established, as shown in Fig. 2, its origin is P(x 0 , y 0 ), the x-axis is the image row direction, and the y-axis is the image column direction. Establish a straight line y=tan(θ)·x passing through the origin P(x 0 ,y 0 ), n is an integer, and -450<n<450, then, find the intersection points (X n1 , Y n1 ) and (X n2 , Y n2 ) of the straight line y and the connected domain, and find the distance between the corresponding two points Finally, sort the distance D n between the two points, find the minimum value D min , and find the angle θ min between the straight line corresponding to the shortest line segment and the x-axis, and the calculated θ min is the inclination angle of the bottle.
3)以重心P(x0,y0)为原点,作与2)得到的最短线段平行等距的采样线l1、l2、l3、l4及l5,相邻两采样线之间的距离为d,然后,分别以所有采样线与药瓶边缘的交点作为中心点,从图像ImageReducedi中选取大小为30×30的采样窗口R1…R5,L1…L5,如图3所示,用于药瓶定位的数据为采样窗口中的数据;3) With the center of gravity P(x 0 , y 0 ) as the origin, draw the sampling lines l 1 , l 2 , l 3 , l 4 and l 5 parallel and equidistant to the shortest line obtained in 2), between two adjacent sampling lines The distance between them is d, and then, taking the intersection of all sampling lines and the edge of the medicine bottle as the center point, select a sampling window R1...R5, L1...L5 with a size of 30×30 from the image ImageReduced i , as shown in Figure 3 , the data used for the positioning of the medicine bottle is the data in the sampling window;
步骤4:对步骤3所得的药瓶采样窗口中的数据,利用亚像素级图像阈值分割和hough变换方法,确定药瓶的水平位移和旋转角度,具体操作过程如下;Step 4: For the data in the sampling window of the medicine bottle obtained in step 3, the horizontal displacement and rotation angle of the medicine bottle are determined by using the sub-pixel image threshold segmentation and hough transform method, and the specific operation process is as follows;
1)采用canny算子对采样窗口中瓶壁边缘进行检测,得到采样窗口中瓶壁的边缘像素点点集,瓶壁左侧边缘上采样窗口中的边缘像素点点集为Pl1 *、Pl2 *、Pl3 *、Pl4 *及Pl5 *,和瓶壁右侧边缘上采集窗口的边缘像素点点集为Pr1 *、Pr2 *、Pr3 *、Pr4 *及Pr5 *;但在边界点集中,除了边界数据点外,还存在其他信息点的干扰,主要原因是瓶体的反光和折射引起的,瓶体的外形是圆柱型,而不规则光源经过瓶壁反射或折射后,会引起成像的不均匀,导致图像内部灰度分布的不均匀性,在进行canny算子处理后,出现弯曲边缘,如图4所示。1) Use the canny operator to detect the edge of the bottle wall in the sampling window, and obtain the edge pixel point set of the bottle wall in the sampling window. The edge pixel point set in the sampling window on the left edge of the bottle wall is P l1 * , P l2 * , P l3 * , P l4 * and P l5 * , and the edge pixel point set of the collection window on the right edge of the bottle wall is P r1 * , P r2 * , P r3 * , P r4 * and P r5 * ; but in The concentration of boundary points, in addition to the boundary data points, there are other interferences of information points, the main reason is caused by the reflection and refraction of the bottle body, the shape of the bottle body is cylindrical, and after the irregular light source is reflected or refracted by the bottle wall, It will cause non-uniform imaging, resulting in non-uniform gray distribution inside the image. After the canny operator processing, curved edges appear, as shown in Figure 4.
2)依次对瓶壁左侧边缘与采样窗口相交的像素点点集Pli *进行hough变换,计算出左边缘拟合直线y=kli·x+bli,其中1<i<5,并根据hough变换中的累加器数组,确定数组中最大值所对应的像素点点集L* i,作为左边缘最相关点集合;同样方法,求得右侧边缘拟合直线y=kri·x+bri,其中1<i<5,确定右侧边缘最相关点集R* i;2) Perform hough transformation on the pixel point set P li * where the left edge of the bottle wall intersects with the sampling window in turn, and calculate the fitting straight line y=k li x+b li on the left edge, where 1<i<5, and according to The accumulator array in the hough transform determines the pixel point set L * i corresponding to the maximum value in the array as the most relevant point set on the left edge; the same method obtains the right edge fitting straight line y=k ri x+b ri , where 1<i<5, determine the most relevant point set R * i on the right edge;
3)对左侧边缘相关点集合L* i和拟合直线y=kli·x+bli进行数据分析,计算出左侧边缘最佳拟合直线;3) Carry out data analysis to the set of relevant points L * i on the left edge and the fitting straight line y=k li x+b li , and calculate the best fitting straight line on the left edge;
分别对拟合直线序列中斜率参数kli(0≤i≤5)和截距参数bli(0≤i≤5)进行排序,求取拟合直线中kli和bli的均值AvgKl、Avgbl,方差SK、Sb,最大值maxKl、maxbl和最小值minKl、minbl,对左侧边缘最佳拟合直线y=kL *·x+bL *进行迭代计算:Respectively sort the slope parameter k li (0≤i≤5) and the intercept parameter b li (0≤i≤5) in the fitted straight line sequence, and calculate the mean values Avg Kl and b li of k li and b li in the fitted straight line Avg bl , variance S K , S b , maximum value max Kl , max bl and minimum value min Kl , min bl , iteratively calculate the best fitting straight line y=k L * x+b L * on the left edge:
a)若SK≤ε且Sb≤ξ,ε和ξ均为设定阈值,则左侧边缘拟合直线的方程为y=AvgKl·x+Avgbl;a) If S K ≤ε and S b ≤ξ, both ε and ξ are set thresholds, then the equation of the left edge fitting straight line is y=Avg Kl x+Avg bl ;
b)若SK>ε或Sb>ξ,ε、ξ为设定阈值,则比较{|maxKl-AvgKl|,|minKl-AvgKl|}或{|maxbl-Avgbl|,|minbl-Avgbl|}的大小,并从左侧边缘相关点集合L*中除去偏离平均值AvgKl或Avgbl最大的边缘最相关点集L* i;然后重新执行3);b) If S K > ε or S b > ξ, ε, ξ are the set thresholds, then compare {|max Kl -Avg Kl |, |min Kl -Avg Kl |} or {|max bl -Avg bl |, The size of |min bl -Avg bl |}, and remove the edge most relevant point set L * i that deviates from the mean value Avg Kl or Avg bl maximum from the left side edge related point set L * ; then re-execute 3);
若左侧边缘相关点集合L*仅包含2组采集框数据集合时,停止迭代,然后对所有左侧边缘点集集合Pl1 *、Pl2 *、Pl3 *、Pl4 *及Pl5 *进行hough变换,生成最佳拟合曲线y=kL *′·x+bL *′;否则,则返回3),获取左侧边缘拟合直线;If the left edge related point set L * only contains 2 sets of acquisition frame data sets, stop the iteration, and then for all the left edge point set P l1 * , P l2 * , P l3 * , P l4 * and P l5 * Perform hough transformation to generate the best fitting curve y=k L *' x+b L *' ; otherwise, return to 3) to obtain the left edge fitting straight line;
4)对右侧边缘相关点集合R* i和拟合直线y=kri·x+bri进行数据分析,计算出右侧边缘最佳拟合直线;4) Carry out data analysis to the right side edge related point set R * i and the fitting straight line y=k ri ·x+b ri , calculate the best fitting straight line of the right side edge;
分别对拟合直线序列中斜率参数kri(0≤i≤n)和截距参数bri(0≤i≤n)进行排序,求取拟合直线中kri和bri的均值AvgKr、Avgbr,方差SKr、Sbr,最大值maxKr、maxbr和最小值minKr、minbr,对右侧边缘最佳拟合直线y=kR *·x+bR *进行迭代计算:Sorting the slope parameter k ri (0≤i≤n) and the intercept parameter b ri (0≤i≤n) in the fitted straight line sequence respectively, and calculating the mean values Avg Kr and b ri of k ri and b ri in the fitted straight line Avg br , variance S Kr , S br , maximum value max Kr , max br and minimum value min Kr , min br , iteratively calculate the best fitting straight line y=k R * x+b R * on the right edge:
a)若SKr≤ε且Sbr≤ξ,ε和ξ均为设定阈值,则右侧边缘最佳拟合直线的方程为y=AvgKr·x+Avgbr;a) If S Kr ≤ ε and S br ≤ ξ, ε and ξ are both set thresholds, then the equation of the best fitting straight line on the right edge is y=Avg Kr x+Avg br ;
b)若SKr>ε或Sbr>ξ,ε、ξ为设定阈值,则比较{|maxKr-AvgKr|,|minKr-AvgKr|}或{|maxbr-Avgbr|,|minbr-Avgbr|}的大小,并从右侧边缘相关点集合R*中除去偏离平均值AvgKr或Avgbr最大的边缘最相关点集R* i;然后重新执行4);b) If S Kr >ε or S br >ξ, ε, ξ are the set thresholds, then compare {|max Kr -Avg Kr |, |min Kr -Avg Kr |} or {|max br -Avg br |, The size of |min br -Avg br |}, and remove the edge most relevant point set R * i that deviates from the mean Avg Kr or Avg br maximum from the right edge related point set R * ; then re-execute 4);
若右侧边缘相关点集合R*仅包含2组采集窗口数据集合时,停止迭代,然后对所有右侧边缘点集集合Pr1 *…Prn *进行hough变换,生成最佳拟合曲线y=kR *′·x+bR *′;否则,则返回4),获取右侧最佳边缘拟合直线;If the right edge related point set R * only contains two sets of acquisition window data sets, stop the iteration, and then perform hough transformation on all the right edge point set P r1 * ... P rn * to generate the best fitting curve y= k R *′ x+b R *′ ; otherwise, return to 4) to obtain the best edge fitting straight line on the right;
5)计算药瓶的旋转角度θ*和水平平移量X*;5) calculate the angle of rotation θ * of the medicine bottle and the amount of horizontal translation X * ;
通过3)和4)得到药瓶两瓶壁边缘的拟合直线,将两拟合直线的角平分线作为衡量药瓶倾斜程度的倾斜标准线,则药瓶倾斜标准线与x轴的交点X*为 By 3) and 4) the fitted straight lines of the two bottle wall edges of the medicine bottle are obtained, and the angle bisector of the two fitted straight lines is used as the inclination standard line measuring the inclination degree of the medicine bottle, then the intersection point X of the medicine bottle inclination standard line and the x-axis * for
其中,
步骤5:依次对序列图像Image的每帧图像进行第一次校正;Step 5: Perform the first correction on each frame of the sequence image Image in turn;
按照水平平移量X*进行平移,并按照药瓶倾斜角θ*进行旋转变换,平移与旋转变换过程中采用二次插值算法,变换矩阵为Rxi:Translate according to the horizontal translation amount X * , and perform rotation transformation according to the tilt angle θ * of the medicine bottle. During the translation and rotation transformation process, the quadratic interpolation algorithm is used, and the transformation matrix is R xi :
经过旋转与水平平移后,生成新的序列图像Im ageRi,i为小于N的整数,如图5所示,对图像Image0生成新的图片ImageR0;After rotation and horizontal translation, a new sequence image ImageR i is generated, i is an integer less than N, as shown in Figure 5, a new image ImageR 0 is generated for image Image 0 ;
步骤6:采用模板匹配,获取相邻帧图像的纵向偏移量,对图像进行第二次校正;Step 6: Use template matching to obtain the vertical offset of the adjacent frame image, and perform a second correction on the image;
1)选取两帧相邻的图像Im ageRi和Im ageRi+1,分别在两帧图像中的点P′(x0′,y0′)处建立用户坐标系UCS,其中,x0′=Im age Width/2,y0′=Im age Height/10,ImageHeight为图像高度;1) Select two adjacent frames of images ImageR i and ImageR i+1 , respectively establish the user coordinate system UCS at the point P′(x 0 ′,y 0 ′) in the two frames of images, where x 0 ′ =Image Width/2, y 0 '=Image Height/10, ImageHeight is image height;
2)在用户坐标系UCS中设置3个模版对[R1,R2]、[R3,R4]及[R5,R6],模板对必须满足以下条件:2) Set three template pairs [R 1 , R 2 ], [R 3 , R 4 ] and [R 5 , R 6 ] in the user coordinate system UCS, and the template pairs must meet the following conditions:
(1)模板对在用户坐标系中关于y轴对称分布,模板对间距离为10~30像素距离;(1) Template pairs are distributed symmetrically about the y-axis in the user coordinate system, and the distance between template pairs is 10 to 30 pixels;
限制模版对距离的主要原因为,异物旋转到瓶体中间位置时,运动速度方向平行于摄像机成像平面,因此,相对于其他位置,单位时间内在像素间的位移最大,故异物进入模版的概率最小;The main reason for limiting the distance between templates is that when the foreign object rotates to the middle of the bottle body, the direction of motion velocity is parallel to the imaging plane of the camera. Therefore, compared with other positions, the displacement between pixels per unit time is the largest, so the probability of foreign objects entering the template is the smallest. ;
(2)模版对在用户坐标系中的竖直方向均匀分布且布满大部分感兴趣区域;可增大明显特征进入模版的概率;(2) Template pairs are evenly distributed in the vertical direction in the user coordinate system and cover most of the region of interest; the probability of obvious features entering the template can be increased;
(3)模板对中的模板矩阵为15-25个像素的正方形;(3) The template matrix in the template pair is a square of 15-25 pixels;
若太大,则降低图像处理速度,太小,则影响匹配准确度,一般选取20个像素值的正方形,具体根据图像的分辨率、抖动振幅和处理速度需求而定。If it is too large, the image processing speed will be reduced; if it is too small, the matching accuracy will be affected. Generally, a square of 20 pixel values is selected, depending on the image resolution, jitter amplitude, and processing speed requirements.
3)通过灰度直方图方法对图像Im ageRi和Im ageRi+1选取最优匹配模板;3) Select the optimal matching template for images ImageR i and ImageR i+1 by the grayscale histogram method;
分别对图像Im ageRi、Im ageRi+1中的对应模板进行灰度直方图计算,得到灰度直方图矩阵i为图像帧序列编号,j为模板匹配序列编号;For the corresponding templates in the images ImageR i and ImageR i+1 respectively Perform grayscale histogram calculation to obtain grayscale histogram matrix i is the image frame sequence number, j is the template matching sequence number;
计算和的方差并对进行排序,选取排列在前三的方差对应的3个模板作为初步匹配模板矩阵,然后,比较这3个初步匹配模板分别对应的的大小,选取最小所对应的模版矩阵设为最优匹配模板Ppm;calculate and Variance and to Sorting, select the three templates corresponding to the first three variances as the preliminary matching template matrix, and then compare the corresponding size, choose the smallest The corresponding template matrix is set as the optimal matching template P pm ;
在初步匹配模板选取过程中,方差值越大,说明模板图像中的特征信息越明显,匹配操作完成后,得到的匹配精度越高,但在匹配过程中,应选择比较小的模板,这样可以避免因异物进入匹配模板内,而导致的模板匹配失败;In the process of preliminary matching template selection, the larger the variance value, the more obvious the feature information in the template image, and the higher the matching accuracy after the matching operation is completed, but in the matching process, it should be selected A relatively small template, which can avoid template matching failure caused by foreign matter entering the matching template;
4)采用去均值归一化相关法进行模板矩阵匹配,对图像进行纵坐标校正;4) Use the mean value normalization correlation method to carry out template matrix matching, and carry out ordinate correction to the image;
取最优匹配模板Ppm的中心坐标(xpm,ypm),然后,将Ppm与图像Im ageRi+1中的图像窗口Gq进行匹配,其中,Im ageRi+1中的图像窗口Gq的中心坐标为(xpm,ypm+q),q为纵向偏移向量,取值范围是(-10,10)的整数,且Gq长和宽分别与最优匹配模板Ppm长和宽相等;通过采用去均值归一化相关法计算模板匹配度系数ρ(Gq)进行模板与图像窗口的匹配:Take the center coordinates (x pm , y pm ) of the optimal matching template P pm , and then match P pm with the image window G q in the image ImageR i +1, where the image window in ImageR i+1 The center coordinates of G q are (x pm , y pm +q), q is the longitudinal offset vector, the value range is an integer of (-10,10), and the length and width of G q are respectively the optimal matching template P pm The length and width are equal; the template and the image window are matched by calculating the template matching degree coefficient ρ(G q ) by using the mean value normalized correlation method:
其中,Gq(a,b)为在像素图像矩阵Gq中坐标(a,b)处的灰度值,Ppm(a,b)为在最优匹配模板中坐标(a,b)处的灰度值,分别为Gq和Ppm的灰度均值,最优匹配模板和图像窗口中均包含S个像素点,均以左下角为起点坐标;Among them, G q (a, b) is the gray value at the coordinate (a, b) in the pixel image matrix G q , and P pm (a, b) is the coordinate (a, b) in the optimal matching template the gray value of are the gray mean values of G q and P pm respectively, both the optimal matching template and the image window contain S pixels, and both take the lower left corner as the starting point coordinates;
既
(1)比较模板匹配度系数ρ(Gq),选取最大值ρmax作为最优匹配度,ρmax(Gq)中的q值作为Im ageRi+1相对于Im ageRi的纵向偏移为依次计算出图像序列中所有图像与前一帧图像的纵向偏移,记为Mi;(1) Compare the template matching degree coefficient ρ(G q ), select the maximum value ρ max as the optimal matching degree, and the q value in ρ max (G q ) as the longitudinal offset of ImageR i+1 relative to ImageR i for Sequentially calculate the longitudinal offsets of all images in the image sequence and the previous frame image, denoted as M i ;
(2)对图像Im ageRi+1进行纵向平移变换得到图像Im ageR′i+1,平移矩阵为Ry(i+1),完成机械抖动引起的纵向偏移纠正;平移矩阵Ry(i+1)为:(2) Perform vertical translation transformation on the image ImageR i+1 to obtain the image ImageR′ i+1 , and the translation matrix is R y(i+1) to complete the vertical offset correction caused by mechanical shaking; the translation matrix R y(i +1) for:
步骤7:对完成纵向偏移纠正后的序列图像进行绝对差分处理,完成医药异物的检测。Step 7: Absolute difference processing is performed on the sequence images after longitudinal offset correction to complete the detection of medical foreign objects.
经过精确抖动消除后的图像,瓶壁中某一污迹或玻斑在序列帧图像中的成像位置基本相同,偏差不会很大,因此,在两帧相邻图像绝对差分过程中,将会被消除,对图像中的微弱异物目标影响较小。In the image after precise jitter removal, the imaging position of a certain stain or glass spot on the bottle wall in the sequence frame images is basically the same, and the deviation will not be large. Therefore, in the process of absolute difference between two adjacent images, there will be It is eliminated, and has little influence on the faint foreign objects in the image.
所述步骤7的具体实现步骤为:The concrete implementation steps of described step 7 are:
(1)对相邻两帧图像Im ageRi′和Im ageR′i+1进行绝对差分处理,得到差分图像Sub Im ageRi=|Im ageRi′-Im ageR′i+1|,i∈[1,N-1]且i∈Z;(1) Perform absolute difference processing on two adjacent frames of images ImageR i ′ and ImageR′ i+1 to obtain the difference image Sub ImageR i =|Im ageR i ′-Im ageR′ i+1 |,i∈[ 1,N-1] and i∈Z;
相邻帧图像的精确配准操作,能够保证一次差分操作能够消除图像的背景信息(包括瓶壁污迹、玻包、瓶体裂痕等),而不影响液体中运动的异物成像特征。The precise registration operation of adjacent frame images can ensure that a differential operation can eliminate the background information of the image (including bottle wall stains, glass bags, bottle cracks, etc.), without affecting the imaging characteristics of foreign objects moving in the liquid.
(2)对一次差分图像进行给定阈值T的二值化处理,得到二值化图像Bin Im ageRi,T取值的是根据检测对象的特征确定,一般玻璃屑的成像灰度值较大,阈值T也较大,毛发、纤维等细长物体,灰度值与背景相差不大,阈值T选取较小;(2) Binarize the primary difference image with a given threshold T to obtain the binarized image Bin ImageR i , the value of T is determined according to the characteristics of the detection object, and the imaging gray value of glass shavings is generally larger , the threshold T is also relatively large, and for slender objects such as hair and fibers, the gray value is not much different from the background, and the threshold T is selected to be small;
(3)对序列帧二值图像Bin Im ageRi进行叠加操作:(3) Perform superposition operation on sequence frame binary image Bin ImageR i :
Im agemax=MAX{Bin Im ageR1,…Bin Im ageRN-1},N为序列帧总数Image max =MAX{Bin ImageR 1 ,...Bin ImageR N-1 }, N is the total number of sequence frames
(4)求取Im agemax的连通域,统计连通域的个数Numtotal,连通域面积总和Areatotal以及面积大于给定值的连通域个数(为异物最小成像面积);(4) Find the connected domain of Image max , count the number of connected domains Num total , the sum of the areas of connected domains Area total and the area greater than a given The number of connected domains of the value ( is the minimum imaging area of foreign matter);
(5)根据计算的数据量,判断医药质量是否合格,产品质量θ为(5) According to the amount of calculated data, it is judged whether the quality of the medicine is qualified, and the product quality θ is
α和β分别为产品质量正品和次品阈值,α设置为5,β设置为20。α and β are the genuine and defective product quality thresholds respectively, α is set to 5, and β is set to 20.
Claims (3)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310113316.7A CN103226814B (en) | 2013-04-02 | 2013-04-02 | A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201310113316.7A CN103226814B (en) | 2013-04-02 | 2013-04-02 | A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification |
Publications (2)
Publication Number | Publication Date |
---|---|
CN103226814A CN103226814A (en) | 2013-07-31 |
CN103226814B true CN103226814B (en) | 2015-09-30 |
Family
ID=48837249
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201310113316.7A Active CN103226814B (en) | 2013-04-02 | 2013-04-02 | A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN103226814B (en) |
Families Citing this family (25)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103489195B (en) * | 2013-10-11 | 2016-05-18 | 胡晓彤 | Metal can body pattern direction detection method |
CN104657940B (en) * | 2013-11-22 | 2019-03-15 | 中兴通讯股份有限公司 | Distorted image correction restores the method and apparatus with analysis alarm |
CN103942792B (en) * | 2014-04-15 | 2015-05-20 | 湖南大学 | Impurity detecting method in medicine detection robot based on time domain features of sequence images |
CN104657977B (en) * | 2014-12-10 | 2017-09-22 | 天津普达软件技术有限公司 | A kind of method for positioning bottle base body center |
CN105139381B (en) * | 2014-12-10 | 2017-12-05 | 天津普达软件技术有限公司 | A kind of method for positioning bottle base body |
CN104537631B (en) * | 2015-02-05 | 2017-07-21 | 哈尔滨工业大学 | A kind of PLIF method for correcting image based on digital image registration technique |
CN104819754B (en) * | 2015-05-13 | 2017-09-29 | 山东大学 | A kind of medicine bottle liquid-level detecting method based on image procossing |
CN104835166B (en) * | 2015-05-13 | 2017-09-29 | 山东大学 | Liquid medicine bottle foreign matter detecting method based on machine vision detection platform |
CN105184770B (en) * | 2015-08-05 | 2017-11-03 | 哈尔滨工业大学 | A kind of soldered ball positioning and its parameter identification method for ball grid array pin chip |
CN105427321B (en) * | 2015-12-01 | 2018-06-26 | 天津普达软件技术有限公司 | Whether the method for soft bag is had on a kind of detection pallet |
CN106023211B (en) * | 2016-05-24 | 2019-02-26 | 深圳前海勇艺达机器人有限公司 | Robot graphics' localization method and system based on deep learning |
CN108154154B (en) * | 2017-11-13 | 2022-03-29 | 广东三维家信息科技有限公司 | Method for detecting number of traditional Chinese medicine tablets in regular grids |
CN108389195B (en) * | 2018-02-24 | 2021-02-23 | 北京理工大学 | Image detection method and device |
CN108888284A (en) * | 2018-05-18 | 2018-11-27 | 沈阳东软医疗系统有限公司 | Image adjusting method, device and equipment, storage medium |
CN109166142A (en) * | 2018-07-30 | 2019-01-08 | 山东大学 | The visible detection method of visible foreign matters in a kind of System of Infusion Drugs |
CN109360195A (en) * | 2018-09-28 | 2019-02-19 | 长沙湘计海盾科技有限公司 | The visible detection method of foreign particles in a kind of bottle-packaging solution |
CN110587616B (en) * | 2019-08-20 | 2023-01-24 | 辽宁成大生物股份有限公司 | Cell factory operation process method |
CN111335633A (en) * | 2020-03-06 | 2020-06-26 | 中核华辰建筑工程有限公司 | Multifunctional assembled building assembly construction floor combined leveling device and method |
CN111652842B (en) * | 2020-04-26 | 2021-05-11 | 佛山读图科技有限公司 | Real-time visual detection method and system for high-speed penicillin bottle capping production line |
CN111931786B (en) * | 2020-06-23 | 2022-02-01 | 联宝(合肥)电子科技有限公司 | Image processing method and device and computer readable storage medium |
CN114577310B (en) * | 2022-01-21 | 2024-11-22 | 北京信息科技大学 | A detection system for liquid level of microplate |
CN114972566B (en) * | 2022-05-27 | 2025-05-09 | 西安盈谷网络科技有限公司 | A method, device and storage medium for removing bed board in CT sequence images |
CN115546072B (en) * | 2022-11-28 | 2023-03-10 | 南京航空航天大学 | A method of image distortion correction |
CN116223521A (en) * | 2022-12-26 | 2023-06-06 | 上海卫星装备研究所 | Method and system for automatic detection of defects in satellite electrical connector contacts |
CN117470719B (en) * | 2023-12-27 | 2024-03-12 | 山西省生态环境监测和应急保障中心(山西省生态环境科学研究院) | Multifunctional environment monitoring robot |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5734467A (en) * | 1995-07-31 | 1998-03-31 | Coors Brewing Company | Inspection apparatus for high temperature environments |
CN101354359A (en) * | 2008-09-04 | 2009-01-28 | 湖南大学 | Detection, tracking and identification method of visible foreign objects moving in liquid medicine |
CN101859378A (en) * | 2010-06-11 | 2010-10-13 | 湖南大学 | Visual inspection method for liquid medicine quality on high-speed pharmaceutical production line |
CN102175693A (en) * | 2011-03-08 | 2011-09-07 | 中南大学 | Machine vision detection method of visual foreign matters in medical medicament |
CN102519984A (en) * | 2011-11-16 | 2012-06-27 | 湖南大学 | Anti-vibration machine vision detection method of foreign matters in liquid medicine |
WO2012172695A1 (en) * | 2011-06-15 | 2012-12-20 | キリンテクノシステム株式会社 | Method and device for inspecting glass bottle |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102472707B (en) * | 2010-05-20 | 2014-03-12 | 松下电器产业株式会社 | Drug solution determination device and drug solution determination method |
-
2013
- 2013-04-02 CN CN201310113316.7A patent/CN103226814B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US5734467A (en) * | 1995-07-31 | 1998-03-31 | Coors Brewing Company | Inspection apparatus for high temperature environments |
CN101354359A (en) * | 2008-09-04 | 2009-01-28 | 湖南大学 | Detection, tracking and identification method of visible foreign objects moving in liquid medicine |
CN101859378A (en) * | 2010-06-11 | 2010-10-13 | 湖南大学 | Visual inspection method for liquid medicine quality on high-speed pharmaceutical production line |
CN102175693A (en) * | 2011-03-08 | 2011-09-07 | 中南大学 | Machine vision detection method of visual foreign matters in medical medicament |
WO2012172695A1 (en) * | 2011-06-15 | 2012-12-20 | キリンテクノシステム株式会社 | Method and device for inspecting glass bottle |
CN102519984A (en) * | 2011-11-16 | 2012-06-27 | 湖南大学 | Anti-vibration machine vision detection method of foreign matters in liquid medicine |
Non-Patent Citations (1)
Title |
---|
基于图像处理的瓶装液体异物检测研究;黄超灵;《中国优秀硕士学位论文全文数据库信息科技辑》;20080815;第33-50页 * |
Also Published As
Publication number | Publication date |
---|---|
CN103226814A (en) | 2013-07-31 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103226814B (en) | A kind of medicine bottle foreign matter detecting method based on medical visual detection robot image rectification | |
CN104359403B (en) | Planar part dimension measurement method based on sub-pixel edge algorithm | |
CN106778737B (en) | A kind of license plate antidote, device and a kind of video acquisition device | |
CN102162797B (en) | Algorithm for detecting glass bottle neck damage and bottle bottom dirt | |
CN105286871B (en) | Video processing-based body height measurement method | |
CN104819754B (en) | A kind of medicine bottle liquid-level detecting method based on image procossing | |
CN105334219A (en) | Bottleneck defect detection method adopting residual analysis and dynamic threshold segmentation | |
CN104835166B (en) | Liquid medicine bottle foreign matter detecting method based on machine vision detection platform | |
CN102654902A (en) | Contour vector feature-based embedded real-time image matching method | |
CN110390696A (en) | A visual detection method of circular hole pose based on image super-resolution reconstruction | |
CN103593849B (en) | Method for quickly recognizing and tracking image sequence oval artificial target points | |
CN103295239A (en) | Laser-point cloud data automatic registration method based on plane base images | |
CN110189375A (en) | An Image Target Recognition Method Based on Monocular Vision Measurement | |
CN116563279B (en) | Measuring switch detection method based on computer vision | |
CN103247032B (en) | Weak extended target positioning method based on attitude compensation | |
CN105784722A (en) | Method and system of detecting visible foreign matters in medicine liquid bottles on flow line | |
CN102708368A (en) | Method for positioning bottle bodies on production line based on machine vision | |
EP3163604A1 (en) | Position detection apparatus, position detection method, information processing program, and storage medium | |
CN106546174B (en) | A kind of circle detection method based on model filtering | |
CN106845535B (en) | Typical Components recognition methods based on cloud | |
CN106815830A (en) | The defect inspection method of image | |
CN108335332A (en) | A kind of axial workpiece central axes measurement method based on binocular vision | |
CN106441162A (en) | Cylindrical object verticality noncontact detection device and method | |
CN114998437A (en) | A method for centroid location of space target | |
CN105488802A (en) | Fingertip depth detection method and system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C14 | Grant of patent or utility model | ||
GR01 | Patent grant |