How to display result
조회 수: 9 (최근 30일)
이전 댓글 표시
Dear all, I have a question. I would to display result in another window. for example when code running a window will appear to display position of red color X(x,y). If i want to display Y = 2*X (e.t.c) in the second window. how can I do that?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Program Name : Red Object Detection and Tracking % % Author : Arindam Bose % % Version : 1.05 % % Description : How to detect and track red objects in Live Video % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Initialization redThresh = 0.25; % Threshold for red detection vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480', ... % Acquire input video stream 'ROI', [1 1 640 480], ... 'ReturnedColorSpace', 'rgb'); vidInfo = imaqhwinfo(vidDevice); % Acquire input video property hblob = vision.BlobAnalysis('AreaOutputPort', false, ... % Set blob analysis handling 'CentroidOutputPort', true, ... 'BoundingBoxOutputPort', true', ... 'MinimumBlobArea', 800, ... 'MaximumBlobArea', 3000, ... 'MaximumCount', 10); hshapeinsRedBox = vision.ShapeInserter('BorderColor', 'Custom', ... % Set Red box handling 'CustomBorderColor', [1 0 0], ... 'Fill', true, ... 'FillColor', 'Custom', ... 'CustomFillColor', [1 0 0], ... 'Opacity', 0.4); htextins = vision.TextInserter('Text', 'Number of Red Object: %2d', ... % Set text for number of blobs 'Location', [7 2], ... 'Color', [1 0 0], ... // red color 'FontSize', 12); htextinsCent = vision.TextInserter('Text', '+ X:%4d, Y:%4d', ... % set text for centroid 'LocationSource', 'Input port', ... 'Color', [1 1 0], ... // yellow color 'FontSize', 14); hVideoIn = vision.VideoPlayer('Name', 'Final Video', ... % Output video player 'Position', [100 100 vidInfo.MaxWidth+20 vidInfo.MaxHeight+30]); nFrame = 0; % Frame number initialization
%% Processing Loop while(nFrame < 20) rgbFrame = step(vidDevice); % Acquire single frame rgbFrame = flipdim(rgbFrame,2); % obtain the mirror image for displaying diffFrame = imsubtract(rgbFrame(:,:,1), rgb2gray(rgbFrame)); % Get red component of the image diffFrame = medfilt2(diffFrame, [3 3]); % Filter out the noise by using median filter binFrame = im2bw(diffFrame, redThresh); % Convert the image into binary image with the red objects as white [centroid, bbox] = step(hblob, binFrame); % Get the centroids and bounding boxes of the blobs centroid = uint16(centroid); % Convert the centroids into Integer for further steps rgbFrame(1:20,1:165,:) = 0; % put a black region on the output stream vidIn = step(hshapeinsRedBox, rgbFrame, bbox); % Instert the red box for object = 1:1:length(bbox(:,1)) % Write the corresponding centroids centX = centroid(object,1); centY = centroid(object,2); vidIn = step(htextinsCent, vidIn, [centX centY], [centX-6 centY-9]); end vidIn = step(htextins, vidIn, uint8(length(bbox(:,1)))); % Count the number of blobs step(hVideoIn, vidIn); % Output video stream nFrame = nFrame+1; end %% Clearing Memory release(hVideoIn); % Release all memory and buffer used release(vidDevice); % clear all; clc;
thanks in advance.
댓글 수: 0
답변 (2개)
David Sanchez
2013년 5월 16일
Use the {}Code option, please, that would help a lot in telling code from comment.
Did you try
figure(2)
before displaying the second figure?
댓글 수: 0
Chandan Gogoi
2017년 1월 10일
use
disp(length(bbox(:,1));
just before the end of while loop.By storing this value to a variable,you can use this value for any purpose like transferring it to arduino,then show it with the help of lcd...etc.etc
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!