当前位置:网站首页>Opencv reads webcam video and saves it locally
Opencv reads webcam video and saves it locally
2022-04-23 02:54:00 【1900_】
The code and comments are as follows :
import cv2
import time
# Acquisition time
def get_time():
it = time.strftime("%Y%m%d%H%M%S", time.localtime()) # Time without separator Can be used as file name
ft = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) # Time format
return [it, ft]
stream = "rtsp://username:password@ip_address/ch1/main/av_stream" # Hikvision camera address User name, password
video_path = '' # Video storage address
cap = cv2.VideoCapture(stream) # Read in video
# Get high wide Frame rate
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = max(cap.get(cv2.CAP_PROP_FPS) % 100, 0) or 25.0
if cap.isOpened() == False or w == 0 or h == 0:
print("connect failed")
frame_count = 0 # Record the number of frames
temp_path = video_path + get_time()[0] + ".mp4" # Save the path ( Spell time as the file name )
# Writing videos
vid_writer = cv2.VideoWriter(temp_path, cv2.VideoWriter_fourcc(*'mp4v'), fps, (w, h))
while True:
cap.grab() # Get the next frame
success, im = cap.retrieve() # decode
if success:
frame_count += 1 # Frame number plus 1
vid_writer.write(im) # Save video
if frame_count > 7500: # Set a time How often do you keep
vid_writer.release() # Save to local
frame_count = 0 # Zero clearing
break
# cv2.imshow("camera", img)
# cv2.waitKey(1)
cap.release() # Release resources
版权声明
本文为[1900_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220658376288.html
边栏推荐
- 【工欲善其事必先利其器】论文编辑及文献管理(Endnote,Latex,JabRef ,overleaf)资源下载及使用指南
- Machine learning (Zhou Zhihua) Chapter 14 probability graph model
- JS learning notes
- Résumé du gestionnaire de projet du système d'information Chapitre VI gestion des ressources humaines du projet
- Android high-level interview must ask: overall business and project architecture design and reconstruction
- Les derniers noeuds K de la liste jz22
- The shell monitors the depth of the IBM MQ queue and scans it three times in 10s. When the depth value exceeds 5 for more than two times, the queue name and depth value are output.
- Shell script learning notes -- shell operation on files sed
- Winsock programming interface experiment: implementation of ipconfig
- L2-006 树的遍历(中后序确定二叉树&层序遍历)
猜你喜欢
Practical combat of industrial defect detection project (II) -- steel surface defect detection based on deep learning framework yolov5
Linux Redis——Redis 数据库缓存服务
解决win7 中powershell挖矿占用CPU100%
Encapsulation of ele table
Servlet template engine usage example
Shell script learning notes - regular expressions
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
Domestic lightweight Kanban scrum agile project management tool
Fashion MNIST dataset classification training
The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
随机推荐
Interpretation of the future development of smart agriculture
MySQL function syntax
C language 171 Number of recent palindromes
Modification du contenu de la recherche dans la boîte déroulante par PHP + MySQL
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
The problem of removing spaces from strings
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
L2-006 树的遍历(中后序确定二叉树&层序遍历)
The input of El input input box is invalid, and error in data(): "referenceerror: El is not defined“
MySQL复杂查询使用临时表/with as(类似表变量)
Implementation of distributed scenario business operation log (based on redis lightweight)
学习正则表达式选项、断言
Encapsulate components such as pull-down menu based on ele
Traversée de l'arbre L2 - 006
JZ35 复杂链表的复制
Kubernetes study notes
Kubernetes - Introduction to actual combat
第46届ICPC亚洲区域赛(昆明) B Blocks(容斥+子集和DP+期望DP)
Difference between relative path and absolute path (often asked in interview)
JZ35 replication of complex linked list