Re: Trying to write a pan/zoom detection algorithm



On 2007-07-11, ShiningMasamune@xxxxxxxxx <ShiningMasamune@xxxxxxxxx> wrote:
Greetings. There's a programming problem that I've been puzzling over
for some time now, and I'm hoping to get some advice. Here's what I'm
trying to do.

Many times in video files, especially in anime, the camera zooms or
pans along a still image. What I need to accomplish is to write a
program that will ascertain exactly how far the camera has panned/
zoomed between one frame and another. In other words, given a later
frame, I need to find out how many pixels I would have to shift over
and to what percentage I would have to zoom in order to get the
original frame.

I realize that despite how simple the problem sounds and how easy it
is for humans to do, coding this will be no small task. From what
I've researched so far, I gathered that what I want to do is similar
to the motion detection algorithms used in video compression. But I
could really use some advice and a point in the right direction. Can
anyone give me any advice on this or tell me where I might find some
help?

For a starting simplification, assume the image contains strong vertical
lines and the pan is perfectly horizontal. Then the algorithm only
needs to inspect one horizontal scanline.

Given scanlines A and B (arrays of pixels):

for offset= -line_width/2 to line_width/2
corr[offset] = correlate(A+offset, B)

We are sliding one image across the other, and looking for the
strongest match.

Obviously, we need to allow for the non-overlapping part somehow.

If the highest corr is greater than a threshold, you have the offset.

What is correlation? In audio, it can be sum(A[n] * B[n]). Two
identical samples will have positive * positive and negative *
negative; thus very high correlation. To adapt the idea to video,
maybe map each scanline as:

map (pixel.brightness - median_pixel_brightness) scanline.pixels

resulting in pixels that are half positive and half negative.

To sense motions other than horizontal, you could use a reversed
Bresenham algorithm to extract diagonal scanlines.
.



Relevant Pages

  • Re: Suggestions for recording a bassoon?
    ... also learned that the camera ... ... "I'll be recording a bassoon for a video." ... This because you said "record for a video" rather than ... Specifically because of Richard Crowley's advice I called and asked ...
    (rec.audio.pro)
  • Re: advice please
    ... advice on a getting a new camera. ... stills at 10 megapixel and video in AVI format? ...
    (uk.rec.photo.misc)
  • Re: No Windows Media in Windows XP, PS2!
    ... Your recommendation was the first advice they gave me, but, ... Which version of media player do you have? ... the video display card has provided updated software to fix this issue ...
    (microsoft.public.windowsmedia)
  • Re: Dynamic loading of javascript files into web pages
    ... I saw a video online. ... Why wasn't it in the FAQ? ... Video presentations often contain advice that is either ... I don't recommend this technique either. ...
    (comp.lang.javascript)
  • Re: Ping : Conway (BPC)
    ... I've failed to thank you for your advice on my display problem. ... bucks to refine/debug/update their drivers. ... You haven't told us which video card or chip you have. ...
    (soc.culture.scottish)

Loading