opencv-python视频处理之白闪效果
程序员文章站
2022-03-07 20:19:25
主要原理就是使用Gamma变换就是指数变换,对图像原来的灰度值进行Gamma次方后得到另一个灰度值,当Gamma小于1大于0时候,灰度值就会趋向低灰度值,这就是曝光...
import cv2
import numpy
def gamma_t(image,gamma):
gamma_ta=[numpy.power(x/255,gamma)*255 for x in range(256)]
gamma_ta=np.round(np.array(gamma_ta)).astype(np.uint8)
return cv2.LUT(image,gamma_ta)
def main_g():
vc = cv2.VideoCapture('sample.mp4')
c = 1
cout = 5 # 帧数
fps = vc.get(cv2.CAP_PROP_FPS)
fourcc = cv2.VideoWriter_fourcc(*'MJPG')
video_writer = cv2.VideoWriter("img_shake.mp4", fourcc, fps, (640, 480))
while vc.isOpened():
rval, frame = vc.read()
# 每5帧抖动一次
if (c % 5 == 0 or 0 < cout < 5):
dst = gamma_t(frame,0.3)
video_writer.write(dst)
else:
# 这里可以控制帧数
cout = 5
cv2.imshow("dst", frame)
video_writer.write(frame)
c = c + 1
cv2.waitKey(1)
vc.release()
利用特效图片
import cv2
import numpy as np
def main_ts() :
img=cv2.imread('sss.jpg')
height,width, n=img. shape
mask=cv2.imread('sss.jpg')#特效图片,
mask=cv2.resize (mask, (width, height) ,interpolation=cv2.INTER_CUBIC)
dst=cv2.addWeighted(img,0.6,mask,0.4,0)
cv2. imshow ("demo", dst)
cv2.waitKey(0)
本文地址:https://blog.csdn.net/weixin_32759777/article/details/107305673
上一篇: 12.7.5 多态案例-制作饮品
下一篇: 160. 相交链表