Comparing images to determine camera movement

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
bigtable
Posts: 14
Joined: 2008-01-23T22:37:27-07:00

Comparing images to determine camera movement

Post by bigtable »

One for the experts:

I'm trying to think of a way to analyze video and compose a single image, stitching the differences between every X frames together. For example, a camera is panning from left to right. I want to build a new stand alone image using frames from the video. The problem is, I do not know if the camera is moving west to east, east to west, north to south, etc.. Is there any known method for determining camera movement from a sequence of images? Bonus points for somewhat accurate assemblage (crops) from said camera movement.

Luke
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Comparing images to determine camera movement

Post by anthony »

Make a small image of something complex in the middle of the first frame, then look for that image in the next frame.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
bigtable
Posts: 14
Joined: 2008-01-23T22:37:27-07:00

Re: Comparing images to determine camera movement

Post by bigtable »

anthony wrote:Make a small image of something complex in the middle of the first frame, then look for that image in the next frame.
I see what you're saying. In the case of automating that approach I won't know what is interesting. What if I were to take a crop of the center of the image and compare to the next? Assuming that works (and if sometimes it doesn't, that's fine), what's the best approach to compare the small image to the next larger image? I've seen a few examples here in the forums but I'm not sure if there's a preferred method for my application. My next question is do you have any advice for measuring the XY offset to the match in the sub-image compare?

Thanks very much
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Comparing images to determine camera movement

Post by fmw42 »

The best match score and location will be returned by the compare function. But you can also use the returned match score image to seek the max value. In both cases, the location will be the offset of the upper left corner of the smaller image with respect to the upper left corner of the larger image.

see viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076

but you now need to add subimage-search http://www.imagemagick.org/script/comma ... age-search to the command line to make it distinguish from two same size image compares.

see also http://www.imagemagick.org/script/compare.php and http://www.imagemagick.org/Usage/compare/

there is also a new metric for comparison ncc -- normalized cross correlation, but it may be slower than rmse

see http://www.imagemagick.org/script/comma ... php#metric
bigtable
Posts: 14
Joined: 2008-01-23T22:37:27-07:00

Re: Comparing images to determine camera movement

Post by bigtable »

fmw42 wrote:The best match score and location will be returned by the compare function. But you can also use the returned match score image to seek the max value. In both cases, the location will be the offset of the upper left corner of the smaller image with respect to the upper left corner of the larger image.

see viewtopic.php?f=1&t=14613&p=51076&hilit ... ric#p51076
That was hidden in plain sight. Got it! I'm hoping my center crop with known coords will be sufficient to use just

Code: Select all

compare -metric rmse largeimage smallimage resultimages
I'll give it a go and post an example in case someone needs a full working example someday. This is being used in conjunction with http://popartmachine.com/ (Vangobot), a painting robot.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Comparing images to determine camera movement

Post by fmw42 »

you now need to add -subimage-search with recent versions of IM for two images that are not the same size

needed as of IM 6.6.3-7
Post Reply