python - 在 OpenCV 中写入几帧视频
问题描述
我有一个将近 60 秒的视频,我想在不同的帧中应用不同的视频处理技术。我正在尝试选择不同的帧,但出现语法错误。这是我到目前为止所写的。
选择不同帧的函数:
def between(cap, lower: int, upper: int):
return lower <= int(cap.get(cv.CAP_PROP_POS_FRAMES)) < upper
在此之后,我想选择不同的框架并应用不同的技术。例如,在下面的前 90 帧中,我转为灰度,从第 91 帧到第 150 帧,我想写一些文本,但是在第二次选择的帧中,我遇到了语法错误。
while cap.isOpened():
ret, frame = cap.read()
if not ret:
print("Can't receive frame (stream end?). Exiting ...")
break
if between(cap, 0, 90):
frame = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
frame = cv.cvtColor(frame, cv.COLOR_GRAY2BGR)
if between(cap, 90, 150)
# Our operations on the frame come here
font = cv.FONT_HERSHEY_SIMPLEX
cv.putText(frame,
'TEXT ON VIDEO',
(50, 50),
font, 1,
(0, 255, 255),
2,
cv.LINE_4)
pass
# write the flipped frame
out.write(frame)
cv.imshow('frame', frame)
if cv.waitKey(1) == ord('q'):
break
cap.release()
out.release()
cv.destroyAllWindows()
关于如何构造我的代码以连续选择下一帧的任何想法。
解决方案
推荐阅读
- laravel - 如何用 Eloquent 实现这个复杂的查询?
- javascript - 在JS中如何将字符串类型的十六进制转换为数字?
- python - bash:-c:第 0 行:从 python-os.system 内部运行 linux cmd 时出现意外标记“换行符”附近的语法错误
- javascript - 在 javascript 中创建特定输入(例如 CT10-0001)的正则表达式
- c# - HttpClientFactory BadRequest?
- python - 如何在其中更改 for 循环?
- c# - 我们可以在 C# 的方法中声明一个属性吗?
- java - 从 java 中的 maven /resource 读取 .json (lib: org.json)
- python - 抓取多个位置的谷歌街景图像
- python - 写入以读写模式打开的文件会改变结构