[img A g]= depth_examplea(); A1=mean(mean(img,3)); G=cast(g,'single'); size(g) level=graythresh(g); BW2 = edge(g,'Prewitt'); [L,Centers] = imsegkmeans(g,4); B = labeloverlay(g,L); imshow(B); title('Labeled Image'); BW2 = bwareaopen(BW2, 20); % Remove blobs smaller than 40. Ibw1 = imfill(BW2,'holes'); binaryImage = bwareafilt(Ibw1, 1); % Extract largest blob only. info = regionprops(binaryImage,'Boundingbox') imshow(binaryImage) hold on for k = 1 : length(info) BB = info(k).BoundingBox; rectangle('Position', [BB(1),BB(2),BB(3),BB(4)],'EdgeColor','r','LineWidth',2) ; X1(:,k)=[BB(1)]; X2(:,k)=[BB(2)]; X3(:,k)=[BB(3)+10]; X4(:,k)=[BB(4)+10]; X=transpose([X1;X2;X3;X4]); end IExpandedBBoxes = insertShape(img,'Rectangle',X,'LineWidth',3); overlapRatio = bboxOverlapRatio(X, X); n = size(overlapRatio,1); overlapRatio(1:n+1:n^2) = 0; g1 = graph(overlapRatio); componentIndices = conncomp(g1); % Merge the boxes based on the minimum and maximum dimensions. xmin = accumarray(componentIndices', X1, [], @min); ymin = accumarray(componentIndices', X2, [], @min); xmax = accumarray(componentIndices', X3, [], @max); ymax = accumarray(componentIndices', X4, [], @max); textBBoxes = [xmin ymin xmax ymax]; xcor=[ textBBoxes(1) textBBoxes(3) textBBoxes(3) textBBoxes(1) textBBoxes(1)]; ycor=[ textBBoxes(2) textBBoxes(2) textBBoxes(4) textBBoxes(4) textBBoxes(2)]; ITextRegion = insertShape(img, 'Rectangle', textBBoxes,'LineWidth',3); s= [regionprops(ITextRegion,'centroid')]; s1=reshape(cell2mat(struct2cell(s)),3,[])'; s1x=s1(:,1); s1y=s1(:,2); xcenter=round(xmin +(xmax/2)) ycenter=round(ymin+(ymax/2)) str = strcat('') imshow(ITextRegion) figure %A2=mean(A1(1:424)); %A3=mean(A1(425:848)); %A4=[A2 A3]; function [img A g]=depth_examplea(); % Make Pipeline object to manage streaming pipe = realsense.pipeline(); % Make Colorizer object to prettify depth output colorizer = realsense.colorizer(); % Start streaming on an arbitrary camera with default settings profile = pipe.start(); % Get streaming device's name dev = profile.get_device(); name = dev.get_info(realsense.camera_info.name); % Get frames. We discard the first couple to allow % the camera time to settle for i = 1:5 fs = pipe.wait_for_frames(); end % Stop streaming pipe.stop(); A=[]; % Select depth frame depth = fs.get_depth_frame(); % Colorize depth frame color = colorizer.colorize(depth); % Get actual data and convert into a format imshow can use % (Color data arrives as [R, G, B, R, G, B, ...] vector) data = color.get_data(); img = permute(reshape(data',[3,color.get_width(),color.get_height()]),[3 2 1]); img(:,1:100,:)=[]; img(:,840:end,:)=[]; img(460:480,:,:)=[]; % Display image imshow(img); title(sprintf("Colorized depth frame from %s", name)); A(:,:,:)=img(:,:,:); g=rgb2gray(img); end