Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
Batuhan Istanbullu
Batuhan Istanbullu am 27 Nov. 2022
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

Antworten (2)

Image Analyst
Image Analyst am 27 Nov. 2022
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 Kommentare
Batuhan Istanbullu
Batuhan Istanbullu am 28 Nov. 2022
and when I do want to run it I encounter with this problem
Batuhan Istanbullu
Batuhan Istanbullu am 28 Nov. 2022
I do not know where I'm doing wrong when I'm trying to implement your code to my values and my video

Melden Sie sich an, um zu kommentieren.


Matt J
Matt J am 27 Nov. 2022
Bearbeitet: Matt J am 27 Nov. 2022
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 Kommentare
Matt J
Matt J am 27 Nov. 2022
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 am 27 Nov. 2022
Yes, I will do that immediately.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by