简体   繁体   English

如何在视频播放n秒后运行特定代码

[英]How to run specific code after n seconds on a video

I am working on python3 and using Microsoft azure face API function 'CF.face.detect' to detect faces in a video. 我正在使用python3并使用Microsoft天蓝色人脸API函数“ CF.face.detect”来检测视频中的人脸。 I want to detect faces after every 1 second in the video that means run CF.face.detect once/second on video frame. 我想在视频中每隔1秒检测一次脸部,这意味着在视频帧上每秒运行一次CF.face.detect。

Please tell how to do it 请告诉我怎么做

Thanks in advance 提前致谢

If you know how many fps your video has, you could read the frames one by one and detect on every n -th frame, n being the number of fps of a video you're processing. 如果您知道视频有多少fps,则可以一帧一帧地读取并在第n个帧上进行检测, n是您正在处理的视频的fps数。

fps = x
cnt = 0

for f in get_frames():
  if cnt % fps == 0: 
    # run algorithm here
    cv.imwrite(f)

After you have gone through the video then you can run the algorithm. 观看完视频后,您可以运行算法。 But I would suggest to run the algorithm in the loop and save the frame then, preferably with drawn result (squares for detection) 但是我建议在循环中运行算法,然后保存帧,最好是绘制结果(用于检测的正方形)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM