Color Tracking with Webcam, how do I speed it up??
Show older comments
This is my code:
clear all
vid=videoinput('winvideo',1);
set(vid,'ReturnedColorSpace','RGB');
for x = 1:10
img = getsnapshot(vid);
R = img(:,:,1);
G = img(:,:,2);
B = img(:,:,3);
a = find(R>90 & R<157 & G>0 & G<100 & B>0 & B<81);
BW=zeros(480,640);
BW(a)=1;
imshow(BW)
end
1 Comment
Walter Roberson
on 14 Jul 2012
Please do not use "matlab" as a Tag. http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
Answers (1)
Walter Roberson
on 11 Jul 2012
Change your two lines
BW=zeros(480,640);
BW(a)=1;
to
BW = double(a);
This would produce exactly the same matrix as you are now producing.
You might possibly get slightly better graphics performance with uint8 instead of double, but you'd want to time carefully to be sure. For that,
BW = uint8(255) .* uint8(a);
or maybe
BW = uint8( 255 .* a );
or perhaps even
T = uint8([0 255]);
BW = T(1 + a);
Categories
Find more on Convert Image Type 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!