Untitled

 avatar
unknown
plain_text
2 months ago
2.3 kB
2
Indexable

Hlines = zeros(4,3);
Llines = zeros(3,3);
Mlines = zeros(6,3);
Circumference = zeros(3,3);
curve = zeros(3,3);



img = imread("Look-outCat.jpg");
imgOriginal = img;

%Controlliamo che l'immagine sia in RGB, quindi la trasformiamo in scala di
%grigi
if size (img,3) == 3 
    grayimage = rgb2gray(img);
end

%miglioriamo il contrasto 
img = imadjust(grayimage);

%rileviamo i bordi tramite l'algoritmo di canny
img = edge(img,"canny",0.05);


%identifico le linee rette tramite la trasformata di hough
[H,teta,rho] = hough(img);
numpeaks = 50; 
p = houghpeaks(H,numpeaks,"Threshold",ceil(0.1*max(H(:))));
lines = houghlines(img,teta,rho,p,"FillGap",5,"MinLength",7);

imshow(img);
 
for k = 1:length(lines)
   xy = [lines(k).point1; lines(k).point2];
   angle = abs(atan2d(xy(2,2)-xy(1,2),xy(2,1)-xy(1,1)));
   if angle <0
       angle = angle +180;
   end
   if (angle < 30) || (angle > 120)
        plot(xy(:,1), xy(:,2), 'LineWidth', 2, 'Color', 'blue');
   elseif (angle>=75 && angle <=105)
        plot(xy(:,1), xy(:,2), 'LineWidth', 2, 'Color', 'green');
   else
        plot(xy(:,1), xy(:,2), 'LineWidth', 2, 'Color', 'red');
   end
end

imshow(imgOriginal);
hold on;

Hlines(1,:) = cross([321 592 1],[384 236 1]);
Hlines(2,:) = cross([801 654 1],[778 317 1]);
Hlines(3,:) = cross([1075 341 1],[1093 417 1]);
Hlines(4,:) = cross([1316 384 1],[1419 665 1]);

Llines(1,:) = cross([402 249 1],[673 282 1]);
Llines(2,:) = cross([470 712 1],[1345 698 1]);
Llines(3,:) = cross([454 775 1],[1166 749 1]);

%[x, y]=getpts;
%scatter(x,y,100,'filled');
Mlines(1,:) = cross([402 250 1],[464 456 1]);
Mlines(2,:) = cross([776 296 1],[720 470 1]);
Mlines(3,:) = cross([969 461 1],[1070 348 1]);
Mlines(4,:) = cross([1165 482 1],[1300 388 1]);
Mlines(5,:) = cross([305 716 1],[420 778 1]);
Mlines(6,:) = cross([1441 697 1],[1175 753 1]);



%Vanishing point find bu using l1 and l3
V1 = cross(Llines(1,:),Llines(3,:));
V1 = V1/V1(3);
plot(V1(1),V1(2),'.b','MarkerSize',30);
text(V1(1),V1(2), 'v1', 'FontSize', 18, 'Color', 'w');

%Vanishing point find bu using m1 and m4
V2 = cross(Mlines(1,:),Mlines(4,:));
V2 = V2/V2(3);
plot(V2(1),V2(2),'.b','MarkerSize',30);
text(V2(1),V2(2), 'v2', 'FontSize', 18, 'Color', 'w');

vanishingLine = cross(V1,V2);
plot([V1(1),V2(1)],[V1(2),V2(2)],'LineWidth', 2, 'Color', 'blue')


Leave a Comment