MATLAB: How to plot the center point on the line

biometricseyesfacefind center point on lineimage processingImage Processing Toolboxlipsmouth

I = imread('Image1.jpg');
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',400);
BB=step(MouthDetect,I);
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',2,'LineStyle','-','EdgeColor','r');
nbox = step(MouthDetect, I);
x1 = nbox(1) + nbox(3)/2;
y1 = nbox(2) + nbox(4)/2;
plot(x1,y1, 'Marker','+','Color','red','MarkerSize',10);
EyeDetect = vision.CascadeObjectDetector('EyePairBig');
BB=step(EyeDetect,I);
hold on
rectangle('Position',BB(i,:),'LineWidth',2,'LineStyle','-','EdgeColor','b');
nbox = step(EyeDetect, I);
x2 = nbox(1) + nbox(3)/2;
y2 = nbox(2) + nbox(4)/2;
plot(x2,y2, 'Marker','+','Color','red','MarkerSize',10);
p=plot([x1 x2],[y1 y2], 'Marker','+','Color','red','MarkerSize',10);
end

Best Answer

The center is the average of the two endpoints of course.
xCenter = (x1+x2)/2;
yCenter = (y1+y2)/2;
hold on;
plot(xCenter, yCenter, 'r*', 'MarkerSize', 24, 'LineWidth', 2);