Live Image Processing and Tracking Image Features

9 views (last 30 days)
I am attempting to adopt the functionality of the 'Fluorescence-Tracker-App' for use with a Mako G-507B camera instead of a video. 'Fluorescence-Tracker-App' can be downloaded from mathworks but I am trying to change it so it works with the camera I have. My idea is to just take a snapshot, select a region of interest, find 4 features, and track those features in the following images that are captured. The code I have is shown below. The problem I am running in to is that the camera times out and is unreliable, it seems, in updating and/or even taking snapshots. So the program doesnt work every time. I would like to do this processing live, and as quickly as is reasonable for the processing to take place. Does anyone have any suggestions to make this program run more reliably?
clear;clc;close all;
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% Parameters for Camera
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
g= gigecam;
exposureTime=140;%[us]
g.Timeout=80;
g.ExposureAuto = 'Off';
g.ExposureMode = 'Timed';
g.ExposureTimeAbs = exposureTime;
g.PixelFormat='Mono12';
g.Height=484;
g.Width=484;
N=20; %Total Number of images to take.
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% Select and add regions of interest
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
region = [];
img=snapshot(g);
marked = mat2gray(img);
fig = figure(Name="Double-click to accept. " ...
+"Close figure when complete.", NumberTitle="off");
while isvalid(fig)
[~,roi] = imcrop(marked);
region = [region; roi]; %#ok<AGROW>
marked = insertShape(marked, Rectangle=roi, Color="white");
end
% If closed without a selection, set default regions [x y w h]
if isempty(region)
region = [400 20 40 60; 180 220 60 60; 220 40 60 40];
end
% Draw the selected region(s) of interest
marked = insertShape(mat2gray(img), Rectangle=region, Color="white");
marked = insertShape(marked, Rectangle=region+[0 double(g.Height) 0 0], Color="white");
figure; imshow(marked);
title("Selected Region(s) of Interest");
maxPts = 4;
points = []; rid = [];
gframe = im2gray(mat2gray(img));
for j = 1:size(region,1)
pts = detectMinEigenFeatures(gframe, ROI=region(j,:));
pts = selectStrongest(pts,maxPts);
points = [points; pts.Location];
rid = [rid; j*ones(size(pts,1),1)];
end
% Use region id (rid) to color code points
cmap = lines(max(rid));
cmap = cmap(rid,:);
% Display the detected points
marked = insertMarker(marked,points,"+", Color=255*cmap);
marked = insertMarker(marked,points+[0 double(g.Height)],"+", Color=255*cmap);
figure; imshow(marked)
title("Detected Features");
tracker = vision.PointTracker(MaxBidirectionalError=1);
initialize(tracker,points,mat2gray(img));
player = vision.VideoPlayer(Position=[60 60 460 610]);
k = 1;
while k<=10*N
k = k + 1;
% Get the next snapshot
frame = snapshot(g);
cframe = mat2gray(imcrop(frame,[0 0 double(g.Width) double(g.Height)]));
% Track the points, note some points may become lost/invalid
[points,val] = tracker(cframe);
if any(val)
% Store corresponding intensity values
idx = sub2ind([double(g.Height) double(g.Width)],round(points(val,2)),round(points(val,1)));
% Mark frames with tracked points
markerSize = 10; % Adjust the marker size as needed
lineWidth = 5; % Adjust the line width as needed
cframe = insertMarker(cframe, points(val,:), 'o', ...
'Color', [255, 0, 0], 'Size',markerSize);
end
% Display annotated video frame using the video player object
player((cframe))
end
% Clean up
release(player)
release(tracker)

Accepted Answer

Image Analyst
Image Analyst on 29 Aug 2023
Call tech support and ask for Andrew B in the image acquisition team. He helped me out with such an issue. There are other functions to use other than snapshot such as start and getdata
data = getdata(obj) returns data, which contains the number of frames specified in the FramesPerTrigger property of the video input object obj. obj must be a 1-by-1 video input object.

More Answers (0)

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!