View Single Post
Old 15th September 2019, 23:28   #2  |  Link
_Al_
Registered User
 
Join Date: May 2011
Posts: 321
Do you work in RGB? You can then use numpy and use even opencv algorithms. Im sure you coul google some "opencv gradients" or better "numpy to gradient".
Just to demonstarate the process, here is some Eval function, where vs array is changed into numpy, opencv making gradients by some built in function and then using some numpy magic to paste that rectangle into original numpy array. Then numpy is going back to vs array.
Code:
import cv2
import numpy as np
import functools
import vshelper
import vapoursynth as vs
from vapoursynth import core
clip = core.ffms2.Source(r'C:/video.mp4')
clip = core.resize.Point(clip, matrix_in_s = '709', format = vs.RGB24)
X1,Y1 = (100,100)
X2,Y2 = (500,500)

def grad(n, clip):
   list_of_arrays = [np.array(clip.get_frame(n).get_read_array(i), copy=False) for i in range(3)]
   np_image = np.dstack(list_of_arrays)
   rectangle = cv2.applyColorMap(np_image, cv2.COLORMAP_JET)[Y1:Y2, X1:X2]
   np_image[Y1:Y2, X1:X2] = rectangle
   out = vshelper.uint8_vsclip(np_image, clip=None)
   out = core.resize.Bilinear(out, format = vs.RGB24)
   return out

clip = core.std.FrameEval(clip, functools.partial(grad, clip=clip))

clip.set_output()
_Al_ is offline   Reply With Quote