[英]Plot rectangle boxes on image using MATLAB
在這里,我開發了一些用於在圖像上繪制框的代碼,但我得到了
不同圖像上的框。 所有的盒子都應該在同一個圖像中。 請幫助我。
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
每次運行代碼時都會打開一個新窗口。 您應該在顯示之前指定要使用的圖形窗口。
所以而不是這個:
figure, imshow(J);
做這個:
figure(1), imshow(J);
這應該每次都在同一個圖形窗口(圖形編號 1)中顯示圖像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.