Clear Filters
Clear Filters

how to take two images from real time image processing?

4 views (last 30 days)
I'm working on a real time image processing... i wrote a code to take an image from the video and then used (pause(3)) function to wait for 3 seconds, and then repeat the first codes again to take anther image. But the second image comes same as the first one with no change. why it's not changing ? why the same image is coming again?
  3 Comments
Image Analyst
Image Analyst on 30 Apr 2016
Maybe you're not moving the camera or changing the scene or lighting. Maybe you call imshow() only once for the first image. Who knows? How can we know?
haya yousuf
haya yousuf on 30 Apr 2016
Edited: Walter Roberson on 30 Apr 2016
this is the code for taking the second image:
pause(3)
while(vid.FramesAcquired<=200)
data = getsnapshot(vid);
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
diff_im = medfilt2(diff_im, [3 3]);
diff_im = im2bw(diff_im,0.18);
diff_im = bwareaopen(diff_im,300);
bw = bwlabel(diff_im, 8);
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
end
boxim=imcrop(data,bb);
figure(2)
imshow(boxim)
k=rgb2gray(boxim);
BW1 = edge(k,'sobel');%, 0.5);
imshow(BW1);
flushdata(vid);

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 30 Apr 2016
Get rid of imshow where you have it and put it after getsnapshot. Then call drawnow;
data = getsnapshot(vid);
imshow(data);
drawnow;

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!