Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Improvement for laser tracking code outside dark room

Status
Not open for further replies.

sakurarandom

Junior Member level 3
Joined
Mar 26, 2011
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,500
I had try on laser tracking on my green laser with coding as shown below. It works if the laser dot in a dark room. Is there any suggestion on how to improve it? I would like to improve it to scan only for coordinate x from 100 to 260 while coordinate y from 300 to 360. Thanks.


close all%Ckise all figure windows except those created by imtool
%closepreview(vid);
%delete(vid);
clear; %Delete all variables
%close(gcf);
clc %Clear command window
clear
imtool close all %Make sure the workspsace panel in showing

vid=videoinput('winvideo',1,'RGB24_640X480');
vid.FramesPerTrigger = 1;
start(vid);
wait(vid);
preview(vid);

xResolution = 640;
yResolution = 480;

intensityThreshold = 250;

tic
while toc < 15

theSnapshot = getsnapshot(vid);
figure(1);
imshow(theSnapshot);

% reset the corner extremes
leftMost = xResolution;
rightMost = 0;
topMost = yResolution;
bottomMost = 0;

[x y] = size (theSnapshot);
for i = 1: xResolution
for j = 1:yResolution
if theSnapshot(i,j,2) > intensityThreshold
% bright green pixel found
if i < topMost
topMost = i;
end
if i > bottomMost
bottomMost = i;
end

if j < leftMost
leftMost = j;
end
if j > rightMost
rightMost = j;
end

end
end
end

% calculate the midpoints of the area
if leftMost ~= xResolution && rightMost ~= 0
% both leftMost and RightMost have been updated

laserFound = true;
laserX = (leftMost + rightMost)/2
laserY = (topMost + bottomMost)/2

else
% unable to find laser
laserFound = false;
end

% plot laser area
% for ease of viewing, y coordinates are viewed flipped around into
% the cartesian system instead of image coordinate system
if laserFound == true
figure(1);
impixelinfo
hold on;
plot((0: xResolution),laserY*ones(1, xResolution+1),'r');
plot(laserX*ones(1, yResolution+1),(0:yResolution),'r');
hold off;
axis([0 xResolution 0 yResolution]);
drawnow;
end

end

% Stop the acquisition, remove the object from memory,
% and clear the variable.
stop(vid)
delete(vid)
clear vid
 

try to improve sensitivity of detector for peak and slow decay behaviour so if scanning too fast, it will reduce chance of being missed.
Also use green color filter to block out stray wavelengths of light say from pulsing FL tubes.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top