The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Identifying object in image
Replies: 3   Last Post: Apr 8, 2012 11:12 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Peter Russo

Posts: 50
Registered: 6/3/09
Re: Identifying object in image
Posted: Apr 8, 2012 11:12 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

So ive been playing with the code following your suggestion, and I have it working ok. I can get it such that it will constantly play images, and will mark the center of my circle. Its a little slow (around 5.3 FPS), which isn't terrible for my purposes, but I will eventually be adding more computation per frame, so it would be nice to speed it up. I clocked it, and the majority of the time (almost 80%) is spent on the "regionprops", even though I limited it to only 3 properties. So my first question is, is there a quicker way to find objects in an image than regionprops?

My second issue is that the marker occasional jumps to other random points in the image from my circle. I was thinking of trying to limit the code so that it only searches for the circle in the same small region that it was in in the previous frame, and filter out circles whos area is widely different from the previous frame. Would this be the easiest way to do it? The only issue then would be if it picks the wrong point from the start, but hopefully that wont happen. The code I currently have is shown below. I can upload a sample frame too, but im not sure how to do it. Any help is appreciated. Thanks


%This program will find and track a ball from the webcam

clear all
close all

CameraName = 'macvideo'; %Name of the camera
info = imaqhwinfo(CameraName,1);
CameraFormat = info.SupportedFormats;

vid=videoinput(CameraName,1,char(CameraFormat)); %Create a video input object

%Set video input object properties
vid.TriggerRepeat = 0;
vid.FrameGrabInterval = 5;
vid.FramesPerTrigger = 1;
vid.ReturnedColorSpace = 'rgb';
vid.FrameGrabInterval = 1;
vid.TriggerRepeat = 0;

vid_src = getselectedsource(vid); %Create video source object

figure; %Create a new figure window
start(vid) %Start acquiring frames

for i=1:100
originalimage=getsnapshot(vid); %Read in image from buffer

grayimage = rgb2gray(originalimage); %convert image to gray scale

% [pixelCount grayLevels] = imhist(grayimage); %Find pixel histogram numbers
% bar(pixelCount); %Plot histogram

thresholdvalue = 150; %Define threshold value
binaryimage = grayimage > thresholdvalue; %Convert grayscale image to a binary image

info = regionprops(binaryimage,'Area','Perimeter','Centroid');

clear area perimeter centroid ratio %Clear needed variables

%Move regions from info to variables, and calc ratio
closest = 100; %Closest finds the region with a radius (from area and perimeter) closest to 1. Start with a large value
for i=1:length(info)
if(info(i).Area >40 && info(i).Perimeter > 5) %eliminate regions with extremely small areas and perimeters
ratio = abs(info(i).Perimeter^2/(4*pi*info(i).Area)) - 1;
if(ratio < closest)
closest = ratio;
coords = info(i).Centroid;

imshow(originalimage(:,:,:,1)); %Display image
hold on;
hold off;



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.