[英]Plot rectangle boxes on image using MATLAB
Here I am developed some code for plotting boxes on image but I am getting在这里,我开发了一些用于在图像上绘制框的代码,但我得到了
boxes on different image.不同图像上的框。 All the boxes should be in same image.
所有的盒子都应该在同一个图像中。 Please help me in this.
请帮助我。
video = VideoReader('parking video1.mp4');
I = read(video,1);
J = read(video,200);
a=104; b=73;
c=104; d=515;
count=0;count1=0;count2=0;
total=10;
for i=1:5
im1=imcrop(I,[a,b,283, 448]);
im3=imcrop(J, [a,b,283, 448]);
Background1 =abs(im1 - im3);
grayImage1 = rgb2gray(Background1);
% Convert to gray level
thresholdLevel1 = graythresh(grayImage1);
% Get threshold.
binaryImage1 = im2bw( grayImage1, thresholdLevel1);
% Do the binarization
binaryImage1 = bwareaopen(binaryImage1,1000);
ak=bwarea(binaryImage1);
figure, imshow(J);
hold on;
if ak>0
rectangle('Position',[a,b,283, 448],'Edgecolor', 'r');
else
rectangle('Position',[a,b,283, 448],'Edgecolor', 'g');
end
a=a+280;
end
You are opening a new window every time your run the code.每次运行代码时都会打开一个新窗口。 You should specify which figure window to use before showing it.
您应该在显示之前指定要使用的图形窗口。
So instead of this:所以而不是这个:
figure, imshow(J);
do this:做这个:
figure(1), imshow(J);
That should show the image in the same figure window (figure number 1) every time.这应该每次都在同一个图形窗口(图形编号 1)中显示图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.