johnny2x2

1D depth map script

Jul 16th, 2016
1,212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.49 KB | None | 0 0
  1. clear all
  2. close all
  3. vidobj = videoinput('winvideo', 1, 'RGB24_960x720'); %Setup Camera
  4. aMega = arduino('COM9');
  5. writeDigitalPin(aMega,'D22',1);
  6. %% Model Variables
  7. f = 919; % Focal length
  8. cx = 495; % Optical center x
  9. cy = 335; % Optical center y
  10. b0 = 140; % Laser distance from camera
  11. C0 =65.9534; % Angle of laser
  12. Y_mltply = 0.234;%Y axis scaling factor
  13. pic1 = getsnapshot(vidobj);
  14. imgSize = size(pic1);
  15. %% Variables for the code
  16. LaserPts = []; % Camera Coordinates of Laser line
  17. CamCoordPts = []; % List of X; Y; Z; points
  18. BW = NewFilter(vidobj,imgSize,aMega,'D22');%Filter laser line
  19. imshow(BW) %display the image
  20. %% Convert Single Line to camera coordinates
  21. counter = 1;
  22. for i = 1:imgSize(1)
  23.     for i1 = 1:imgSize(2)
  24.         testpt = BW(i,i1);
  25.         if testpt == 1 % if point on Y
  26.         LaserPts(1,counter) = i1-cx; % add to LaserPts list in Camera Coordinates
  27.         LaserPts(2,counter) = cy-i;
  28.         counter = counter+1;
  29.         end
  30.     end
  31. end
  32. %% Determine World Coordinates for each Y
  33. sizeDisx = size(LaserPts);
  34. for i = 1:sizeDisx(2)
  35.     delta_px_x0 = LaserPts(1,i);
  36.     A0 = 90+atand(delta_px_x0/f);
  37.     B0 = 180 - (A0+C0);
  38.     a0 = (sind(A0)*b0)/sind(B0);
  39.     h1 = a0*cosd(atand(delta_px_x0/f));
  40.     CamCoordPts(3,i)=h1;
  41.     CamCoordPts(2,i) = Y_mltply*LaserPts(2,i);
  42. end
  43. CamCoordPts(1,:) = 0;
  44. %% Set X = 0
  45. transCW = transpose(CamCoordPts); % Transpose the list
  46. pointCloud = pointCloud(transCW);
  47. figure;pcshow(pcdenoise(pointCloud)) % View the pointcloud
Advertisement
Add Comment
Please, Sign In to add comment