Detection of red color RGB
17 ビュー (過去 30 日間)
古いコメントを表示
i want a solution for my problem snice i am doing object detection using RGB and i cant get the orientation of the object . here is the code , also i have a problem with different light intesity that camera can detect object when light is normal but if it get lets dark camera cant detect
vid=videoinput('winvideo',1,'YUY2_640x480');
%Set the frames&RGB
set(vid,'FramesPerTrigger',inf);
set(vid,'ReturnedColorspace','rgb')
%Set timer of screenshoting of images per millisecond
vid.FrameGrabInterval=0.5;
%Acquiring video
start(vid);
%Set number of Frames in video
while(vid.FramesAcquired<=10000)
%To store extracted frames
data=getsnapshot(vid);
%extracting the Red color from grayscale image
diff_im=imsubtract(data(:,:,1),rgb2gray(data));
%Filtering the noise
diff_im=medfilt2(diff_im,[3,3]);
%Converting grayscale image into binary image
diff_im=im2bw(diff_im,0.18);
%remove all pixels less than 300 pixel
diff_im=bwareaopen(diff_im,300);
%Draw rectangular boxes around the red object detected & label image
bw=bwlabel(diff_im,8);
stats=regionprops(bw,'BoundingBox','Centroid');
%Show image
imshow(data);
hold on
%create a loop for the regtangular box
for(object=1:length(stats))
%saving data of centroid and boundary in BB & BC
bb=stats(object).BoundingBox;
bc=stats(object).Centroid;
%Draw the rectangle with data BB & BC
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
%Plot the rectangle output
plot(bc(1),bc(2),'-m+')
%Output X&Y coordinates
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
end
hold off
end
stop(vid);
%Flush the memory
flushdata(vid);
clear all;
0 件のコメント
採用された回答
Image Analyst
2019 年 3 月 21 日
Use the Color Thresholder app (on the Apps tab of tool ribbon) to generate a function that will get a mask for the red blobs. Then you can get the orientation of the Old Spice package by using the Orientation property returned by regionprops().
As an example, see attached demo I just posted a few minutes ago for another poster.
See my Image Segmentation Tutorial: click here
3 件のコメント
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!