2016-05-26 75 views
1

这里我开发了一些用于绘制图像框的代码,但是我在不同的图像上获取了
框。所有的盒子应该在相同的图像。 请帮我。使用MATLAB在图像上绘制矩形框

output image 1

output image 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 

回答

1

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

因此,不是这样的:

figure, imshow(J); 

做到这一点:

figure(1), imshow(J); 

这应该显示在同一图窗口每次(图号1)的图像。

+0

或者在for循环之前打开数字并使用循环中的句柄。像'fig1 = figure;'然后'为... figure(fig1)... end'。 – shamalaia

+0

它不起作用 –

+0

说实话,你的问题并没有很好的定义。这是不明显的你想要做什么。我认为你的问题是,带有红色矩形的图像出现在一个数字窗口中,绿色的图像出现在另一个数字窗口中。那是对的吗? – kkuilla