Log in

View Full Version : Rotation: New script!


redfordxx
28th January 2020, 07:38
EDIT:Hours and hours and I didn't give up.
Script for camera rotation around x and y axes in the attachment. You need to enter FoV, direction and amount of the rotation ... all in degrees.

Basic usage:
FoV=65
deg_dir=30
deg_amt=10

ColorBars().Trim(0,1000).Killaudio()

RotateCamera(FoV, deg_dir, deg_amt, add_borders=-512)
Script example:borders=240
FoV=65
dir_speed=5.0
amt_speed=0.5

ColorBars(pixel_type="YV12").Trim(0,10000).Killaudio()
AddBorders(borders,borders,borders,borders,$000000)
ScriptClip("""
RotateCamera(FoV, dir_speed*current_frame, amt_speed*current_frame, has_borders=borders, info=true, qq=4)
ConvertToYV12
""")


Another script:
tested_frame=3167

#### camera
FoV=62.55934

#### script
layers=8
base_dir_step=45



################## setup amount
# borders for amount 2
maxamt=8.0
max_borders=160
min_borders=80

# borders for amount 3
#maxamt=3.0
#max_borders=80
#min_borders=40

# borders for amount 4
#maxamt=4.0
#max_borders=120
#min_borders=60



##### precalc
frcnt=floor(layers*(layers+1)*180/base_dir_step)
amt_step=maxamt/layers

#clip
a=LSMASHVideoSource("....",format="RGB32").AddBorders(max_borders,max_borders,max_borders,max_borders,$FF00FF)
c0=a.Trim(tested_frame,-1).Loop(frcnt+1)

c0.ScriptClip("""
c=last
cf=current_frame-1
lvl=(cf<0) ? 0 : floor((1+sqrt(1+4*cf*base_dir_step/180))/2)
dir=(cf<0) ? 0 : cf*base_dir_step/lvl-(lvl-1)*180
amt=lvl*amt_step
c.RotateCamera(FoV, dir, amt, has_borders=max_borders, info=false, qq=4, lock_central=true)
(1==1) ? last : last.Subtitle("current_frame = "+string(current_frame)+"\n" +\
"layers = "+string(layers)+"\n" +\
"frcnt = "+string(frcnt)+"\n" +\
"base_dir_step = "+string(base_dir_step)+"\n" +\
"lvl = "+string(lvl)+"\n" +\
"dir = "+string(dir)+"\n" +\
"amt = "+string(amt)+"\n" +\
"amt_step = "+string(amt_step)+"\n" \
,lsp=0)
#ConvertToYV12
""")

Crop(max_borders-min_borders,max_borders-min_borders,-(max_borders-min_borders),-(max_borders-min_borders))



Warp (https://forum.doom9.org/showthread.php?t=176031) needed

TheFluff
28th January 2020, 10:31
I don't understand what you are trying to do. Please draw a diagram of the camera and the subject and mark the axis of rotation.

redfordxx
28th January 2020, 11:30
I thought it would be unerstandable from the other post. My fault.
Ok. I cannot draw right now, but...

I have four points in the real world. They will appear as four pixels on the screen with coordinates (x1,y1) ... (x4,y4).
I will rotate the camera down around the x axis.
What will be the new pixel coordinates of these four points?

TheFluff
28th January 2020, 11:32
The problem is I don't know which convention you're using for axis naming. Let's do some ascii art. Say we're looking at a camera from directly above it:

+--+
| |
+------+ |
| |
+------+ |
| |
+--+

The lens is pointing to the left, of course. Now, is the X axis parallel with the the lens (as in, horizontal in the diagram), is it parallel with the ground but perpendicular to the lens (as in, vertical in the diagram), or is it perpendicular to both of them (coming out of the screen in the diagram)?

redfordxx
28th January 2020, 11:37
No.
I thought the lens is looking as I am looking on the monitor. In your picture x is vertical.

redfordxx
28th January 2020, 11:44
... and z is in your picture horizontal and y is going though the ground.

johnmeyer
28th January 2020, 16:27
Not sure where the tangent function comes in.

The camera rotates horizontally and, in most systems, that angle of rotation would be described by either a sine or cosine function (they are, as you probably know, pretty much interchangeable in many equations). The camera can then go up or down, and that too would be described in the same way. You also might have a camera rotation. There can also be an up or down and back and forth (basicially, a dolly move). Finally, the camera itself might rotate on some sort of gimbal so it can it can rotate upside down.

If you want answers, you might get help by Googling:

drone camera gimbal "equations" sin cos (https://www.google.com/search?client=firefox-b-1-d&sxsrf=ACYBGNRierS3guxMvibBd5uV_q1JB-ccHg%3A1580225207786&ei=t1IwXrjJL9P0tAb_26voCQ&q=drone+camera+gimbal+%22equations%22+sin+cos&oq=drone+camera+gimbal+%22equations%22+sin+cos&gs_l=psy-ab.3..33i160l2j33i299l2.73211.75976..76491...0.5..0.185.1137.0j8......0....1..gws-wiz.......0i71j35i39.aRkXe9dbTfY&ved=0ahUKEwj4gLPRzabnAhVTOs0KHf_tCp0Q4dUDCAo&uact=5)

[edit]I just glanced at some of the results and the modeling can get pretty hairy, depending on what you're trying to do, because when you change one of the servo motors, depending on how the gimbal is contructed, that can alter the mechanics of the other parts of the mechanism.

TheFluff
28th January 2020, 17:04
Not sure where the tangent function comes in.

The camera rotates horizontally and, in most systems, that angle of rotation would be described by either a sine or cosine function (they are, as you probably know, pretty much interchangeable in many equations). The camera can then go up or down, and that too would be described in the same way. You also might have a camera rotation. There can also be an up or down and back and forth (basicially, a dolly move). Finally, the camera itself might rotate on some sort of gimbal so it can it can rotate upside down.

If you want answers, you might get help by Googling:

drone camera gimbal "equations" sin cos (https://www.google.com/search?client=firefox-b-1-d&sxsrf=ACYBGNRierS3guxMvibBd5uV_q1JB-ccHg%3A1580225207786&ei=t1IwXrjJL9P0tAb_26voCQ&q=drone+camera+gimbal+%22equations%22+sin+cos&oq=drone+camera+gimbal+%22equations%22+sin+cos&gs_l=psy-ab.3..33i160l2j33i299l2.73211.75976..76491...0.5..0.185.1137.0j8......0....1..gws-wiz.......0i71j35i39.aRkXe9dbTfY&ved=0ahUKEwj4gLPRzabnAhVTOs0KHf_tCp0Q4dUDCAo&uact=5)

[edit]I just glanced at some of the results and the modeling can get pretty hairy, depending on what you're trying to do, because when you change one of the servo motors, depending on how the gimbal is contructed, that can alter the mechanics of the other parts of the mechanism.

I... don't think has anything to do with the question in the OP.

As far as I understand it, what OP is asking for is basically a 3D perspective transform, except in a rather roundabout way. Consider the upper diagram in this image:

https://i.imgur.com/QSeHIhK.png

We have a camera located at C and a camera-referenced coordinate system with three axes denoted by capital X, Y and Z. We're pretending that the video frame is the image plane (perhaps thinking of it as a flat plane that perfectly fills the camera viewport at this particular distance from C), and so we also have a two-dimensional view-referenced coordinate system with two axes (x and y). Now, if we tilt the camera down by some angle (rotating it around the X axis), we want to find the view-referenced coordinates for the corners of the image, so we can feed them to the quad() filter.

I'm not experienced enough with 3D to solve this, but it seems relatively obnoxious and probably involves some coordinate transforms (c.f. OpenGL's various coordinate systems (https://learnopengl.com/Getting-started/Coordinate-Systems)). I think it's actually made more complex by involving quad(), but again I'm not all that well versed in 3D graphics.

redfordxx
28th January 2020, 17:58
Exactly Fluff... thank you.
You assume quad is not the way to do in in avs?

TheFluff
28th January 2020, 18:22
I don't really know, to be honest. I don't know of any other filter that can do this sort of perspective transform off the top of my head. Something about the conversion to view-referenced coordinates seems like overcomplicating things to me, but that's just a hunch. Don't take my word for it, I've barely touched 3D stuff at all.

redfordxx
29th January 2020, 10:06
I am starting to be mad...
I am drawing triangles everywhere... and still no success.
I didn.t think it would be difficult. But I don't know what I am missing.

redfordxx
29th January 2020, 18:39
I think I figured it out. I am gonna test it.

redfordxx
30th January 2020, 10:50
I have some results already. Only it is misbehaving when rotating along two axes.
I will share soon results hopefully...

redfordxx
31st January 2020, 21:30
d=x*SIN(rad_dir)+y*COS(rad_dir)
r=Sqrt( (Pow(TAN(ATAN(d)+rad_amt),2)+1)/(Pow(d,2)+1) )

x_new=x*r+TAN(ATAN(d)+rad_amt)*SIN(rad_dir)-d*SIN(rad_dir)*r #new value x
y_new=y*r+TAN(ATAN(d)+rad_amt)*COS(rad_dir)-d*COS(rad_dir)*r #new value y

These are working formulas. I'll soon share the finished function.

Before that...can anyone simplify this?

redfordxx
2nd February 2020, 14:42
I finished the script and posted.... there are still some todos...

StainlessS
2nd February 2020, 15:57
Thanks for your herculean effort red, much appreciated.
Can attachment be approved please Mr Moderator. [EDIT: In 1st post]

StainlessS
4th February 2020, 12:37
Bump!


can attachment be approved please mr moderator. [edit: In 1st post]

redfordxx
4th February 2020, 13:33
Can attachment be approved please Mr Moderator. [EDIT: In 1st post]

Should I better share attachments via links? What is best server easier without registering?

StainlessS, you have full PM quota...😉

StainlessS
4th February 2020, 16:32
What is best server easier without registering?
SendSpace(30 day storage), and Pastebin(text only), PostImage (images only) do not req register
https://www.sendspace.com/
https://pastebin.com/
https://postimage.org/

PostImage sometimes slips in a link (following forum embedded image) that points to some advert, just need edit out the appended link [does not happen if register].

MediaFire(big files, req register), I currently have more than 50GB free storage(not sure exactly how much, I only use a few hundred MB, allowance grows with membership time).

you have full PM quota
Yep, stops people like you from bothering me.
Cleared to 99.0%.

poisondeathray
4th February 2020, 17:25
Nice work!

StainlessS
4th February 2020, 17:45
Red,
Script was only 8KB, you can post up to 16KB in Usage forum (20KB in Devs), just remember to wrap in CODE tags.
(the word CODE wrapped in '[' and ']' characters) and Slash /CODE wrapped for closing tag).

redfordxx
6th February 2020, 14:39
I put another rotation example in the 1st post.

I would like to make them part of the rotation avsi and publish, but it would be better with to do it in cycles.

A little help here, guys... how to use GScript, For cycle and arrays in AVS+?

Thanx