【发布时间】:2019-05-20 19:03:37
【问题描述】:
I hope this image helps. 我从相机拍摄了一张图像并在其上生成了网格。我怎么知道我的质心在哪个网格中?我需要生成一个可以进一步使用的变量或数字。例如,质心在第 3 个框中,它生成 3,我可以使用串行通信将其发送到 Arduino 以进行进一步操作。我希望你能明白。在这种情况下,投资回报率是否会有所帮助,如果是,那么我该如何使用它?
图像中已经生成了质心和边界框 使用此代码。
stat = regionprops(Ibw1, 'Centroid', 'BoundingBox')
hold on
for x=1:numel(stat)
rectangle('Position',stat(x).BoundingBox,'EdgeColor','r','LineWidth',1);
plot(stat(x).Centroid(1),stat(x).Centroid(2),'r*');
end
hold off
在此之后,我使用此代码为图像生成网格。
[rows, columns, ~] = size(I);
for row = 1 : 52 : rows
line([1, columns], [row, row], 'Color', 'r');
end
for col = 1 : 53 : columns
line([col, col], [1, rows], 'Color', 'r');
end
【问题讨论】:
-
示例图片会有所帮助。
-
你问怎么办
floor(stat(x).Centroid(1) / boxWidth)? -
正如您在示例图像中看到的,Centroid 存在于所有网格的单个网格中。我如何编码以找到该质心所在的确切网格?
标签: matlab image-processing grid centroid