[3D] Sky Touch 3D objects with Matlab

  1. close all
  2. clear all
  3. clc
  4. [x,y]=meshgrid(-2:0.1:2,-2:0.1:2);
  5. %surf(x,y,x.^2-y.^2)
  6. %view(x,20)
  7. % Create context and read xml file at first
  8. context = mxNiCreateContext('SamplesConfig.xml');
  9. %% Initialise FIGURE
  10. width = 640;
  11. height = 480;
  12. % depth image
  13. %figure(1), h1 = imagesc(zeros(height,width,'uint16'));
  14. %           set(gcf,'MenuBar','none'); set(gca,'Position',[0 0 1 1]);
  15. %colormap gray
  16. for k=1:1000
  17.     option.adjust_view_point = false;
  18.     % Acquire rgb and depth image
  19.     tic
  20.     [~, depth] = mxNiImage(context, option);
  21.     bw=depth>400 & depth<1100;
  22.     bww=(1100-depth).*uint16(bw);
  23.     bwsq=bww.^2; %verhoogt beeld
  24.     [YCoord, XCoord] = find(bwsq);
  25.     CentroidX = 500-mean(XCoord);
  26.     %CentroidY = 500-mean(YCoord);
  27.     CentroidY = mean(YCoord);
  28.     surf(x,y,x.^2-y.^2)
  29.     if isnan(CentroidX) == 0
  30.         view(CentroidX,CentroidY)
  31.     end
  32.     axis([-2 2 -2 2 -4 4]); axis equal;axis square
  33.     %plot(CentroidX,CentroidY,'ko','MarkerSize',15)
  34.     %axis([ 0 500 0 500])
  35.     % Update figure
  36.     %set(h1,'CData',bww);
  37.     drawnow;
  38.     %disp(['itr=' sprintf('%d',k) , ' : FPS=' sprintf('%f',1/toc)]);
  39.     disp(['fps=' sprintf('%f',1/toc)]);
  40. end
  41. % Delete the context object
  42. mxNiDeleteContext(context);
]]>

You may also like...

4 Responses

  1. Carsten Fries says:

    Hi Tim,
    when I try your code, the 3d model does not rotate. Can you help me with that, please?
    Best regards,
    Carsten

  2. Rami says:

    How can I run this code? where XML files and another files needed?

  3. ushie says:

    plz give me the code.i dont knw how to fix this