毕业论文

打赏
当前位置: 毕业论文 > 自动化 >

Matlab生产自动化实验系统机器视觉单元设计+CAD图纸(17)

时间:2016-11-24 21:28来源:毕业论文
圆的极坐标方程为:x = a + r cos y = b + r sin 则圆的参数为:x = a + r cos y = b + r sin 其中为梯度角,对于每一个在(x,y)处的,并且具有边缘方向角的边缘点,如


圆的极坐标方程为:x = a + r cosθ   y = b + r sinθ
则圆的参数为:x = a + r cosθ      y = b + r sinθ
其中θ为梯度角,对于每一个在(x,y)处的,并且具有边缘方向角θ的边缘点,如果半径已知,即可设置一个增量累加器,根据上述公式求出对应的 a、b 值,从而进行累加,确定圆心的位置。
如上传统的 Hough 有如下的特点:
(1) 参数由直线的两个参数即截距和斜率,上升到三个即圆心坐标和半径;每个点映射成参数空间的一个曲面是一对多映射,因而计算量急剧增大;
 
图 5.2.4.1 Hough 变换检测圆心      图 5.2.4.2 针对性 Hough 检测圆周
(2) 需占用大量内存空间,耗时久、实时性差;


5.3演示实例
5.3.1识别圆的实例
RGB = imread('pillsetc.png');%读取图像
figure; imshow(RGB);%显示
I = rgb2gray(RGB);%转化为灰度图像
threshold = graythresh(I);%阈值
bw = im2bw(I,threshold);%转化为二值图像
figure; imshow(bw)%显示二值图像
bw = bwareaopen(bw,30);%去除小目标
se = strel('disk',2);%圆形结构元素
bw = imclose(bw,se);%关操作
bw = imfill(bw,'holes');%填充孔洞
figure; imshow(bw)%显示填充孔洞后的图像
[B,L] = bwboundaries(bw,'noholes');%图像边界
figure; imshow(label2rgb(L, @jet, [.5 .5 .5]))%不同颜色显示
hold on
for k = 1:length(B)
 boundary = B{k};
 plot(boundary(:,2),boundary(:,1), 'w', 'LineWidth', 2)%显示白色边界
end
stats = regionprops(L,'Area','Centroid');%求取面积、质心等
threshold = 0.94;%阈值
for k = 1:length(B)
  boundary = B{k};
  delta_sq = diff(boundary).^2;
  perimeter = sum(sqrt(sum(delta_sq,2)));%求取周长
  area = stats(k).Area;%面积
  metric = 4*pi*area/perimeter^2;%圆形的量度
  metric_string = sprintf('%2.2f',metric);
  if metric > threshold
    centroid = stats(k).Centroid;
    plot(centroid(1),centroid(2),'ko');%标记圆心
  end
  text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'Color',...
      'y', 'FontSize',14,'FontWeight','bold');%标注圆形度量
end
title(['Metrics closer to 1 indicate that ',...
       'the object is approximately round']);
输出:
5.3.2检测半径实例
RGB = imread('tape.png');%读取图像
figure; imshow(RGB);%显示
text(15,15,'Estimate radius of the roll of tape',...
     'FontWeight','bold','Color','y');
I = rgb2gray(RGB);%转化为灰度图像
threshold = graythresh(I);%阈值
BW = im2bw(I,threshold);%转化为二值图像
figure; imshow(BW)%显示二值图像
dim = size(BW);%图像大小
col = round(dim(2)/2)-90;%边界起始点的列
row = find(BW(:,col), 1);%边界起始点的行
connectivity = 8;%连通性为8
num_points   = 180;%边界点的个数
contour = bwtraceboundary(BW, [row, col], 'N',...
    connectivity, num_points);%求取圆周
figure;  imshow(RGB);%显示原图像
hold on;
plot(contour(:,2),contour(:,1),'g','LineWidth',2);%显示绿色边界
x = contour(:,2); y = contour(:,1);
abc = [x y ones(length(x),1)] \ -(x.^2+y.^2);%计算参数
a = abc(1); b = abc(2); c = abc(3);
xc = -a/2;%圆心的x轴坐标
yc = -b/2;%圆心的y轴坐标 Matlab生产自动化实验系统机器视觉单元设计+CAD图纸(17):http://www.751com.cn/zidonghua/lunwen_276.html
------分隔线----------------------------
推荐内容