当前位置: 首页 > news >正文

从视频截取每一帧作为图像

查看视频有多少帧

import cv2def count_frames_per_second(video_path):cap = cv2.VideoCapture(video_path)if not cap.isOpened():print("Error: Could not open video")return None# Get frames per secondfps = cap.get(cv2.CAP_PROP_FPS)# Get total number of framestotal_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))# Calculate total time in secondstotal_time_seconds = total_frames / fps if fps > 0 else 0# Convert total time to minutes and seconds for better readabilitytotal_minutes = total_time_seconds // 60total_seconds = total_time_seconds % 60print(f"Frames per second: {fps}")print(f"Total frames in the video: {total_frames}")print(f"Total time of the video: {int(total_minutes)} minutes and {total_seconds:.2f} seconds")cap.release()return fps, total_frames, total_time_seconds# Example usage
video_path = "D:\\WorkSpace\\pitaya_video\\video\\VID_20241015_082527.mp4"  # Change this to your video file path
count_frames_per_second(video_path)

单个视频

import cv2
import osdef capture_frames(video_path,save_frame_path):# Get the video name without extensionvideo_name,suffix_mp4 = os.path.splitext(os.path.basename(video_path))    # Create a directory to save framesframes_dir = os.path.join(save_frame_path, video_name)os.makedirs(frames_dir, exist_ok=True)# Open the video filecap = cv2.VideoCapture(video_path)if not cap.isOpened():print(f"Error: Could not open video file {video_path}")returnframe_count = 0while True:# Read a frame from the videoret, frame = cap.read()# Break the loop if there are no more framesif not ret:break# Save the frame as an image fileframe_filename = os.path.join(frames_dir, f"{video_name}_frame_{frame_count:04d}.jpg")cv2.imwrite(frame_filename, frame)print(f"Saved {frame_filename}")frame_count += 1# Release the video capture objectcap.release()print(f"Total frames saved: {frame_count}")# Example usage
video_file_path = "D:\\WorkSpace\\pitaya_video\\video"  # Replace with your video file path
video_file_path = os.path.join(video_file_path,"VID_20241015_082527.mp4")
save_frame_path = "D:\\WorkSpace\\pitaya_video\\all_image"
capture_frames(video_file_path,save_frame_path)

多个视频

import cv2
import osdef capture_frames_from_videos(video_directory,save_frame_path):# List all video files in the specified directoryvideo_files = [f for f in os.listdir(video_directory) if f.endswith('.mp4')]for video_file in video_files:video_path = os.path.join(video_directory, video_file)print(f"Processing video: {video_path}")# Get the video name without extensionvideo_name, suffix_mp4= os.path.splitext(video_file)# Create a directory to save framesframes_dir = os.path.join(save_frame_path, video_name)os.makedirs(frames_dir, exist_ok=True)# Open the video filecap = cv2.VideoCapture(video_path)if not cap.isOpened():print(f"Error: Could not open video file {video_path}")continueframe_count = 0while True:# Read a frame from the videoret, frame = cap.read()# Break the loop if there are no more framesif not ret:break# Save the frame as an image fileframe_filename = os.path.join(frames_dir, f"{video_name}_frame_{frame_count:04d}.jpg")cv2.imwrite(frame_filename, frame)print(f"Saved {frame_filename}")frame_count += 1# Release the video capture objectcap.release()print(f"Total frames saved for {video_file}: {frame_count}")# Example usage
video_directory = "D:\\WorkSpace\\pitaya_video\\video"  # Replace with your video directory path
save_frame_path = "D:\\WorkSpace\\pitaya_video\\all_image"
capture_frames_from_videos(video_directory,save_frame_path)

一秒截取3帧

import cv2
import osdef capture_frames_from_videos(video_directory, save_frame_path):# List all video files in the specified directoryvideo_files = [f for f in os.listdir(video_directory) if f.endswith('.mp4')]for video_file in video_files:video_path = os.path.join(video_directory, video_file)print(f"Processing video: {video_path}")# Get the video name without extensionvideo_name, _ = os.path.splitext(video_file)# Create a directory to save framesframes_dir = os.path.join(save_frame_path, video_name)os.makedirs(frames_dir, exist_ok=True)# Open the video filecap = cv2.VideoCapture(video_path)if not cap.isOpened():print(f"Error: Could not open video file {video_path}")continue# Get the frames per second (fps) of the videofps = cap.get(cv2.CAP_PROP_FPS)print(f"Frames per second: {fps}")# Calculate the interval to capture 3 frames per secondframe_interval = max(int(fps / 3), 1)  # Ensure at least one frame intervalframe_count = 0saved_frame_count = 0while True:# Read a frame from the videoret, frame = cap.read()# Break the loop if there are no more framesif not ret:break# Save the frame at specific intervalsif frame_count % frame_interval == 0:frame_filename = os.path.join(frames_dir, f"{video_name}_frame_{saved_frame_count:04d}.jpg")cv2.imwrite(frame_filename, frame)print(f"Saved {frame_filename}")saved_frame_count += 1frame_count += 1# Release the video capture objectcap.release()print(f"Total frames saved for {video_file}: {saved_frame_count}")# Example usage
video_directory = "D:\\WorkSpace\\pitaya_video\\video"  # Replace with your video directory path
save_frame_path = "D:\\WorkSpace\\pitaya_video\\all_image"  # Replace with your desired output path
capture_frames_from_videos(video_directory, save_frame_path)

相关文章:

从视频截取每一帧作为图像

查看视频有多少帧 import cv2def count_frames_per_second(video_path):cap cv2.VideoCapture(video_path)if not cap.isOpened():print("Error: Could not open video")return None# Get frames per secondfps cap.get(cv2.CAP_PROP_FPS)# Get total number of f…...

终端 数据表格

// // Created by HongDaYu on 17 十月 2024. //#ifndef HDYSDK_UTIL_H #define HDYSDK_UTIL_H#include <cstdint> #include <string> #include <list> #include <iomanip> #include <memory>class dataGrid { private:std::list<const char*…...

2.4.ReactOS系统运行级别降低IRQL级别KfLowerIrql 函数

2.4.ReactOS系统运行级别降低IRQL级别KfLowerIrql 函数 2.4.ReactOS系统运行级别降低IRQL级别KfLowerIrql 函数 文章目录 2.4.ReactOS系统运行级别降低IRQL级别KfLowerIrql 函数KfLowerIrql 函数 KfLowerIrql 函数 /*******************************************************…...

数字后端实现静态时序分析STA Timing Signoff之min period violation

今天给大家分享一个在高性能数字IC后端实现timing signoff阶段经常遇到的min period violation。大部分时候出现memory min period问题基本上都是需要返工重新生成memory的。这是非常致命的错误&#xff0c;希望大家在做静态时序分析时一定要查看min period violation。 什么是…...

phpstorm+phpstudy 配置xdebug(无需开启浏览器扩展)

今天又被xdebug折磨了&#xff0c;忘记了以前咋配置了现在百度发现好多都是各种浏览器扩展而且也没有真正的用到项目上的都是测试的地址怎么样的 我就简单写一下自己实战吧 不支持workerman swoole hyperf等这种服务框架 如果你会请教教我 工具版本phpstudy8.1.xphpstorm2021.x…...

AI赋能安全运营 | 赛宁网安深度参与四川省网络安全沙龙

为促进四川省、市网络安全公共服务领域的经验交流与深入探讨&#xff0c;打通网络安全供需上下游&#xff0c;加速汇聚省、市优质网络安全设备和服务资源&#xff0c;提升巴中市乃至四川省网络安全防护水平&#xff0c;共同推动四川省网络安全事业的蓬勃发展。 2024年10月15日…...

R语言中,.RData 和 .rds 的区别

.RData 和 .rds 是 R 语言中两种不同的数据保存格式&#xff0c;二者有一些关键的区别&#xff1a; 1. 存储内容的类型&#xff1a; .RData 文件&#xff1a;可以同时保存多个对象&#xff08;如数据框、向量、列表等&#xff09;&#xff0c;当你加载 .RData 文件时&#xf…...

python实现录屏功能

python实现录屏功能 将生成的avi文件转为mp4格式后删掉avi文件 参考感谢&#xff1a;https://www.cnblogs.com/peachh/p/16549254.html import os import cv2 import time import threading import numpy as np from PIL import ImageGrab from pynput import keyboard from da…...

酷克数据出席2024金融业数据库技术大会

10月16日&#xff0c;由中国金融电子化集团指导&#xff0c;北京金融信息化研究所主办的“2024金融业数据库技术大会”在京顺利召开。本次大会以“大模型时代下的数据库创新发展”为主题&#xff0c;汇聚了来自管理部门、金融机构、科技企业以及学术研究机构的众多专家学者&…...

find_library、pkg_check_modules、pkg_search_module的区别

在CMake中&#xff0c;find_library、pkg_check_modules和pkg_search_module是用于查找和使用库的三种不同命令。以下是具体介绍&#xff1a; find_library 功能&#xff1a;find_library用于查找指定的库文件&#xff08;动态库或静态库&#xff09;&#xff0c;不依赖于库提供…...

多jdk版本环境下,jenkins系统设置需指定JAVA_HOME环境变量

一、背景 由于不同项目对jdk版本的要求不同&#xff0c;有些是要求jdk11&#xff0c;有些只需要jdk8即可。 而linux机器上安装jdk的方式又多种多样&#xff0c;最后导致jenkins打包到底使用的是哪个jdk&#xff0c;比较混乱。 1、java在哪 > whereis java java: /usr/bin/…...

Java mybatis day1015

ok了家人们&#xff0c;今天学习了mybatis这个框架&#xff0c;我们一起去看看吧 一.Mybatis简介 1.1 Mybatis概述 MyBatis 最初是 Apache 的一个开源项目 iBatis, 2010 年 6 月 这个项目由 Apache Software Foundation 迁移到了 Google Code 。随着开发团队转投 Google Cod…...

音乐播放器项目专栏介绍​

1.简介 本专栏使用Qt QWidget作为显示界面&#xff0c;你将会学习到以下内容&#xff1a; 1.大量ui美化的实例。 2.各种复杂ui布局。 3.常见显示效果实现。 4.大量QSS实例。 5.Qt音频播放&#xff0c;音乐歌词文件加载&#xff0c;展示。 6.播放器界面换肤。 相信学习了本专栏…...

如何修改SpringBoot内置容器默认上下文

引言 默认情况下&#xff0c;Spring boot 应用程序通过上下文路径“/”访问&#xff0c;这是嵌入式服务器的默认设置&#xff0c;即我们可以直接通过http://localhost:8080/访问该应用程序。 但是在生产环境中部署 Spring Boot 应用程序时&#xff0c;指定上下文路径是一个常…...

R语言详解predict函数

R语言中predict函数在建立模型&#xff0c;研究关系时常用。但是不同type得到的结果常常被混为一谈&#xff0c;接下来&#xff0c;探讨predict得到的不同结果。 #数据 set.seed(123) n<-1000 age<-rnorm(n,mean50,sd10) gender<-rbinom(n,1,0.5) disease<-rbinom…...

QT 实现随机码验证

1.界面实现效果 以下是具体的项目需要用到的效果展示&#xff0c;用于验证字母。 2.简介 自定义CaptchaMovableLabel&#xff0c;继承自QLabel类&#xff1a; 中间的4个字母&#xff0c;就是CaptchaMovableLabel类来实例化的对象。 主要功能如下&#xff1a; 1.显示字母&am…...

集合框架12:Set集合概述、Set接口使用

视频链接&#xff1a;13.24 Set接口使用_哔哩哔哩_bilibilihttps://www.bilibili.com/video/BV1zD4y1Q7Fw?spm_id_from333.788.videopod.episodes&vd_sourceb5775c3a4ea16a5306db9c7c1c1486b5&p24 1、Set集合概述 特点&#xff1a;无序、无下标&#xff0c;元素不可…...

如何打开荣耀手机的调试模式?

问题描述&#xff1a; 最近用荣耀手机进行测试&#xff0c;打开开发者选项&#xff0c;打开USB调试&#xff0c;在选择USB配置时&#xff0c;发现仅有选择USB以太网才可以连接Android Studio&#xff0c;也就是打开ADB调试模式。 但是&#xff0c;打开USB以太网后&#xff0c…...

Meta新模型Dualformer:融合快慢思维,推理能力媲美人脑

Meta 的 FAIR 团队最近推出了一款名为 Dualformer 的全新 Transformer 模型&#xff0c;该模型模仿人类的双重认知系统&#xff0c;能够无缝整合快速和慢速推理模式&#xff0c;在推理能力和计算效率上取得了显著突破。 人类的思维过程通常被认为是由两种系统控制的:系统1快速…...

CDGA|数据治理:如何让传统行业实现数据智能

在当今这个数字化时代&#xff0c;数据已成为推动各行各业转型升级的关键力量。对于传统行业而言&#xff0c;如何从海量、复杂的数据中挖掘价值&#xff0c;实现“数据智能”&#xff0c;成为了提升竞争力、优化运营效率、创新业务模式的重要途径。本文将探讨数据治理如何助力…...

Phi-4-mini-reasoning真实作品:微分方程求解+物理意义解释双模态输出

Phi-4-mini-reasoning真实作品&#xff1a;微分方程求解物理意义解释双模态输出 1. 模型简介 Phi-4-mini-reasoning是一个基于合成数据构建的轻量级开源模型&#xff0c;专注于高质量、密集推理的数据处理能力。作为Phi-4模型家族的一员&#xff0c;它经过专门微调以提升数学…...

LaTeX公式一键转换Word:学术写作的效率革命

LaTeX公式一键转换Word&#xff1a;学术写作的效率革命 【免费下载链接】LaTeX2Word-Equation Copy LaTeX Equations as Word Equations, a Chrome Extension 项目地址: https://gitcode.com/gh_mirrors/la/LaTeX2Word-Equation 作为一名研究生&#xff0c;你是否曾经为…...

学术公式迁移困境:从3小时到45秒的转换革命——LaTeX2Word-Equation技术解析

学术公式迁移困境&#xff1a;从3小时到45秒的转换革命——LaTeX2Word-Equation技术解析 【免费下载链接】LaTeX2Word-Equation Copy LaTeX Equations as Word Equations, a Chrome Extension 项目地址: https://gitcode.com/gh_mirrors/la/LaTeX2Word-Equation 问题溯源…...

网络安全学习(面试题)

1、jeecg框架有哪些漏洞&#xff0c; 弱口令漏洞&#xff0c;admin/123456&#xff0c;jeecg/123456&#xff0c;jeecg/jeecg123 信息泄露&#xff0c;接口任意用户密码重置&#xff0c;sql注入等历史漏洞&#xff0c;用工具一键梭哈 找了好久&#xff0c;一直都没找到学校关于…...

实战演练:将idea ai插件的灵感在快马平台转化为可部署的全栈博客管理系统

今天想和大家分享一个实战经验&#xff1a;如何把IDEA AI插件产生的灵感快速转化为一个可部署的全栈博客管理系统。整个过程在InsCode(快马)平台上完成&#xff0c;从构思到上线只用了不到一小时&#xff0c;特别适合想要快速验证想法的开发者。 从IDEA插件到完整项目 平时用…...

Kandinsky-5.0-I2V-Lite-5s应用场景:游戏NPC立绘动态化+过场动画快速生成

Kandinsky-5.0-I2V-Lite-5s应用场景&#xff1a;游戏NPC立绘动态化过场动画快速生成 1. 游戏开发中的视觉挑战 在游戏开发过程中&#xff0c;NPC立绘动态化和过场动画制作一直是两个耗时费力的环节。传统方法需要美术团队逐帧绘制动画&#xff0c;或者使用复杂的3D建模工具&a…...

YOLOv8鹰眼快速入门:三步完成图像上传、检测与结果查看

YOLOv8鹰眼快速入门&#xff1a;三步完成图像上传、检测与结果查看 1. 引言&#xff1a;为什么选择YOLOv8鹰眼目标检测 在计算机视觉领域&#xff0c;目标检测技术正变得越来越重要。无论是安防监控、自动驾驶还是工业质检&#xff0c;快速准确地识别图像中的物体都是核心需求…...

H-第一周

文章目录计算机基础和Linux安装linux基础命令实践Linux基础与文件系统基础目录结构文件链接计算机基础和Linux安装 ubuntu-24.04-server安装官方镜像下载地址&#xff1a;https://cn.ubuntu.com/download/server/thank-you?version24.04.3&architectureamd64 创建虚拟机 …...

OpenClaw+Phi-3-vision-128k-instruct:个人知识库自动化建设方案

OpenClawPhi-3-vision-128k-instruct&#xff1a;个人知识库自动化建设方案 1. 为什么需要自动化知识管理 作为一个长期与技术文档打交道的开发者&#xff0c;我发现自己陷入了一个典型的知识管理困境&#xff1a;每天接触大量优质内容——技术博客、论文PDF、会议视频、截图…...

解密OpenHarmony设备安全认证:从SPEKE密钥交换到四级证书链的完整流程解析

OpenHarmony设备安全认证体系深度解析&#xff1a;从密钥交换到证书链验证 1. 安全认证架构设计理念 OpenHarmony作为面向全场景的分布式操作系统&#xff0c;其安全认证体系采用分层防御策略&#xff0c;构建了覆盖设备发现、身份认证、数据传输全生命周期的安全防护机制。这套…...