当前位置:网站首页>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
边栏推荐
- php+mysql對下拉框搜索的內容修改
- Domestic lightweight Kanban scrum agile project management tool
- L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
- ROP Emporium x86_64 7~8题
- Codeforces round 784 (Div. 4) (a - H)
- Store consumption SMS notification template
- Linux redis - redis ha sentinel cluster construction details & redis master-slave deployment
- MySQL insert free column
- Servlet template engine usage example
- Day 4 of learning rhcsa
猜你喜欢

The way to conquer C language

工业互联网+危化安全生产综合管理平台怎样建

Sonic cloud real machine tutorial

Servlet template engine usage example

Store consumption SMS notification template

Encapsulation of ele table

Machine learning (Zhou Zhihua) Chapter 14 probability graph model

php+mysql对下拉框搜索的内容修改

Flink stream processing engine system learning (I)

Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
随机推荐
Classification and regression tree of machine learning
First day of rhcsa
Chapter IV project cost management of information system project manager summary
Windows MySQL 8 zip installation
Winsock programming interface experiment: Ping
JVM runtime data area (I)
Processes and threads
C language 171 Number of recent palindromes
Interim summary (Introduction + application layer + transportation layer)
Centos7 install MySQL 8 0
Machine learning (Zhou Zhihua) Chapter 14 probability graph model
Store consumption SMS notification template
Decision tree principle of machine learning
MySQL function syntax
Configuring Apache Web services for servers such as Tianyi cloud
The problem of removing spaces from strings
Intelligent agricultural management model
Kubernetes study notes
Rhcsa second day operation
国产轻量级看板式Scrum敏捷项目管理工具