Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Position of moving element in picture box

Posted on 1999-07-15
17
Medium Priority
?
284 Views
Last Modified: 2010-04-02
I've a TV-Card and i get the video in a box like a picture box and i want to find out the x-y position of moving elements (first perhaps only of a black circle) or another not difficult shape. But it should work very fast and i need something like a dll, because I'm a VB60-Programmer and there such Progs are not makable.
0
Comment
Question by:martinschuster1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 2
  • +1
17 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1200350
This is done by taking bitmaps pf two sequential frames and "subtracting" the images.  You do this by subtracting the pixel values on one image from the cooresponding pixel values of the other image.  This vields a 3rd image.  The image will be black (pixels will be 0) where the are no changes (no movement), the image will be non-black (pixels will be non-o) where there were changes (movement).  Then offten the next step is to convert this image to monochrome (Black and white), where the black pixels remain black and the non-black pixels become white pixels.

The first thing you have to do is to get the images from the TV-Card.  Can you do so?
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1200351
Getting the images from the card and 'substracting' them may be 'easy'. Determining if its the desired shape, or (just) tracking a specific shape is rather difficult.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200352
difficult?  just short of impossible.  However, it may not be necessary to "convert" that information into geometic shapes.  It depends on how it is being used.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1200353
Instead of subtracting the pixels and then converting them to black and white, you can do this in one step by using BitBlt(..., SRCINVERT); which is an xor operation.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200354
Often you will want the resulting image to be a monchrome (i bit per pixel) image even though you start with color images.  It may make simpler to use in analysis.  You also might want finer control over the conversion from to B&W.   You may want to allow changes below a certain "threshold" to be ignored, i.e. to convert to black.  This allows for small changes in lighting and the response of photoarray.  (Usually, to do this you square each of the color indices of the resulting pixel and add those three values.  Then compare the this value with the threshold value.  if it is below the threshold, you make the resulting pixel black, otherwise it is white.
0
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1200355
Instead of subtracting the pixels and then converting them to black and white, you can do this in one step by using BitBlt(..., SRCINVERT); which is an xor operation.
0
 
LVL 1

Expert Comment

by:MartinSchuster
ID: 1200356
I'm able to receive the images from the Video card and i don't need not the color information only in grey-scale. I have also read something about BitBlt but can anybody give me some code or somthing how to find out what i want?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200357
What exactly do you want?  In what sort of form?  I can showl you how to mathematically manupilate the image to yield images that "show" the differences.  Is that good enough?
0
 
LVL 1

Expert Comment

by:MartinSchuster
ID: 1200358
I've a avi-clip (sample), and in that clip is a filled black circle on a red backgroud.
The circle is moving and i want the x-y Position of the circle.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200359
Would this algorithm work for you?  Subtract the two images so that you get a white ball on a black background.  Then find the highest and lowest white pixels and average them to find the height of the ball's center   Find the left-most and right-most pixel and average them to find the position of the ball's center.

We used that algorithm to study the trajectory of a projectile.   For that approach you want an initial frame that has no ball in it and then you want to subtract thatfrome from the ones that show the ball moving.  Does that work for you?
0
 
LVL 1

Expert Comment

by:MartinSchuster
ID: 1200360
Yes I think so, can you send me a code of that? Please.
MartinSchuster@yahoo.com
0
 
LVL 22

Accepted Solution

by:
nietod earned 1200 total points
ID: 1200361
The following procedure takes two images in the form of 32 bit RGB values.  The first parameter describes the size of the images, but assumes the format is 32 bit RGB.  If you don't have the images in this format, let me know.  You'll probably want to convert to this format as it is likely to be the fastest (The background gets converted only once, then each successive image gets converted and fed to the procedure.)

POINT                                            // Coordinates of center of circle found in      //
                                                 // image.  Will return (-1,-1) if the circle was //
                                                 // not found.                                    //
Sub(const BITMAPINFOHEADER &ImgInf,              // Describes format of the images to be          //
                                                 // processed.                                    //
    const COLORREF         *ImgDatPtr,           // -> pixel data for image with the circle.      //
                                                 // This image data must be in uncompressed 32    //
                                                 // bit color and in the same dimensions as       //
                                                 // specified by ImgInf.                          //
    const COLORREF         *ImgBckPtr,           // -> pixel data for image without the circle.   //
                                                 // This image data must be in uncompressed 32    //
                                                 // bit color and in the same dimensions as       //
                                                 // specified by ImgInf.                          //
    int                     Epsilon)             // Threshold factor.  Controls the level at      //
                                                 // which a change in a pixel indicates the       //
                                                 // presence of the circle. Specify 0 if any      //
                                                 // change is to signify the presence of the      //
                                                 // disk.  The maximum value is 3*256 which will  //
                                                 // prevent any change from signifying the        //
                                                 // presence of the disk.                         //
{
   const int EpsSqr = Epsilon*Epsilon;           // Epsilon squared.                              //
   int       MaxX   = 0;                         // Maximum X value of changed pixel.             //
   int       MaxY   = 0;                         // Maximum Y value of changed pixel.             //
   int       MinX   = ImgInf.biWidth;            // Minimum X value of changed pixel.             //
   int       MinY   = ImgInf.biHeight;           // Minimum Y value of changed pixel.             //
   POINT     RetVal = {-1,-1};                   // Value to be returned.                         //

   for (int Y = 0; Y < ImgInf.biHeight; ++Y)
   {
      for (int X = 0; X < ImgInf.biHeight; ++X)
      {
         COLORREF ImgRGB = *ImgDatPtr++;         // Image's current pixel's RGB data.             //
         COLORREF BckRGB = *ImgBckPtr++;         // Background's current pixel's RGB data.        //

         // These values could be used to create a new image, but in this case it is faster to    //
         // just to process them as is and not save them to a new image.                          //
         const int RDelta = GetRValue(ImgRGB) - GetRValue(BckRGB); // Change in red value.        //
         const int GDelta = GetGValue(ImgRGB) - GetGValue(BckRGB); // Change in green value.      //
         const int BDelta = GetBValue(ImgRGB) - GetBValue(BckRGB); // Change in blue value.       //
         const int DelSqr = RDelta*RDelta + GDelta*GDelta + BDelta*BDelta; // Squared change in pixel. //

         if (DelSqr > EpsSqr)                    // If pixel has changed, then                    //
         {
            MaxX = max(MaxX,X);                  // Get new maximum X value, if needed.           //
            MaxY = max(MaxY,Y);                  // Get new minimum Y value, if needed.           //
            MinX = min(MaxX,X);                  // Get new maximum X value, if needed.           //
            MinY = min(MaxY,Y);                  // Get new minimum Y value, if needed.           //
         }
      }
   }
   if (MinX < MaxX && MinY < MaxY)               // If the circle was found                       //
   {
      RetVal.x = (MinX + MaxX) / 2;              // Get X coordinate of center.                   //
      RetVal.y = (MinY + MaxY) / 2;              // Get Y coordinate of center.                   //
   }
   return RetVal;                                // Return the point found.                       //
}

0
 
LVL 1

Expert Comment

by:MartinSchuster
ID: 1200362
I now its not right to ask that but do you have an idea how it works in VB? Because its not very easy for me to read your source!
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200363
This is the C++ topic area????   I don't know VB.  Do you know C/C++?

If needed, I can explain the algorithm, its pretty easy.  But that is largely what I already did.
0
 
LVL 1

Expert Comment

by:MartinSchuster
ID: 1200364
I now its not right to ask that but do you have an idea how it works in VB? Because its not very easy for me to read your source!
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 1200365
Maybe you can point out some lines you cannot interpretate.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1200366
I'm moving in a few days and will probably be on EE for only 2 more days.  So if you need help from me, ask soon.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

715 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