当前位置:网站首页>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
边栏推荐
- Linux Redis ——Redis HA Sentinel 集群搭建详解 & Redis主从部署
- The express project changes the jade template to art template
- Flink stream processing engine system learning (III)
- grain rain
- 工业互联网+危化安全生产综合管理平台怎样建
- Close the computer port
- Basic workflow of CPU
- How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year
- Gavl021, gavl281, AC220V to 5v200ma small volume non isolated chip scheme
- Those years can not do math problems, using pyhon only takes 1 minute?
猜你喜欢

Intelligent agricultural management model

Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow

基于Scrum进行创新和管理

Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl

Encapsulation of ele table
![[unity3d] rolling barrage effect in live broadcasting room](/img/61/46a7d6c4bf887fca8f088e7673cf2f.png)
[unity3d] rolling barrage effect in live broadcasting room

JVM runtime data area (I)

Store consumption SMS notification template

Flink stream processing engine system learning (I)

First knowledge of C language ~ branch statements
随机推荐
Chapter VII project communication management of information system project manager summary
Efficient music format conversion tool Music Converter Pro
Winsock programming interface experiment: Ping
Shell script learning -- practical case
C语言 171. 最近回文数
重大危险源企业如何保障年底前完成双预防机制数字化建设任务
L2-006 樹的遍曆(中後序確定二叉樹&層序遍曆)
MySQL function syntax
Implementation of distributed scenario business operation log (based on redis lightweight)
Linux redis - redis database caching service
OCR recognition PDF file
php+mysql对下拉框搜索的内容修改
Navicat failed to connect to Oracle Database: cannot load OCI DLL, 87: instant client package is
MySQL复杂查询使用临时表/with as(类似表变量)
OCR识别PDF文件
Kubernetes study notes
Navicat premium import SQL file
Huawei machine test question -- deformation of hj53 Yang Hui triangle
JZ76 删除链表中重复的结点
How big the program development of single chip microcomputer project can be, it represents your level of knocking code