Overlay motion vectors

Hi all! I solve the problem in which I want to find all the motion vector image, as in the picture. I am using the Overlay motion vectors function. But I do not know what the rate should be applied to the inputs Velocity Component 1 and Velocity Component 2. Help me, maybe I need to use the function Optical flow. But I also could not use it.
Attachments:
Overlay motion vectors.vi ‏1328 KB
22da17293663c2056496223d23a577b2.png ‏151 KB

Hi! Thank you! Success came. I used the feature, about which you say and even replaced the function of capturing video.
And to the same set of the same types of values of the image as a example of the Optical Flow example.vi. But I do not stand on the spot and wanted to
ask if there is one more thing.
How to use this algorithm to a few areas of interest(ROI)? To one ROI algorithm applicable well, and here's to more does not work.
Attachments:
Снимок.JPG ‏84 KB
Снимок1.JPG ‏56 KB
Снимок2.JPG ‏47 KB

Similar Messages

  • Extract motion vectors in MPEG-1 using JMF?

    Is there a way to extract motion vectors in MPEG-1 using JMF?
    Thanks in advance.

    That's a bizarre question... you're going to have to explain yourself better.
    A "motion vector"... what's that ?
    I'm guessing that you automatically want to compute the directions of one or more arbitrary objects in a video clip ????
    Are you expecting it to be 2D or 3D ?
    Any video clip, or a pre-defined scene like a table top experiment ?
    regards,
    Owen

  • Motion Vectors in AfterEffects

    Hi,
    The plugin i am developing needs Motion vectors. Looking at the SDK documentation the only  reference I have found in the sdk docs for motion vectors are in relation to the PF_CHANNELSUITE1, PF_GetLayerChannelTypedRefAndDesc. Which I read to only be availiable if they were in the underlying "file type", not quite sure what that means but doesn't sound like something I can depend on. Does after effects provide access to motion vectors for the input layer of effects?
    Thanks,
    Cian.

    Thank you for your response. I am not really interested in identifing objects or surfaces in frame.
    I am refereing to  http://en.wikipedia.org/wiki/Motion_vector that would descibe a pixels or block of pixels movement from one frame to another. These might be used for creating motion compensated frames (http://en.wikipedia.org/wiki/Motion_compensation).  
    So I am hearing this is a no?
    Thanks,
    Cian.

  • What Program Should I use to create motion vector intro?

    Hello,
    I am creating an intro to a series I am making for a client. I will be animating vector images that I have created in Illustrator by saving them as ".ai" files. In the past I have created a similar project using Premiere Pro CS6 using ".png" files in hopes of saving time and processing power.(However, the final product's quality was not where it should have been.) Would it be more beneficial to create this project in After Effects CS6? What are the benefits of using vector images in After Effects rather than Premiere? Are they any benefits? Also if you have any experience creating animation in these programs I would love to hear any advice seeing that I am new to this type of work.
    Thanks,
    Alex

    What is the final destination of your animation, are you producing this to go on a DVD, or a website. After Effects is superior to Premiere in animation capabilities of vector objects (which really turn into bitmpaped objects for the final rendering no matter what program you use) , but Premiere is quicker for splicing videos together and putting transitions in between them.
    If the final quality is not where it should have been your settings were not correct. My advice is to  use an experienced professional to do this job for you, until you learn more about quality control for animation.

  • B-frames, 4 motion vectors, I-frames, trellis quantization, quarter pixel??

    i'm using the program ffmpegx and it has all these options that I don't know anything about. can anyone tell me what these different options do and their advantages/disadvantages?

    i dont know casue im not a video wiz. but have you tried these porgrams for converting video on a mac. I use all 3 depending on the type of video.
    quicktime pro 7
    handbrake
    http://diveintomark.org/howto/ipod-dvd-ripping-guide/
    or pspware
    http://www.versiontracker.com/dyn/moreinfo/macosx/26153
    did you see this
    http://homepage.mac.com/major4/ipod.html
    give those a try to. im sure 1 or all will prove easier.
    GFF

  • IMAQ optical FLOW (LKP)

    Hi
    i use the function IMAQ optical FLOW (LKP) but the only way to see the output of this funcion (motion of objectes) es call IMAQ Overlay Motion Vector to paint the result as a overlay on the image i need to used these data on my calculation but i can´t use it first there is no output from motion funcions , seconde i dont i ahve a funciones that convert the overlay image as a data (points ,lines , rectangle, arc,...etc) i can save the image with overlaydata and readit but i cannt use it.
    1- i need output from the motion funciones
    2- funciones that conevrt the overlay image to data as point , lines, rectangles... etc.

    You are using LKP right? as far asI understood, the data was given in points, so there is an output, the distance array and the points out.

  • For all of you who are having Motion Menu render problems - try this

    Just humour me for a minute.
    I have another Sonic application, and a known bug in the Motion Menu rendering applies to 29.97DF projects only.
    IE, NTSC.
    Often the video in a motion menu will fail to mux.
    There are workarounds though.
    1 - Make sure your GOP structure is 15 at most
    2 - Make certain the frame length of your video file is divisible by the GOP structure. IE, it must be a multiple of 15 frames.
    3 - if these both fail, reduce the bitrate of the video 500kbps at a time until it muxes. Most will work at 7,000, some need to be 6,000 and there are even times when you need to go as low as 4000.
    Try it - Encore uses a Sonic Authorcore, so it's worth a look.

    >Are you saying that NTSC 29.97 divided by 15 is okay?
    Not really.
    What I am saying is that your movie frame length should be divisible by the GOP structure with a GOP of 15.
    With NTSC video, you can have GOP lengths
    i up to
    18, but it is not mandatory to go to 18 - 15 is a perfectly acceptable figure. You could use a GOP of 12 if you really wanted to. What this means is typically the number of frames between I-Frames.
    MPEG-2 encoding (AKA "Moving Pictures by Educated Guesswork") P & B frames work something like this:
    i P-frames provide more compression than I-frames because they take advantage of the data in the previous I-frame or P-frame. I-frames and P-frames are called reference frames. To generate a P-frame, the previous reference frame is reconstructed, just as it would be in a TV receiver or DVD player. The frame being compressed is divided into 16 pixel by 16 pixel macroblocks. Then, for each of those macroblocks, the reconstructed reference frame is searched to find that 16 by 16 macroblock that best matches the macroblock being compressed. The offset is encoded as a "motion vector." Frequently, the offset is zero. But, if something in the picture is moving, the offset might be something like 23 pixels to the right and 4 pixels up. The match between the two macroblocks will often not be perfect. To correct for this, the encoder computes the strings of coefficient values as described above for both macroblocks and, then, subtracts one from the other. This "residual" is appended to the motion vector and the result sent to the receiver or stored on the DVD for each macroblock being compressed. Sometimes no suitable match is found. Then, the macroblock is treated like an I-frame macroblock. The processing of B-frames is similar to that of P-frames except that B-frames use the picture in the following reference frame as well as the picture in the preceding reference frame. As a result, B-frames usually provide more compression than P-frames. B-frames are never reference frames.
    In short, the I-Frame is the full description reference frame. A P frame is also a reference frame but describes the difference between the last I-Frame & itself. A good analogy is when you are on the telephone & describing what you see to a friend. The initial background description (The street, the sky, what you can see etc) would be an I-Frame. Then you describe a person walking down the street - that would be your P-Frames, as you are only describing the i changes
    in the scene.
    The bitrate can also affect things - I mentioned this too, and if a motion menu will not mux, first make sure that the film length is divisible by the GOP, and that the GOP is 15.
    If it
    i still
    won't mux, drop the bitrate by factors of 500 until it will.

  • How to minimise motion artefacts in the time warp effect?

    Iv'e got a scene in disco where the subjects move quite quickly. How can I minimise the motion artefacts? What are the best settings? It looks sometimes quite 'digital' as if filtered with a median filter and sometimes there are ripple-like structures on the faces as if processed with wavelets.

    I've experimented for a while now and setting the error threshold to 10 (from 1) and the motion detail to 5 makes it look pretty good. The error threshold essentially decides when to switch to frame blending instead of motion estimation. With a motion detail of 5 the motion vectors are quite coarse and the hopping looks natural. Hope that saves somebody else's time!

  • Slow Motion Problems With Twixtor Pro in AE CS5.5

    Hello forum! I recorded some footage at 1080p and at 60 fps. My shutter speed was 1/1000 and the ISO was 3200. After importing my footage and applying twixtor pro to a solid and setting the color source to my footage, i get a lot of ghosting effects. Some other things i did with Twixtor: Changed speed % to 20, Cahnged Frame Interp to Motion Weighted Blend, Changed, Input Frame Rate to 29.97, and Finally Changed Warping to Inverse w/ smart blend. Below is my video. If the emedded video below doesn't work (because I'm new to the forums), then heres the link: http://www.youtube.com/watch?v=3qGmW7or3gw

    Peregrinecommando99 wrote:
    I'm a bit confused... How would a 1/2 shutter speed be better than 1/1000? I thought 1/1000 was faster?
    Maybe this will help. If you were going for a target slow mo of 1/2 speed and your playback was going to be at 30 fps then you'd shoot at 60 fps. If you had a film camera with a normal shutter shooting at 60 fps wold give you and exposure of about 1/100 of a second. That means that if you have a video camera that will shoot at 60 P, or even 60I that your shutter speed should not be any faster than 1/100 of a second. Slowing down 60P or 60i footage is easy, It only gets hard when you want to slow something down to 1/4 or even 1/8 normal speed.
    Let's take 1/8 speed. IOW one second of real time takes eight seconds of playback time.
    If your project was set to 24 fps that means your target filming frame rate would be 8 X 24 or 192 fps. That means your shutter speed would be somewhere close to 1/400 of a second or half the duration of the frame rate. So I guess I should have said frame rate times 2.
    Setting the shutter to 1/1000 will give you an unnatural look to the slow mo because the edges will be too sharp. There are some occasions when you want that crystal sharp image in slow mo, but you have to be able to film the original scene at a high frame rate. Images with very sharp fast moving edges give Twixtor a very hard time. The edges end up creating weird ghosting that can’t be interpolated away. It’s just too much information for the motion vectors to successfully recreate. 1/8 speed is about my limit for Twixtor. If the camera was capable of 60i or 60p that that means doesn't mean I could slow down that original footage to 1/16 speed. It means that at 1/8 speed I'd have twice as much original information to work with and would therefore get a better result. It also means that I'd still want a shutter speed that was no faster than 1/400 of a second.
    Did you follow that? First rule of slow mo: Film at as high a frame rate as you can with your camera. Second rule: Try and emulate the shutter speed of a film camera that is over-cranked. Third rule of slow mo: Don't try and slow down too much. The amount of slowdown you can successfully achieve depends entirely on the movement in the frame. Unfortunately, the faster the motion, the harder it is to slow it down using software interpolation.
    I spent several months working with re:vision fx on deinterlacing and speed changes in interlaced footage. This advice comes from several hundred experiments on several types of footage and from 40+ years behind the viewfinder of film cameras. I hope this helps.

  • How to best achieve slow motion and fast motion

    Hi - I am new to the forum and a basic user of Premiere Pro CS5. I am working on a project shot at 24 fps, and would like to do slow and fast motion.
    From what i understand there are 2-3 different ways to do this in Premiere - choosing speed/duration of the clip from timeline, or choosing time remapping form effects panel ot using rate stretch tool. Wondering how do these compare and which is better - any pointers for this will be great help. Also is slow motion and fast motion better done in After Effects than Premiere. Or any recommended plugins that would work on cs5 and cs5.5. Thanks.

    The main difference between using time-remapping and just using time-stretching is that time-remapping allows you to change the speed quite flexibly at different times in the same clip, whereas stretching just changes the rate for the whole clip.
    See this page:
    "Change speed and duration for one or more clips"
    > Also is slow motion and fast motion better done in After Effects than Premiere.
    After Effects has far more control, especially with regard to how new image information is created between the original frames when you change speed and require frame interpolation (frame blending). Pixel Motion and Timewarp use a very advanced motion vector method (based on the Foundry's Kronos software) for doing this.
    See "Time-stretching and time-remapping".

  • Slow Motion Software

    I do a lot of wildlife filming in Africa. Can't afford a camera which will give me the slow motion option. Looked at the TWIXTOR software from www.revisionfx.com, who claim compatibility with PPro CS5. Has anyone any other suggestion of other software which works on a similar principle (creating intermediate frames) and produces good quality slow motion for HD?

    Harm Millaard wrote:
    Twixtor is the first one to think of. I know there are a few more, but can't remember their names. I would not look any further and just choose Twixtor. Be prepared for long rendering times however.
    Yes, Twixtor appears to be the gold standard for this in the Ae community.  I saw a short film by a guy who was slowing down some footage to really small percentages, like 1%, and the outcome was pretty amazing, almost as if it had been shot with a high speed camera.
    The long render times are because Twixtor analyzes the clip before slowing it, and calculates motion vectors, and creates tween frames and blur in accordance with the motion contained in the video.

  • Is Motion 5 worth buying if...

    Hello
    Is Motion 5 worth buying if you do all your movie editing in iMovie? I haven't used Final Cut since 2007 and have only heard bad things about the latest version. Also, iMovie seems to meet most of my needs, so haven't felt the need to use anything else.
    However, being able to produce motion graphics is appealing to me, so is Motion 5 worth purchasing if you use iMovie?
    And, if so, how easy is it to use?
    Thanks!
    Joe.

    Joe,
    I'm not sure how you want to use a Motion project in iMovie, but if you wanted to overlay Motion text over iMovie video, no I don't think you can do that. I haven't used the newer iMovie very much, but don't think you can stack video clips like you can in other video editors.
    You could, however, export the segment of iMovie where you want to superimpose text, bring that into Motion, create your text effect over the iMovie footage, export and import back into iMovie. Aside from the exporting and importing, the downside would be if you need to change the timing of something, you pretty much need to start over.
    Do try the trial of FCPX. Coming from iMovie you'll have a leg up on those who came from FCP7 or earlier. The magnetic time line might be a challenge, but look for Kevin P. McAuliffe's Creative Cow podcasts and and Mark Spencer & Steve Martin's MacBreak Studio podcasts are very helpful. Shortly after FCPX was released they both did some podcasts on getting started and understanding how FCPX works. Also take a look at Izzy Video's offerings. All three also offer Motion tutorials. Izzy has some free training. And there's lots of good help on the FCPX forum. Once you get the basics of FCPX down, you'll be amazed how much more it can do that iMovie, especially as your need get more complicated.
    And keep an eye out for Best Buy and Target discounts on iTunes gift cards. I've seen them up to 20% off. Best Buy seems to offer them every month or so. Target less frequently.
    Ross Hunter
    Orange, VA

  • Motion or Twixtor for Speed ramping & Retiming?

    Can anyone tell me if Apple Motion can create "the same" speed ramping & retiming effects that Twixtor does?
    Yeah, I'm new!
    Any help is appreciated.

    Yes, it has optical-flow retiming - it can analyze footage based on motion vectors. But it works pretty straightforward, Twixtor has a lot more options to control the effect, like using massk to track specific motion. So basically the technology is the same, but options are very limited.

  • Stabilize not applying correction to video?

    I am having issues with Stabilize in Motion 5. I have added a couple of trackers and run the analysis and Motion generates the motion vectors on screen. However, when I play back it appears the motion vectors are not being applied to the video - the video shakes just as much as it did before, and you can see the motion tracking overlay still showing the motion vectors. Am I missing something obvious here? How do I actually get Stabilize to stop the shaking?

    First of all, I must confess that I have not used Stabilize very much at all. It usually works great with the default: add + analyze (no trackers.)  So, I found one of the worst clips I could find and tried out various things with it and I have to admit, ***your problems are EASILY reproduceable***
    PLUS, in Motion 5, once you get a bad track you will never get a good one!!! not in the same project no matter how many times you delete and re-add a Stabilize behavior.  On that bad test clip I used, I got a good track ONCE. Then I Added (not duplicated) a new copy of the same clip and tried using a tracker. The track is perfect, the playback just moves the entire video around like it's a Match Move on the track. Tried deleting the tracker; Analyze again, and it's stuck with the same movement that went with the tracker. Tried deleting the retiming cache (it's used for Optical flow and other motion things) and nothing.  [Meanwhile, rechecking the original perfectly stabilized *same* clip originally imported "new" — still perfectly stabilized — to add insult to injury, if I use the tracker data (that is, if I put the first clip in the drop well) from this clip in the 2nd import clip - the stabilization is exactly the same on the 2nd clip... which is completely pointless if you can't get the "right" stabilization to begin with!] [PS- by "perfectly" I mean it's the best possible stabilization I could hope for: most of the clip was rock solid, but high jitter/jerk areas still had some "blips" in it -- lined up fine -- but a quick re-scale kind of thing -- it was a really bad clip ]
    Went into Motion 4. I didn't like the way Stabilize trackers worked for my test, deleted them, re-Analyzed with no tracker: WORKED PERFECTLY. No matter what I did to mess up the stabilization on purpose - I could always delete the trackers and re-Analyze without having to delete and replace the behavior - and start over again like I had just added the behavior. Motion 4 worked like you would expect it to.
    So... I would have to say that Stabilize is YET ANOTHER BROKEN SOMETHING IN MOTION 5!
    But back to your problem.  If you have Motion 4, use it to stabilize your video, export (as prores) and import into your Motion 5 project. If you don't have Motion 4... Open a brand new project; import your clip; Add Stabilize (NO TRACKERS); cross your fingers. If you get a good stabilization, export it out for future use.
    By all means, let Apple know of this problem via the Provide Motion Feedback menu item under Motion.
    Your specific questions: I would say if you have Motion 4, you could use the tracking region in that way, but I tried it in M5 and the Region is also a tracker and that will mess up the stabilization. If you only have M5, create a new project, import your clip, add the levels and adjust it for a "bit" more detail, add the Stabilize and Analyze only. You basically get one shot to get it right... per project per clip (maybe that's pushing it). Even in Motion 4, if the clip is in pretty bad shape, Stabilize does its best to get "most" of the clip right— so you may have to opt trimming out pieces that won't stabilize as well [in my experience, most often, that will be at the beginning and the end when you make contact with the camera to both start and stop recording, or to zoom.] You might also consider trimming the ends of the clip a bit beforehand as well because, no matter how you line up the clilp in the timeline, Motion analyzes the *entire clip*, no matter what!
    Anybody else notice the lack of a Motion 5.0.2 update when FCPX 10.0.2 came out?? I'm still waiting. Every day I check— at least 3 times. M5 must be really badly damaged to be taking this long (and I have found A LOT of problems with it... most of which won't affect the average user... but stil!)

  • Problem converting a (working) Java program into an applet

    When I'm trying to access an Image through a call to :
    mediaTracker = new MediaTracker(this);
    backGroundImage = getImage(getDocumentBase(), "background.gif");
    mediaTracker.addImage(backGroundImage, 0);
    I'm getting a nullPointerException as a result of the call to getDocumentBase() :
    C:\Chantier\Java\BallsApplet
    AppletViewer testBallsApplet.htmljava.lang.NullPointerException
    at java.applet.Applet.getDocumentBase(Applet.java:125)
    at Balls.<init>(Balls.java:84)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstruct
    orAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingC
    onstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
    at java.lang.Class.newInstance0(Class.java:296)
    at java.lang.Class.newInstance(Class.java:249)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:548)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:477)
    at sun.applet.AppletPanel.run(AppletPanel.java:290)
    at java.lang.Thread.run(Thread.java:536)
    It seems very weird to me... :-/
    (all the .gif files are in the same directory than the .class files)
    The problem appears with AppletViewer trying to open an HTML file
    containing :
    <HTML>
    <APPLET CODE="Balls.class" WIDTH=300 HEIGHT=211>
    </APPLET>
    </HTML>
    (I tried unsuccessfully the CODEBASE and ARCHIVE attributes, with and without putting the .gif and .class into a .jar file)
    I can't find the solution by myself, so, I'd be very glad if someone could help
    me with this... Thank you very much in advance ! :-)
    You'll find below the source of a small game that I wrote and debugged (without
    problem) and that I'm now (unsuccessfully) trying to convert into an Applet :
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.net.URL;
    public class Balls extends java.applet.Applet implements Runnable, KeyListener
    private Image offScreenImage;
    private Image backGroundImage;
    private Image[] gifImages = new Image[6];
    private Image PressStart ;
    private Sprite pressStartSprite = null ;
    private Image YouLose ;
    private Sprite YouLoseSprite = null ;
    private Image NextStage ;
    private Sprite NextStageSprite = null ;
    private Image GamePaused ;
    private Sprite GamePausedSprite = null ;
    //offscreen graphics context
    private Graphics offScreenGraphicsCtx;
    private Thread animationThread;
    private MediaTracker mediaTracker;
    private SpriteManager spriteManager;
    //Animation display rate, 12fps
    private int animationDelay = 83;
    private Random rand = new Random(System.currentTimeMillis());
    private int message = 0 ; // 0 = no message (normal playing phase)
    // 1 = press space to start
    // 2 = press space for next level
    // 3 = game PAUSED, press space to unpause
    // 4 = You LOSE
    public static void main(String[] args)
    try
    new Balls() ;
    catch (java.net.MalformedURLException e)
    System.out.println(e);
    }//end main
    public void start()
    //Create and start animation thread
    animationThread = new Thread(this);
    animationThread.start();
    public void init()
    try
    new Balls() ;
    catch (java.net.MalformedURLException e)
    System.out.println(e);
    public Balls() throws java.net.MalformedURLException
    {//constructor
    // Load and track the images
    mediaTracker = new MediaTracker(this);
    backGroundImage = getImage(getDocumentBase(), "background.gif");
    mediaTracker.addImage(backGroundImage, 0);
    PressStart = getImage(getDocumentBase(), "press_start.gif");
    mediaTracker.addImage(PressStart, 0);
    NextStage = getImage(getDocumentBase(), "stage_complete.gif");
    mediaTracker.addImage(NextStage, 0);
    GamePaused = getImage(getDocumentBase(), "game_paused.gif");
    mediaTracker.addImage(GamePaused, 0);
    YouLose = getImage(getDocumentBase(), "you_lose.gif");
    mediaTracker.addImage(YouLose, 0);
    //Get and track 6 images to use
    // for sprites
    gifImages[0] = getImage(getDocumentBase(), "blueball.gif");
    mediaTracker.addImage(gifImages[0], 0);
    gifImages[1] = getImage(getDocumentBase(), "redball.gif");
    mediaTracker.addImage(gifImages[1], 0);
    gifImages[2] = getImage(getDocumentBase(), "greenball.gif");
    mediaTracker.addImage(gifImages[2], 0);
    gifImages[3] = getImage(getDocumentBase(), "yellowball.gif");
    mediaTracker.addImage(gifImages[3], 0);
    gifImages[4] = getImage(getDocumentBase(), "purpleball.gif");
    mediaTracker.addImage(gifImages[4], 0);
    gifImages[5] = getImage(getDocumentBase(), "orangeball.gif");
    mediaTracker.addImage(gifImages[5], 0);
    //Block and wait for all images to
    // be loaded
    try {
    mediaTracker.waitForID(0);
    }catch (InterruptedException e) {
    System.out.println(e);
    }//end catch
    //Base the Frame size on the size
    // of the background image.
    //These getter methods return -1 if
    // the size is not yet known.
    //Insets will be used later to
    // limit the graphics area to the
    // client area of the Frame.
    int width = backGroundImage.getWidth(this);
    int height = backGroundImage.getHeight(this);
    //While not likely, it may be
    // possible that the size isn't
    // known yet. Do the following
    // just in case.
    //Wait until size is known
    while(width == -1 || height == -1)
    System.out.println("Waiting for image");
    width = backGroundImage.getWidth(this);
    height = backGroundImage.getHeight(this);
    }//end while loop
    //Display the frame
    setSize(width,height);
    setVisible(true);
    //setTitle("Balls");
    //Anonymous inner class window
    // listener to terminate the
    // program.
    this.addWindowListener
    (new WindowAdapter()
    {public void windowClosing(WindowEvent e){System.exit(0);}});
    // Add a key listener for keyboard management
    this.addKeyListener(this);
    }//end constructor
    public void run()
    Point center_place = new Point(
    backGroundImage.getWidth(this)/2-PressStart.getWidth(this)/2,
    backGroundImage.getHeight(this)/2-PressStart.getHeight(this)/2) ;
    pressStartSprite = new Sprite(this, PressStart, center_place, new Point(0, 0),true);
    center_place = new Point(
    backGroundImage.getWidth(this)/2-NextStage.getWidth(this)/2,
    backGroundImage.getHeight(this)/2-NextStage.getHeight(this)/2) ;
    NextStageSprite = new Sprite(this, NextStage, center_place, new Point(0, 0),true);
    center_place = new Point(
    backGroundImage.getWidth(this)/2-GamePaused.getWidth(this)/2,
    backGroundImage.getHeight(this)/2-GamePaused.getHeight(this)/2) ;
    GamePausedSprite = new Sprite(this, GamePaused, center_place, new Point(0, 0),true);
    center_place = new Point(
    backGroundImage.getWidth(this)/2-YouLose.getWidth(this)/2,
    backGroundImage.getHeight(this)/2-YouLose.getHeight(this)/2) ;
    YouLoseSprite = new Sprite(this, YouLose, center_place, new Point(0, 0),true);
    BackgroundImage bgimage = new BackgroundImage(this, backGroundImage) ;
    for (;;) // infinite loop
    long time = System.currentTimeMillis();
    message = 1 ; // "press start to begin"
    while (message != 0)
    repaint() ;
    try
    time += animationDelay;
    Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
    catch (InterruptedException e)
    System.out.println(e);
    }//end catch
    boolean you_lose = false ;
    for (int max_speed = 7 ; !you_lose && max_speed < 15 ; max_speed++)
    for (int difficulty = 2 ; !you_lose && difficulty < 14 ; difficulty++)
    boolean unfinished_stage = true ;
    spriteManager = new SpriteManager(bgimage);
    spriteManager.setParameters(difficulty, max_speed) ;
    //Create 15 sprites from 6 gif
    // files.
    for (int cnt = 0; cnt < 15; cnt++)
    if (cnt == 0)
    Point position = new Point(
    backGroundImage.getWidth(this)/2-gifImages[0].getWidth(this)/2,
    backGroundImage.getHeight(this)/2-gifImages[0].getHeight(this)/2) ;
    spriteManager.addSprite(makeSprite(position, 0, false));
    else
    Point position = spriteManager.
    getEmptyPosition(new Dimension(gifImages[0].getWidth(this),
    gifImages[0].getHeight(this)));
    if (cnt < difficulty)
    spriteManager.addSprite(makeSprite(position, 1, true));
    else
    spriteManager.addSprite(makeSprite(position, 2, true));
    }//end for loop
    time = System.currentTimeMillis();
    while (!spriteManager.getFinishedStage() && !spriteManager.getGameOver())
    // Loop, sleep, and update sprite
    // positions once each 83
    // milliseconds
    spriteManager.update();
    repaint();
    try
    time += animationDelay;
    Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
    catch (InterruptedException e)
    System.out.println(e);
    }//end catch
    }//end while loop
    if (spriteManager.getGameOver())
    message = 4 ;
    while (message != 0)
    spriteManager.update();
    repaint();
    try
    time += animationDelay;
    Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
    catch (InterruptedException e)
    System.out.println(e);
    }//end catch
    you_lose = true ;
    if (spriteManager.getFinishedStage())
    message = 2 ;
    while (message != 0)
    spriteManager.update();
    repaint();
    try
    time += animationDelay;
    Thread.sleep(Math.max(0,time - System.currentTimeMillis()));
    catch (InterruptedException e)
    System.out.println(e);
    }//end catch
    } // end for difficulty loop
    } // end for max_speed
    } // end infinite loop
    }//end run method
    private Sprite makeSprite(Point position, int imageIndex, boolean wind)
    return new Sprite(
    this,
    gifImages[imageIndex],
    position,
    new Point(rand.nextInt() % 5,
    rand.nextInt() % 5),
    wind);
    }//end makeSprite()
    //Overridden graphics update method
    // on the Frame
    public void update(Graphics g)
    //Create the offscreen graphics
    // context
    if (offScreenGraphicsCtx == null)
    offScreenImage = createImage(getSize().width,
    getSize().height);
    offScreenGraphicsCtx = offScreenImage.getGraphics();
    }//end if
    if (message == 0)
    // Draw the sprites offscreen
    spriteManager.drawScene(offScreenGraphicsCtx);
    else if (message == 1)
    pressStartSprite.drawSpriteImage(offScreenGraphicsCtx);
    else if (message == 2)
    NextStageSprite.drawSpriteImage(offScreenGraphicsCtx);
    else if (message == 3)
    GamePausedSprite.drawSpriteImage(offScreenGraphicsCtx);
    else if (message == 4)
    YouLoseSprite.drawSpriteImage(offScreenGraphicsCtx);
    // Draw the scene onto the screen
    if(offScreenImage != null)
    g.drawImage(offScreenImage, 0, 0, this);
    }//end if
    }//end overridden update method
    //Overridden paint method on the
    // Frame
    public void paint(Graphics g)
    //Nothing required here. All
    // drawing is done in the update
    // method above.
    }//end overridden paint method
    // Methods to handle Keyboard event
    public void keyPressed(KeyEvent evt)
    int key = evt.getKeyCode(); // Keyboard code for the pressed key.
    if (key == KeyEvent.VK_SPACE)
    if (message != 0)
    message = 0 ;
    else
    message = 3 ;
    if (key == KeyEvent.VK_LEFT)
    if (spriteManager != null)
    spriteManager.goLeft() ;
    else if (key == KeyEvent.VK_RIGHT)
    if (spriteManager != null)
    spriteManager.goRight() ;
    else if (key == KeyEvent.VK_UP)
    if (spriteManager != null)
    spriteManager.goUp() ;
    else if (key == KeyEvent.VK_DOWN)
    if (spriteManager != null)
    spriteManager.goDown() ;
    if (spriteManager != null)
    spriteManager.setMessage(message) ;
    public void keyReleased(KeyEvent evt)
    public void keyTyped(KeyEvent e)
    char key = e.getKeyChar() ;
    //~ if (key == 's')
    //~ stop = true ;
    //~ else if (key == 'c')
    //~ stop = false ;
    //~ spriteManager.setStop(stop) ;
    }//end class Balls
    //===================================//
    class BackgroundImage
    private Image image;
    private Component component;
    private Dimension size;
    public BackgroundImage(
    Component component,
    Image image)
    this.component = component;
    size = component.getSize();
    this.image = image;
    }//end construtor
    public Dimension getSize(){
    return size;
    }//end getSize()
    public Image getImage(){
    return image;
    }//end getImage()
    public void setImage(Image image){
    this.image = image;
    }//end setImage()
    public void drawBackgroundImage(Graphics g)
    g.drawImage(image, 0, 0, component);
    }//end drawBackgroundImage()
    }//end class BackgroundImage
    //===========================
    class SpriteManager extends Vector
    private BackgroundImage backgroundImage;
    private boolean finished_stage = false ;
    private boolean game_over = false ;
    private int difficulty ;
    private int max_speed ;
    public boolean getFinishedStage()
    finished_stage = true ;
    for (int cnt = difficulty ; cnt < size(); cnt++)
    Sprite sprite = (Sprite)elementAt(cnt);
    if (!sprite.getEaten())
    finished_stage = false ;
    return finished_stage ;
    public boolean getGameOver() {return game_over ;}
    public void setParameters(int diff, int speed)
    difficulty = diff ;
    max_speed = speed ;
    finished_stage = false ;
    game_over = false ;
    Sprite sprite;
    for (int cnt = 0;cnt < size(); cnt++)
    sprite = (Sprite)elementAt(cnt);
    sprite.setSpeed(max_speed) ;
    public SpriteManager(BackgroundImage backgroundImage)
    this.backgroundImage = backgroundImage ;
    }//end constructor
    public Point getEmptyPosition(Dimension spriteSize)
    Rectangle trialSpaceOccupied = new Rectangle(0, 0,
    spriteSize.width,
    spriteSize.height);
    Random rand = new Random(System.currentTimeMillis());
    boolean empty = false;
    int numTries = 0;
    // Search for an empty position
    while (!empty && numTries++ < 100)
    // Get a trial position
    trialSpaceOccupied.x =
    Math.abs(rand.nextInt() %
    backgroundImage.
    getSize().width);
    trialSpaceOccupied.y =
    Math.abs(rand.nextInt() %
    backgroundImage.
    getSize().height);
    // Iterate through existing
    // sprites, checking if position
    // is empty
    boolean collision = false;
    for(int cnt = 0;cnt < size(); cnt++)
    Rectangle testSpaceOccupied = ((Sprite)elementAt(cnt)).getSpaceOccupied();
    if (trialSpaceOccupied.intersects(testSpaceOccupied))
    collision = true;
    }//end if
    }//end for loop
    empty = !collision;
    }//end while loop
    return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y);
    }//end getEmptyPosition()
    public void update()
    Sprite sprite;
    // treat special case of sprite #0 (the player)
    sprite = (Sprite)elementAt(0);
    sprite.updatePosition() ;
    int hitIndex = testForCollision(sprite);
    if (hitIndex != -1)
    if (hitIndex < difficulty)
    { // if player collides with an hunter (red ball), he loose
    sprite.setEaten() ;
    game_over = true ;
    else
    // if player collides with an hunted (green ball), he eats the green
    ((Sprite)elementAt(hitIndex)).setEaten() ;
    //Iterate through sprite list
    for (int cnt = 1;cnt < size(); cnt++)
    sprite = (Sprite)elementAt(cnt);
    //Update a sprite's position
    sprite.updatePosition();
    //Test for collision. Positive
    // result indicates a collision
    hitIndex = testForCollision(sprite);
    if (hitIndex >= 0)
    //a collision has occurred
    bounceOffSprite(cnt,hitIndex);
    }//end if
    }//end for loop
    }//end update
    public void setMessage(int message)
    Sprite sprite;
    //Iterate through sprite list
    for (int cnt = 0;cnt < size(); cnt++)
    sprite = (Sprite)elementAt(cnt);
    //Update a sprite's stop status
    sprite.setMessage(message);
    }//end for loop
    }//end update
    public void goLeft()
    Sprite sprite = (Sprite)elementAt(0);
    sprite.goLeft() ;
    public void goRight()
    Sprite sprite = (Sprite)elementAt(0);
    sprite.goRight() ;
    public void goUp()
    Sprite sprite = (Sprite)elementAt(0);
    sprite.goUp() ;
    public void goDown()
    Sprite sprite = (Sprite)elementAt(0);
    sprite.goDown() ;
    private int testForCollision(Sprite testSprite)
    //Check for collision with other
    // sprites
    Sprite sprite;
    for (int cnt = 0;cnt < size(); cnt++)
    sprite = (Sprite)elementAt(cnt);
    if (sprite == testSprite)
    //don't check self
    continue;
    //Invoke testCollision method
    // of Sprite class to perform
    // the actual test.
    if (testSprite.testCollision(sprite))
    //Return index of colliding
    // sprite
    return cnt;
    }//end for loop
    return -1;//No collision detected
    }//end testForCollision()
    private void bounceOffSprite(int oneHitIndex, int otherHitIndex)
    //Swap motion vectors for
    // bounce algorithm
    Sprite oneSprite = (Sprite)elementAt(oneHitIndex);
    Sprite otherSprite = (Sprite)elementAt(otherHitIndex);
    Point swap = oneSprite.getMotionVector();
    oneSprite.setMotionVector(otherSprite.getMotionVector());
    otherSprite.setMotionVector(swap);
    }//end bounceOffSprite()
    public void drawScene(Graphics g)
    //Draw the background and erase
    // sprites from graphics area
    //Disable the following statement
    // for an interesting effect.
    backgroundImage.drawBackgroundImage(g);
    //Iterate through sprites, drawing
    // each sprite
    for (int cnt = 0;cnt < size(); cnt++)
    ((Sprite)elementAt(cnt)).drawSpriteImage(g);
    }//end drawScene()
    public void addSprite(Sprite sprite)
    addElement(sprite);
    }//end addSprite()
    }//end class SpriteManager
    //===================================//
    class Sprite
    private Component component;
    private Image image;
    private Rectangle spaceOccupied;
    private Point motionVector;
    private Rectangle bounds;
    private Random rand;
    private int message = 0 ; // number of message currently displayed (0 means "no message" = normal game)
    private int max_speed = 7 ;
    private boolean eaten = false ; // when a green sprite is eaten, it is no longer displayed on screen
    private boolean wind = true ;
    private boolean go_left = false ;
    private boolean go_right = false ;
    private boolean go_up = false ;
    private boolean go_down = false ;
    public Sprite(Component component,
    Image image,
    Point position,
    Point motionVector,
    boolean Wind
    //Seed a random number generator
    // for this sprite with the sprite
    // position.
    rand = new Random(position.x);
    this.component = component;
    this.image = image;
    setSpaceOccupied(new Rectangle(
    position.x,
    position.y,
    image.getWidth(component),
    image.getHeight(component)));
    this.motionVector = motionVector;
    this.wind = Wind ;
    //Compute edges of usable graphics
    // area in the Frame.
    int topBanner = ((Container)component).getInsets().top;
    int bottomBorder = ((Container)component).getInsets().bottom;
    int leftBorder = ((Container)component).getInsets().left;
    int rightBorder = ((Container)component).getInsets().right;
    bounds = new Rectangle( 0 + leftBorder, 0 + topBanner
    , component.getSize().width - (leftBorder + rightBorder)
    , component.getSize().height - (topBanner + bottomBorder));
    }//end constructor
    public void setMessage(int message_number)
    message = message_number ;
    public void setSpeed(int speed)
    max_speed = speed ;
    public void goLeft()
    go_left = true ;
    public void goRight()
    go_right = true ;
    public void goUp()
    go_up = true ;
    public void goDown()
    go_down = true ;
    public void setEaten()
    eaten = true ;
    setSpaceOccupied(new Rectangle(4000,4000,0,0)) ;
    public boolean getEaten()
    return eaten ;
    public Rectangle getSpaceOccupied()
    return spaceOccupied;
    }//end getSpaceOccupied()
    void setSpaceOccupied(Rectangle spaceOccupied)
    this.spaceOccupied = spaceOccupied;
    }//setSpaceOccupied()
    public void setSpaceOccupied(
    Point position){
    spaceOccupied.setLocation(
    position.x, position.y);
    }//setSpaceOccupied()
    public Point getMotionVector(){
    return motionVector;
    }//end getMotionVector()
    public void setMotionVector(
    Point motionVector){
    this.motionVector = motionVector;
    }//end setMotionVector()
    public void setBounds(Rectangle bounds)
    this.bounds = bounds;
    }//end setBounds()
    public void updatePosition()
    Point position = new Point(spaceOccupied.x, spaceOccupied.y);
    if (message != 0)
    return ;
    //Insert random behavior. During
    // each update, a sprite has about
    // one chance in 10 of making a
    // random change to its
    // motionVector. When a change
    // occurs, the motionVector
    // coordinate values are forced to
    // fall between -7 and 7. This
    // puts a cap on the maximum speed
    // for a sprite.
    if (!wind)
    if (go_left)
    motionVector.x -= 2 ;
    if (motionVector.x < -15)
    motionVector.x = -14 ;
    go_left = false ;
    if (go_right)
    motionVector.x += 2 ;
    if (motionVector.x > 15)
    motionVector.x = 14 ;
    go_right = false ;
    if (go_up)
    motionVector.y -= 2 ;
    if (motionVector.y < -15)
    motionVector.y = -14 ;
    go_up = false ;
    if (go_down)
    motionVector.y += 2 ;
    if (motionVector.y > 15)
    motionVector.y = 14 ;
    go_down = false ;
    else if(rand.nextInt() % 7 == 0)
    Point randomOffset =
    new Point(rand.nextInt() % 3,
    rand.nextInt() % 3);
    motionVector.x += randomOffset.x;
    if(motionVector.x >= max_speed)
    motionVector.x -= max_speed;
    if(motionVector.x <= -max_speed)
    motionVector.x += max_speed ;
    motionVector.y += randomOffset.y;
    if(motionVector.y >= max_speed)
    motionVector.y -= max_speed;
    if(motionVector.y <= -max_speed)
    motionVector.y += max_speed;
    }//end if
    //Move the sprite on the screen
    position.translate(motionVector.x, motionVector.y);
    //Bounce off the walls
    boolean bounceRequired = false;
    Point tempMotionVector = new Point(
    motionVector.x,
    motionVector.y);
    //Handle walls in x-dimension
    if (position.x < bounds.x)
    bounceRequired = true;
    position.x = bounds.x;
    //reverse direction in x
    tempMotionVector.x = -tempMotionVector.x;
    else if ((position.x + spaceOccupied.width) > (bounds.x + bounds.width))
    bounceRequired = true;
    position.x = bounds.x +
    bounds.width -
    spaceOccupied.width;
    //reverse direction in x
    tempMotionVector.x =
    -tempMotionVector.x;
    }//end else if
    //Handle walls in y-dimension
    if (position.y < bounds.y)
    bounceRequired = true;
    position.y = bounds.y;
    tempMotionVector.y = -tempMotionVector.y;
    else if ((position.y + spaceOccupied.height)
    > (bounds.y + bounds.height))
    bounceRequired = true;
    position.y = bounds.y +
    bounds.height -
    spaceOccupied.height;
    tempMotionVector.y =
    -tempMotionVector.y;
    }//end else if
    if(bounceRequired)
    //save new motionVector
    setMotionVector(
    tempMotionVector);
    //update spaceOccupied
    setSpaceOccupied(position);
    }//end updatePosition()
    public void drawSpriteImage(Graphics g)
    if (!eaten)
    g.drawImage(image,
    spaceOccupied.x,
    spaceOccupied.y,
    component);
    }//end drawSpriteImage()
    public boolean testCollision(Sprite testSprite)
    //Check for collision with
    // another sprite
    if (testSprite != this)
    return spaceOccupied.intersects(
    testSprite.getSpaceOccupied());
    }//end if
    return false;
    }//end testCollision
    }//end Sprite class
    //===================================//
    Thanks for your help...

    Sorry,
    Can you tell me how do you solve it because I have got the same problem.
    Can you indicate me the topic where did you find solution.
    Thank in advance.

Maybe you are looking for