ウェブカメラからのビデオで赤いオブジェクトを検出して追跡し、空白の背景で対応する強度値を上げて、仮想の描画パッドを作成しようとしています。このコードを使用して赤いオブジェクトを追跡しています
data = getsnapshot(vid);
diff_im = imsubtract(data(:,:,1), rgb2gray(data)); %find red regions in image
diff_im = medfilt2(diff_im, [3 3]); %Use a median filter to filter out noise
diff_im = im2bw(diff_im,0.18); % Convert the resulting grayscale image into a binary image.
diff_im = bwareaopen(diff_im,300); % Remove all those pixels less than 300px,
[bw, count] = bwlabel(diff_im, 8);
if(count > 0)
%% then draw rectangle around centroid of detected object
すべてのピクセルをチェックしているため、画像サイズが大きくなると処理時間が長くなります (640*480 の場合でも)。この結果、多くのフレームで出力が空白になります。どうすれば改善できますか..??