opencv 对视频的操作

//VideoCapture类:可以是从文件中读取同样也可以是从摄像头里获得
videoCapture cap("  ");
cap>>frame; //获得视频中的帧
cap.get(int propid);
cap.set(int propid,double value);
propid:  cv::CAP_PROP_POS_MSEC    0  Current position in video file(milliseconds)or video 
                                     capture timestamp
         cv::CAP_PROP_POS_FRAMES  1  Zero-based index of next frame
         
         cv::CAP_PROP_POS_AVI_RATIO  2 Relative position in the video(range is 0 to 1
        
         cv::CAP_PROP_FRAME_WIDTH 3  Width of frames in the video

         cv::CAP_PROP_FRAME_HEIGHT 4 Height of frames in the video

         cv::CAP_PROP_FPS         5   Frame rate at which the video was recorded

         cv::CAP_PROP_FOURCC      6   Four character code indicating codec

         cv::CAP_PROP_FRAME_COUNT 7   Total number of frames in a video file

         cv::CAP_PROP_FORMAT      8   Format if the Mat objects retured(e.g.,CV_8UC3)

         cv::CAP_PROP_MODE        9   Indicates capture mode;values are specific to video
                                      backend being used(e.g.,DC 1394)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenCV 是一个用于计算机视觉的开源库,它提供了各种图像和视频处理功能。以下是 OpenCV 中的一些常见视频操作: 1. 读取视频:可以使用 VideoCapture 类从本地文件或网络摄像头读取视频流。 ``` import cv2 video = cv2.VideoCapture('video.mp4') # 或者设备索引如 0 while video.isOpened(): ret, frame = video.read() if not ret: break # 处理帧 ... video.release() cv2.destroyAllWindows() ``` 2. 显示视频:可以使用 imshow() 方法显示视频帧。 ``` cv2.imshow('Video', frame) cv2.waitKey(1) ``` 3. 保存视频:可以使用 VideoWriter 类将处理后的帧保存为视频文件。 ``` fourcc = cv2.VideoWriter_fourcc(*'XVID') writer = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480)) while video.isOpened(): ret, frame = video.read() if not ret: break # 处理帧 ... writer.write(frame) ``` 4. 视频分割:可以使用 split() 将视频分割成单个帧。 ``` frames = [] while video.isOpened(): ret, frame = video.read() if not ret: break frames.append(frame) # 对单个帧进行处理 for frame in frames: # 处理帧 ... ``` 5. 视频合成:可以使用 merge() 将处理后的帧合成为视频。 ``` fourcc = cv2.VideoWriter_fourcc(*'XVID') writer = cv2.VideoWriter('output.avi', fourcc, 20.0, (640, 480)) for frame_processed in frames_processed: # 对单个帧进行处理 writer.write(frame_processed) ``` 这些是 OpenCV 中的一些常见视频操作,您可以使用它们来实现各种视频处理功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值