1

在这里,我开发了一些用于在图像上绘制框的代码,但我得到
了不同图像上的框。所有的盒子都应该在同一个图像中。请帮助我。

输出图像 1

输出图像 2

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
4

1 回答 1

1

每次运行代码时,您都会打开一个新窗口。您应该在显示之前指定要使用的图形窗口。

所以代替这个:

figure, imshow(J);

做这个:

figure(1), imshow(J);

那应该每次都在同一个图形窗口(图形编号 1)中显示图像。

于 2016-05-26T08:36:50.973 回答