View Full Version : Stabilize via sprocket holes?
althor1138
29th July 2012, 00:56
I have a short film that is less than a minute long that I have captured with a digital camera and slide copier. The frames are captured entirely, including the sprocket holes. I want to stabilize the film but I don't want to use Depan or Deshaker because it is hard to tweak from scene to scene and it ends up cutting off some of the image at times.
Is it possible to somehow in Avisynth align the sprocket holes of each frame to match the first frame?
Thanks in advance. Even if the answer is simply no it will save me some time :).
jmac698
29th July 2012, 03:54
Yes, there's been cases where I've wanted to stabilize one object and depan is more for global stabilization.
Try Centertracker, it's meant to focus on one thing.
videoFred
30th July 2012, 06:54
With Depan, it is possible to do the motion detection on the sprocket holes only, and then apply the result on the entire clip.
Please try this script:
# film stabilisation script by videoFred.
# modified june 2012
#=============================================================================================
film= "C:\Users\You\Documents\Yourfile.avi" # source clip, you must specify the full path here
#PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
result="stabS" # specify the wanted output here stab= stabilised clip, stabS= comparison before/after
trim_begin=2 play_speed= 18 #trim frames and play speed
#SIZE, CROP AND BORDERS PARAMETERS
#----------------------------------------------------------------------------------------------------------------------------
CLeft=20 CTop=20 CRight=20 CBottom=20 #crop values after Depan and before final resizing
W=720 H=576 #final size after cropping
bord_left=0 bord_top=0 bord_right=0 bord_bot=0 #720p= borders 150
#STABILISING PARAMETERS, YOU REALY MUST USE STABS TO CHECK STABILISATION!
#----------------------------------------------------------------------------------------------------------------------------
maxstabH=40
maxstabV=40 #maximum values for the stabiliser (in pixels) 20 is a good start value
est_left=40 est_top=40 est_right=40 est_bottom=40 #crop values for special Estimate clip
trust_value= 1.0 # scene change detection, higher= more sensitive
cutoff_value= 0.5 # no need to change this, but you can play with it and see what you get
# END VARIABLES, BEGIN SCRIPT
#=================================================================================================================================
SetMemoryMax(800) #set this to 1/3 of the available memory
Loadplugin("plugins/Depan.dll")
LoadPlugin("plugins/DepanEstimate.dll")
source1= AviSource(film).assumefps(play_speed).trim(trim_begin,0).converttoYV12()
#STABILIZING/CROPPING
#..........................................................................................................................................
stab_reference= source1.crop(est_left,est_top,-est_right,-est_bottom)
mdata=DePanEstimate(stab_reference,trust=trust_value,dxmax=maxstabH,dymax=maxstabV)
stab=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,mirror=15)
stab2= stab.crop(CLeft,CTop,-CRight,-CBottom)
stab3=DePanStabilize(source1,data=mdata,cutoff=cutoff_value,dxmax=maxstabH,dymax=maxstabV,method=0,info=true)
WS= width(stab)
HS= height(stab)
stab4= stab3.addborders(10,10,10,10,$B1B1B1).Lanczos4Resize(WS,HS)
stab5= Lanczos4Resize(stab2,W,H).sharpen(0.5)
#RESULT5: SPECIAL SERVICE CLIP FOR RESULT S5
#..................................................................................................................................................
result5= overlay(source1,greyscale(stab_reference),x=est_left,y=est_top).addborders(2,2,2,2,$FFFFFF).Lanczos4Resize(WS,HS)
#PARAMETERS FOR THE COMPARISONS
#..................................................................................................................................................
W2= W+bord_left+bord_right
H2= H+bord_top+bord_bot
source4=Lanczos4Resize(source1,W2,H2)
#SPECIAL COMPARISON CLIP FOR TESTING THE STABILIZER
#.........................................................................................................................................................................
stabS= stackhorizontal(subtitle(result5,"baseclip for stabiliser -only the B/W clip is used",size=32,align=2),\
subtitle(stab4,"test stabiliser: dx=horizontal, dy=vertical",size=32,align=5)).converttoYUY2()
Eval(result)
With est_left etc.. you can crop the Depan Estimate clip to the sprocket holes only. With stabS you can see what is happening.
Fred.
jmac698
30th July 2012, 07:02
That's an obvious solution Fred, great idea. I was always wondering if depan can be set to have zero inertia, meaning it absolutely stabilizes the scene for each frame, in this case a sprocket image.
althor1138
30th July 2012, 21:24
Thanks. Jmac and VideoFred. I have tried both methods now and they both work fairly well.
Centertracker works very good other than the fact that I can't seem to get it to show the whole frame when I'm selecting the area for stabilization. (EDIT: What I mean is that centertracker will open and process the video but the GUI will only show a portion of the frame during area selection) This kind of prevents me from selecting exactly the area I would like. The frames were captured at around 2k resolution. If I could find a way to use centertracker with high resolution video it would be perfect.
Video Fred's script would also work quite well I think but I can't seem to crop down to an area small enough to select only the sprocket holes. It keeps telling me this:
DepanEstimate: DXMAX must be less than WINX/2!
It also doesn't stabilize as well as centertracker but it is pretty acceptable.
johnmeyer
30th July 2012, 21:38
I know that you have already rejected the idea of using Deshaker, but I thought I should nonetheless point out that it does provide the ability to focus just on the outside edges of the video. You use the "Ignore Pixels" settings which lets you define areas of the image that you wish to ignore (the center, from top to bottom, in your case). Deshaker will then stabilize just on the sprockets.
althor1138
30th July 2012, 21:45
I have tried it with many different settings and it never reliably seems to lock onto anything. A person I know has attempted the same thing and even talked with Gunnar about the problem and he said that it wouldn't work so well. Something about the light in the sprocket holes or something. I see that he has a newer version out since the last time I tried it so maybe it will produce better results?
jmac698
30th July 2012, 21:55
Hi,
Fixing these problems is easy Just crop to the sprocket holes yourself, save that as a script, then load the script as a video to centertracker. Then use it's output but compensate the coordinates to fix the whole frame, if you know what I mean.
althor1138
30th July 2012, 22:16
Hi,
Fixing these problems is easy Just crop to the sprocket holes yourself, save that as a script, then load the script as a video to centertracker. Then use it's output but compensate the coordinates to fix the whole frame, if you know what I mean.
This worked nearly flawlessly. It is by far the most stable registration I've achieved. I cropped the image down to an area that covered 2 sprocket holes and stopped just before the next holes. Then set the area about 100 pixels above and below the holes and set the center in the middle.
The auto-generated avs file is flawed though. I had to create a variable that makes a blankclip from the source vid and feed it to scriptclip.
videoFred
31st July 2012, 09:29
Video Fred's script would also work quite well I think but I can't seem to crop down to an area small enough to select only the sprocket holes. It keeps telling me this:
DepanEstimate: DXMAX must be less than WINX/2!
Try this:
maxstabH=10 (or less)
maxstabV=10
Fred.
althor1138
3rd August 2012, 22:08
Try this:
maxstabH=10 (or less)
maxstabV=10
Fred.
Thanks a bunch. It now works great and I can crop to the portion I want to.
As a side thing I'm wondering if anybody knows a good way of aligning the optical audio from a second worth of frames into 1 long frame?
jmac698
4th August 2012, 14:41
I think you want freezeframe.
happyvideo
24th August 2012, 18:57
Centertracker works very good other than the fact that I can't seem to get it to show the whole frame when I'm selecting the area for stabilization. (EDIT: What I mean is that centertracker will open and process the video but the GUI will only show a portion of the frame during area selection) This kind of prevents me from selecting exactly the area I would like. The frames were captured at around 2k resolution. If I could find a way to use centertracker with high resolution video it would be perfect.
this is due to OpenCV's window handling. The maximum display size depends on the resultion of your screen. If it is for example 1280x800 that will be the maximum size. Anything larger than that will be cropped. I've checked if there's a workaround. Resizing is possible:
http://opencv.willowgarage.com/documentation/c/highgui_qt_new_functions.html
however, with the smaller image choosing the area becomes impossible. I will keep an eye on that issue and if there's a solution I'll implement it.
Thus, setting the screen resolution to the desired dimensions (if possible) is the only method to deal with it so far.
Stephan
ps. sry for the late reply, just found the topic :)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.