MATLAB Answers

How can I mark corners on a binary image?

3 views (last 30 days)
Francisco Mendoza
Francisco Mendoza on 15 Dec 2014
Commented: Francisco Mendoza on 15 Dec 2014
I have the nxt problem with my code, it's suppose to detect a hand... Here is the code:
if true
function varargout = detenciondemano(varargin)
% DETENCIONDEMANO MATLAB code for detenciondemano.fig
% DETENCIONDEMANO, by itself, creates a new DETENCIONDEMANO or raises the existing
% singleton*.
% H = DETENCIONDEMANO returns the handle to a new DETENCIONDEMANO or the handle to
% the existing singleton*.
% DETENCIONDEMANO('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DETENCIONDEMANO.M with the given input arguments.
% DETENCIONDEMANO('Property','Value',...) creates a new DETENCIONDEMANO or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before detenciondemano_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to detenciondemano_OpeningFcn via varargin.
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
% Edit the above text to modify the response to help detenciondemano
% Last Modified by GUIDE v2.5 12-Dec-2014 19:25:18
% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @detenciondemano_OpeningFcn, ... 'gui_OutputFcn', @detenciondemano_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT
% --- Executes just before detenciondemano is made visible. function detenciondemano_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to detenciondemano (see VARARGIN)
% Choose default command line output for detenciondemano handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes detenciondemano wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = detenciondemano_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in empezar. function empezar_Callback(hObject, eventdata, handles) % hObject handle to empezar (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
vid = videoinput('macvideo', 1, 'YCbCr422_1280x720'); % Captura una trama por trigger vid.FramesPerTrigger=1; % Salida de la Imagen RGB=color/GRAYSCALE=escala grises vid.ReturnedColorSpace = 'rgb'; % Se le indica a Matlab que la camara no inicie Automaticamente sino a % peticion del usuario triggerconfig(vid,'manual'); % Adquirimos la altura y anchura de la imagen vidRes=get(vid,'VideoResolution'); % Altura de la Imagen imWidth = vidRes(1); % Anchura de la Imagen imHeight = vidRes(2); nBands = get(vid, 'NumberOfBands'); % Crea una Variable q contenga la Imagen para mostrala en el AXIS(handles.axes1) hImage = image(zeros(imHeight, imWidth, nBands), 'parent', handles.axes1); % Empieza Webcam Preview preview(vid, hImage);
for i=1:100 I=getsnapshot(vid); I=imresize(I,0.5); r=I(:,:,1); b=I(:,:,3); g=I(:,:,2); hand=r-b; hand=hand>30; hand=bwareaopen(hand, 13000); loc = regionprops(hand , {'centroid' , 'ConvexArea' , 'Orientation'}); [L , Ne] = bwlabel(hand); CH = bwconvhull(hand);
if i>5
BW = edge(CH, 'sobel');
se = strel('disk', 2);
BW = imdilate(BW,se);
BW = imerode(BW,se);
BW = imfill(BW, 'holes');
B = bwboundaries(BW, 8, 'holes');
B = B{1};
objB = bsxfun(@minus, B, mean(B))
[theta, rho] = cart2pol(objB(:,2), objB(:,1));
%# find corners %#corners = find( diff(diff(rho)>0) < 0 ); %# find peaks [~,order] = sort(rho, 'descend'); corners = order(1:10);
%# plot boundary signature + corners %figure, plot(theta, rho, '.'), hold on %plot(theta(corners), rho(corners), 'ro'), hold off %xlim([-pi pi]), title('Boundary Signature'), xlabel('\theta'), ylabel('\rho')
%# plot image + corners imshow(BW), hold on plot(B(corners,2), B(corners,1), 's', 'MarkerSize',10, 'MarkerFaceColor','r') hold off end
stop(vid); close all clear all
Then, I want to mark every vertices from the convex hull image, but only show one... This is the output:
Where can i get and example for do this? I'm always searching and did not find anything... It can be done with OpenCV, but I really want to do it with MatLab..
And, another topic, I was reading about K-curvature but i didn't find any for matlab.
I appreciate very much your answers.

Answers (1)

Image Analyst
Image Analyst on 15 Dec 2014
Look at how the Computer Vision System Toolbox can track the man's head as it moves around:
  1 Comment
Francisco Mendoza
Francisco Mendoza on 15 Dec 2014
Yeah, i have already done, indeed, I have the code for tracking man's head at runtime using SURFF; the only problem is that is too slowly..
I want to use K-curvature and convex hull:(

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by