欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Opencv3.4.0實(shí)現(xiàn)視頻中的幀保存為圖片功能

 更新時(shí)間:2020年03月20日 17:06:59   作者:Gpwner  
這篇文章主要為大家詳細(xì)介紹了Opencv3.4.0實(shí)現(xiàn)視頻中的幀保存為圖片功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

現(xiàn)在有一個(gè)收集人臉的需求,每一張照片只有一個(gè)人。我的解決辦法是用收集錄制一段視頻,然后上傳到PC上。在PC上使用OpenCV將圖片中的每一幀保存為JPG圖片。

以下是代碼:

import time

import cv2

if __name__ == '__main__':
 # 填寫(xiě)視頻的絕對(duì)路徑
 vidcap = cv2.VideoCapture('/home/shushi/video/獵場(chǎng).mp4')
 success, image = vidcap.read()
 start_time = time.time()
 print(start_time)

 while success:
  end_time = time.time()
  file_name = str(end_time).replace('.', '')
  # 每隔三秒截屏
  if 3 == int(end_time - start_time):
   start_time = end_time
   # 保存JGP 的絕對(duì)路徑
   cv2.imwrite('/home/shushi/video/' + file_name + ".jpg", image) # save frame as JPEG file
  success, image = vidcap.read()
  if cv2.waitKey(10) == 27: # exit if Escape is hit
   break

將視頻放到與Python文件同級(jí)目錄下,然后運(yùn)行程序,你就會(huì)得到視頻幀對(duì)應(yīng)的JPG圖片了:

小編再為大家分享一段代碼:OpenCV按視頻幀進(jìn)行截取,作者是Haku_yyf

#include <opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>
 
 
int main(int argc, char **argv)
 
{
 
 //打開(kāi)視頻文件
 
 cv::VideoCapture cap("E:\\New folder\\DSC_3543.MOV");
 
 if (!cap.isOpened())
 {
 std::cout << "不能打開(kāi)視頻文件" << std::endl;
 return -1;
 }
 
 //從3000ms開(kāi)始播放視頻 
 //cap.set(CV_CAP_PROP_POS_MSEC, 3000);
 //獲取視頻的幀速率
 
 double fps = cap.get(cv::CAP_PROP_FPS);
 double width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
 double height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
 
 //std::cout << fps << std::endl;
 //std::cout << width << std::endl;
 //std::cout << height << std::endl;
 
 
 cv::VideoWriter wrt("C:\\Users\\Administrator\\Desktop\\1.avi", CV_FOURCC('M', 'J', 'P', 'G'), fps, cv::Size(width, height));
 int cout = 0;
 while (true)
 
 {
 
 cv::Mat frame;
 
 //從視頻中讀取一個(gè)幀
 
 bool bSuccess = cap.read(frame);
 ++cout;
 if (!bSuccess)
 
 {
 
 std::cout << "不能從視頻文件讀取幀" << std::endl;
 
 break;
 
 }
 
 //在MyVideo窗口上顯示當(dāng)前幀
 if (cout>=fps*1 && cout<=fps*56)//取視頻1-56秒內(nèi)容
 {
 std::cout << "正在截取..."<<(int)(((cout-fps)/(fps*(56-1)))*100)<<"%" << std::endl;
 wrt << frame;
 }
 
 
 if (cout>fps*57)
 {
 std::cout << "ENd!!!" << std::endl;
 break;
 }
 
 }
 system("pause");
 return 0;
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論