I want to turn this code into led light instead of red ones

조회 수: 1 (최근 30일)
Batuhan Istanbullu
Batuhan Istanbullu 2022년 11월 27일
댓글: Batuhan Istanbullu 2022년 11월 28일
Hi, I want to turn this code into led light instead of red ones. How may I do that; which part should I change?
Here is my code;
data =imread('IMG_4236.JPG');
% Now to track red objects in real time
% we have to subtract the red component
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);
% Remove all those pixels less than 300px
diff_im = bwareaopen(diff_im,300);
% Label all the connected components in the image.
bw = bwlabel(diff_im, 8);
% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
%This is a loop to bound the red objects in a rectangular box.
for object = 1:length(stats)
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
and here is the image

답변 (2개)

Image Analyst
Image Analyst 2022년 11월 27일
I don't know what this means: "turn this code into led light instead of red ones".
You can't turn code into a light. The light you have in your scene is white. If you want a red LED instead of a white one, then put a red LED into your circuit. It has nothing to do with code. It has to do with electrical components and perhaps a soldering iron or a breadboard or other components to build circuits with.
The bright light in the image is not red. Plus your algorithm is just overly simplistic (even if the light were red) and basically no good. If you want to track a colored object in an image, see my attached demo where I track a green Sharpie marker in a video.
  댓글 수: 15
Batuhan Istanbullu
Batuhan Istanbullu 2022년 11월 28일
and when I do want to run it I encounter with this problem
Batuhan Istanbullu
Batuhan Istanbullu 2022년 11월 28일
I do not know where I'm doing wrong when I'm trying to implement your code to my values and my video

댓글을 달려면 로그인하십시오.


Matt J
Matt J 2022년 11월 27일
편집: Matt J 2022년 11월 27일
Is this what you want?
IMG=load('Image').A;
c=regionprops(all(IMG>250,3),'Centroid').Centroid; %LED centroid/position
imshow(IMG); hold on
plot(c(1),c(2),'rx'); hold off
  댓글 수: 6
Matt J
Matt J 2022년 11월 27일
You're welcome, but please Accept-click the answer as well as answers to other questions you've posted which are now resolved.
Batuhan Istanbullu
Batuhan Istanbullu 2022년 11월 27일
Yes, I will do that immediately.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by