你好吗?我需要帮助。我读取图像然后显示它,然后单击图像上的两个点说:p1和p2。现在我想画线(如果可能的话,箭头)表明这些是与地平面正交的向量。然后画平行于y轴的线,每个点都说l1和l2最后计算这些线之间的最短距离。我得到了分数,画了线,但不知道如何得到距离。我还观察到,对于一条线它工作正常,但对于两条线,它们被绘制在不同的位置,我不知道为什么。我一直在尝试这样做大约三天,但我得到的结果与我想要的相差甚远。至于某些部分不知道该怎么做。以下是我目前拥有的代码。我还附上了一张图片,展示了想要实现的目标。我希望它可以理解。我删除了我试图获得距离的部分,因为即使我知道我需要这些线中的四个点来估计它们之间的最短距离,我也不知道如何获得这些点:( - 我愿意接受建议。 [![在此处输入图像描述][1]][1]
谢谢您的帮助。PS。让我知道我想做什么是不可能的。不过,当我开始这样做时,这对我来说似乎是合乎逻辑的。
以下是我当前的代码
% Read and display image
i = imread('sample.jpg');
im = i;
f = figure;
imshow(im);
% Get user clicked points
[p1 p2] = getpts(f);
% Draw parallel vertical lines at given pts. parallel to the y-axis/post
hold on;
line([p1(1) p1(1)], get(gca, 'ylim'));
line([p2(1) p2(1)], get(gca, 'ylim'));
% Calculate shortest distance between these two lines
% - not sure how to proceed with this because as far as i know I need at
% least 4 points to determine where they meet :(
% Draw vector symbols at points
% 1. draw x component arrow/line - parallel to the x-axis of image
% (or perpendicular to y-axis??) but must be perpendicular to ground plane
% Slope of current line
m = (diff(p1)/diff(get(gca, 'ylim')));
% Slope of new line
Li = 10 ;
minv = -1/m;
line([mean(p1) mean(p1)+Li],[mean(get(gca, 'ylim')) mean(get(gca, 'ylim'))+Li*minv],'Color','r')
% 2. draw y component arrow/line - parallel to the y-axis of image
% Slope of current line
m = (diff(p2)/diff(get(gca, 'ylim')));
% Slope of new line
Li = 10 ;
minv = -1/m;
line([mean(p2) mean(p2)+Li],[mean(get(gca, 'ylim')) mean(get(gca, 'ylim'))+Li*minv],'Color','k')
axis equal;