Get rectangle of 4 points and detect formed rectangle orientation

4 次查看(过去 30 天)
Hello, I have an image as shown below
I wrote the following script to detect their centroids
clc;
clear all;
imgRGB = imread('img1.png');
subplot(2,2,1)
imshow(imgRGB), title('Original Image')
imgGray = rgb2gray(imgRGB);
subplot(2,2,2)
imshow(imgGray),title('Gray Image')
imgBinary = imbinarize(imgGray,'global');
imgBinary = imcomplement(imgBinary);
subplot(2,2,3)
imshow(imgBinary), title('Binary Image')
hblob = vision.BlobAnalysis;
hblob.Connectivity = 8;
hblob.AreaOutputPort = false;
hblob.BoundingBoxOutputPort = false;
centroid = step(hblob,imgBinary);
table(centroid)
subplot(2,2,4)
imshow(imgRGB), title('Detected Objects')
hold on
for i = 1 : numel(centroid(:,1))
plot(centroid(i,1),centroid(i,2),'+r');
end
My two questions are:
  1. Is there any mean to draw a rectangle lines between them even if image is rotated ?
  2. Id there any mean to detect the orientation of formed rectangle ?

回答(1 个)

Image Analyst
Image Analyst 2018-4-30
Once you have the centroids, you can use plot() to plot a line in the overlay above the image. It doesn't care if the rectangle is aligned with vertical and horizontal or not. If you need them burned into the image, you can use imline() to create a binary image that you can use as a mask to burn in values.

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by