Re: Trying to write a pan/zoom detection algorithm
- From: John Doe <john@xxxxxxxxxxx>
- Date: 15 Jul 2007 21:36:20 GMT
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.
.
- References:
- Trying to write a pan/zoom detection algorithm
- From: ShiningMasamune
- Trying to write a pan/zoom detection algorithm
- Prev by Date: Custom Software Development
- Next by Date: Re: Inspirational language design books?
- Previous by thread: Re: Trying to write a pan/zoom detection algorithm
- Next by thread: How to shift multi bytes for certain bits?
- Index(es):
Relevant Pages
|
Loading