Sending commands after detecting red colour in a captured image.

1 view (last 30 days)
I've found a program online that is able to detect red through live image and i was able to stop the live video after a certain amount of time. However i would like to send the data for the red that is captured for further commands. Would using 'stats' in the code below be able to send the captured red data for further commands?
vid = videoinput('winvideos', 1);
set(vid, 'FramesPerTrigger', Inf);
set(vid, 'ReturnedColorSpace', 'rgb');
vid.FrameGrabInterval = 1;
start(vid)
while (vid.FramesAcquired<=10)
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');
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)+15, bc(2), '-m+')
end
hold off
end
stop(vid);
flushdata(vid);
clear all

Accepted Answer

Image Analyst
Image Analyst on 11 Oct 2015
Yes, it would. The variable "stats" is a structure array that contains all the measurements you specified, and you can send that to any other function you want, or use it in the same function.
  2 Comments
Coco
Coco on 12 Oct 2015
Would the variable "stats" also be able to send the data for red not being detected?
Image Analyst
Image Analyst on 12 Oct 2015
You got stats by measuring an image you thresholded. That image is the difference between the red channel and a weighted average of the red, green, and blue channel. Not sure what that difference means exactly but whatever it is, stats will have information about it. Note that it is not strictly all about the red image since you're subtracting an image that is a weighted sum of all the channels, not just the red channel. What you did is not really a good algorithm for finding red. If you want to find red in a video, just modify my attached demo where I find and track green blobs.

Sign in to comment.

More Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!