Improve company productivity with a Business Account.Sign Up


Recognise a object in an image

Posted on 2006-07-12
Medium Priority
Last Modified: 2010-04-05
I need a script that recognises an object in an image.

Lets say I have a picture (a jpg or bmp file) of a room, and in the room is a red ball. The image hast the size of lets say 400px X 400px big. I need a good script that tells me the coordinates from the rectange in which the red ball is, so if the red ball is in the center of the picture the script should give me a rectangle like this: TRect(180, 180, 40, 40).

The best would be if I could "feed" the algorithm with a clean photo of the object and it would recognise it in the picture. It only needs to recognise clean objects like a ball or a box that has a bright color.

Important is that I only need the rectagle, nothing more. I hope to find here some good help.

Question by:KBunk
LVL 17

Expert Comment

ID: 17096100
is the object that you are searching for always the same size?

Author Comment

ID: 17097266
the object itself yes, but in the picture the object may be further away and thus smaller or nearer and bigger... the purpose of this is to make my hexabot (a spider robot with 6 legs) able to recognise a red ball and follow it. For this I just need an algorithm that solves me the above mentioned problem.

It is not important in which language.. best would be delphi, but any other language woul do it to. Does maybe someone know any open source projects or sdk that handle this?
LVL 17

Accepted Solution

TheRealLoki earned 672 total points
ID: 17105574
without googling, 1 method off the top of my head would be to get a "magic wand" routine, like many paint programs have, and perform the routine at various places in your image (eg. every "half the minimum width of the image you are trying to find"). then compare the "shape points" from the "magic wand" to the shape you are trying to find (allowing for size, so you will want either angles, or % change rather than just x,y)

another thought I had is you could do a mask on "red" so everything else is removed from teh image. it's then just a simple loop to find the "red" objects, and find their borders.
The problem with tracking a red ball is the light. you get light spots on it and the colour quickly fades making it hard to find. Make the ball matte, not shiny for a start.

I checked out some other EE questions on the subject, and the general theme seems to be
use as few colours as possible.
shape recognition is usually made of the following steps:
1) contour extraction (usually made by a convolution mask applied on the image)
2) Removal of isolated pixels (and small groups of pixels too)
3) Recognition of the borders (previously extracted and cleaned) you have to find coordinates of segments that best fit with the contour pixels

some c++ references here
and autotrace my have some possibilities

sorry I couldn't be of more help.
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 664 total points
ID: 17106922
Unless I am mistaken, yo have multiple images which you can compare with each other. So what I would do is first "subtract" the images from each other and see where the two are different. If two images are identical, nothing will have moved. But if something has moved, then the two pictures will be slightly different and basically, what you want to analyse are the differences, not the whole picture.
Once you know the locations of where these differences are, all you need to do is check out the shapes in those locations. If you find a red ball there, using the method described by TheRealLoki, then you'll have found your target.

But you will have to deal with other issues too here. First of all, it sounds the pictures are coming from a webcam or whatever. This means that you will have to keep in mind some slight variances in lights and shadows in the two pictures. And if your robot can turn it's head or walk around, you will also have to adjust your calculations to include the small amounts that the picture might have changed, meaning that the area that you're comparing will be a bit smaller than the whole picture. For example, your bot moves it's head slightly to the left. This means that your 400x400 pictures will be completely different if you just subtract them. You will have to find the area that picture 1 and picture 2 have in common and just subtract compare those two pictures. (And you'd also have to check the area that was added to the new picture in case the ball turned up in that area.

You're dealing here with a very complex situation which requires very good math skills and good knowledge of certain algorithms. Even the experts haven't found good solutions for this.
LVL 26

Assisted Solution

by:Eddie Shipman
Eddie Shipman earned 664 total points
ID: 17111600
If it always the same color...

You can use the BitmapToRegion code here:

Set the transparent color to the color you want to detect, then combine the region returned with a region
that encompasses the entire bitmap to get the region that contains the color. Then check the location of the
spider to the "ball" using PtInRgn

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
If you are looking for an automated tool which can generate reports for Outlook emails and other items from PST file, then you can go for Kernel PST Reporter tool. The reports which are created by this tool are helpful to analyze and understand PST …
To export Lotus Notes to Outlook PST or Exchange and Domino Server files to Exchange Server or PST files with ease, go for Kernel for Lotus Notes to Outlook conversion tool. Through the video, you can watch the conversion process. A common user with…

608 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question