how to draw bounding box to a object in a video after finding its centroid basing on its color ?
Mostra commenti meno recenti
It is the code we worked on please help me to draw bounding box we left with only 2 days to submit our project .any one plz help me i have placed the source code and the video we working on by zipping the files run the code by placing the video and help me to draw bounding box around the ball clc; clear all; close all; %----------------video input--------------------------------------% vid=uigetfile('.avi','select an video'); info=mmfileinfo(vid); t=info.Duration; vid=mmreader(vid); numFrames = vid.NumberOfFrames; n=numFrames; get(vid); framerate=vid.FrameRate; for i =1:50 frames = read(vid,i); imwrite(frames,strcat([int2str(i) '.tif'])); end for i= 1:50 if(i<50) greenBall1=imread([int2str(i),'.tif']); greenball2=imread([int2str(i+1),'.tif']); %------------------------------------------------------------------% %figure;imshow(greenBall1);figure; r = greenBall1(:, :, 1); g = greenBall1(:, :, 2); b = greenBall1(:, :, 3); justGreen = g - r/2 - b/2; bw = justGreen > 50; figure;imagesc(greenBall1); % figure; % imagesc(bw); % colormap(gray); ball1 = bwareaopen(bw, 30); % figure; % imagesc(ball1); s1 = regionprops(ball1, {'centroid','Area'}); if isempty(s1) error('No ball found!'); else [~, id] = max([s1.Area]); hold on, plot(s1(id).Centroid(1),s1(id).Centroid(2),'wp','MarkerSize',10,'MarkerFaceColor','b'), hold off disp(['Center location is (',num2str(s1(id).Centroid(1),4),', ',num2str(s1(id).Centroid(2),4),')']); end %-------------------------------------------------------------------------- %-------------------------------------------------------------------------------------------------------% r1 = greenball2(:, :, 1); g1 = greenball2(:, :, 2); b1 = greenball2(:, :, 3); justGreen2 = g1 - r1/2 - b1/2; bw2 = justGreen2 > 50; % figure;imagesc(greenball2); % figure;imagesc(bw2); % colormap(gray); ball2 = bwareaopen(bw2, 30); %figure;imagesc(ball2); s2 = regionprops(ball2, {'centroid','area'}); if isempty(s2) error('No ball found!'); else [~, id] = max([s2.Area]); hold on, plot(s2(id).Centroid(1),s2(id).Centroid(2),'wp','MarkerSize',10,'MarkerFaceColor','r'), hold off disp(['Center location is (',num2str(s2(id).Centroid(1),4),', ',num2str(s2(id).Centroid(2),4),')']) end differ(i,1)=(s2(id).Centroid(1)-s1(id).Centroid(1)).^2; differ(i,2)=(s2(id).Centroid(2)-s1(id).Centroid(2)).^2; %disp(differ); % figure; % imshow(differ); % hline = imdistline(differ,s1(id).Centroid,s2(id).Centroid); % api = iptgetapi(hline); distance(i,:)=sqrt(differ(i,1)+differ(i,2)); disp(distance); velocity(i,:)=(distance(i,:)/framerate); disp('velocity='); disp(velocity); end end velocity1=mean(distance)/framerate; disp(velocity1);
2 Commenti
Image Analyst
il 4 Apr 2014
Is this code more updated than your previous (apparent duplicate) question: http://www.mathworks.com/matlabcentral/answers/124492-how-to-draw-bounding-box-to-a-object-in-a-video-after-finding-its-centroid-basing-on-its-color?
Image Analyst
il 5 Apr 2014
If not, I'll delete this one.
Risposte (0)
Categorie
Scopri di più su Video Formats and Interfaces in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!