1. 程式人生 > >Python3 + OpenCV 3.3讀取攝像頭,儲存視訊檔案

Python3 + OpenCV 3.3讀取攝像頭,儲存視訊檔案

import cv2
##開啟攝像頭
cap = cv2.VideoCapture(0)

##視訊大小設定,獲取幀寬度,獲取幀高度
sz = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)))

fps = 20
# 輸出格式
# fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
# fourcc = cv2.VideoWriter_fourcc('m','p','e','g')
# fourcc = cv2.VideoWriter_fourcc(*'mpeg') ##open and set props vout = cv2.VideoWriter() vout.open('output.mp4',fourcc,fps,sz,True) cnt = 0 while cnt<20: cnt += 1 print(cnt) _, frame = cap.read() ##putText輸出到視訊上,各引數依次是:照片/新增的文字/左上角座標/字型/字型大小/顏色/字型粗細 cv2.putText(frame,str(cnt),(10,20),cv2.FONT_HERSHEY_PLAIN,
1,(0,255,0),1,cv2.LINE_AA) vout.write(frame) vout.release() cap.release()

相關推薦

Python3 + OpenCV 3.3讀取攝像頭儲存視訊檔案

import cv2 ##開啟攝像頭 cap = cv2.VideoCapture(0) ##視訊大小設定,獲取幀寬度,獲取幀高度 sz = (int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),int(cap.get(cv2.CAP_PROP_F

Opencv+Python3在WIN10環境下呼叫電腦攝像頭儲存視訊

測試環境:win10 Python-3.7.1 opencv-3.4.2 話不多說,直接上程式碼: # 匯入opencv和numpy的庫檔案 import cv2 import numpy as np # VideoCapture()用來捕獲視訊裝置的ID,device = 0表示只有一個

樹莓派3使用CSI攝像頭遠端連線

樹莓派3中安裝VLC程式:sudo apt-get -y install vlc 然後寫入配置等引數:raspivid -o - -t 0 -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standa

opencv 讀取攝像頭儲存

m_capture = 0; m_writer = 0; m_frame = 0; m_capture = cvCaptureFromCAM(0/*m_CamIndex*/); int count = 0; m_frame = cvQueryFrame( m_c

OpenCV視頻讀取播放視頻轉換為圖片

character capture clas 等待 del only _for lis ostream 轉載請註明出處!!!http://blog.csdn.net/zhonghuan1992 OpenCV視頻讀取播放,視頻轉換為圖片

opencv-python如何調取攝像頭並實現按鍵終止

開學來的第一篇部落格,由於作者剛開始學習這個所以可能有什麼不對的地方請大家幫忙指正哈。 今天主要是給大家講一下最基本的呼叫攝像頭的操作,首先呢我們先了解OpenCV的cv2.VideoCapture(i)函式。 i代表攝像頭的數字,當有不止一個攝像頭的時候就會需要標明攝像

Python3使用csv模組csv.writer().writerow()儲存csv檔案產生空行的問題

問題:csv.writer().writerow()儲存的csv檔案,開啟時每行後都多一行空行 一開始的程式碼如下: def write_csv_file(path, head, data):     try:         with open(path, 'w')

opencv 影象的讀取顯示和儲存

opencv影象處理系統組成(個人見解) 影象獲取:本地載入圖片(jpg,bmp,png) : 相機獲取影象Frame Byte : 視訊獲取資料 :建立影象Cre

opencv中批量讀取圖片並儲存

在生成訓練集的時通常需要對資料夾中圖片進行批處理,本文簡要介紹影象批量讀取、處理、儲存的方法。 方法一: 1.生成圖片描述檔案     對於有多幅影象的資料夾,首先生成txt檔案,儲存圖片路徑。    在DOS模式下匯入資料夾路徑並生成TXT檔案: 2.通過TXT批

MATLAB讀取攝像頭InstalledAdaptors為空

剛開始使用matlab讀取USB攝像頭時遇到問題 輸入 info = imaqhwinfo 得到: WARNING: No Image Acquisition adaptors found. Image acquisition adaptors may b

用goquery從國家統計局拉取最新省市區3級行政區劃程式碼生成SQL檔案匯入資料庫

想找一份最新的省市區三級聯動的資料,網上的怕不夠新,不夠準確 正好用go從國家統計局官方網站爬一份,生成sql檔案,然後匯入資料庫 資料庫表結構 DROP TABLE IF EXISTS `3goals_area`; CREATE TABLE `3go

opencv 讀取視訊、開啟攝像頭、寫入視訊檔案

1、開啟視訊檔案 #include "opencv2/core/core.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2/i

用Python下載視訊儲存檔案的demo

def download_video(url): try: print('準備下載視訊:'+url) response=requests.get(url,headers=headers) data=response.content

利用python實現自動捕獲程序netstat資訊和自動捕獲telnet資訊儲存log檔案

#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ AUTH: [email protected] tag: telnet ,then execute all of the API,and capture the p

iOS 錄視訊相簿選擇視訊視訊壓縮儲存本地檔案播放上傳

iOS 錄視訊,相簿選擇視訊,視訊壓縮,儲存本地檔案,播放,上傳 工程中用到了這部分的功能,也糾結了幾天後做完了,現在總結下這部分的東西。 先說描述下需求: (1)從相簿取視訊、錄視訊; (2)視訊轉碼為mp4; (3)儲存在檔案中,覆蓋更新後也能讀取視訊 (4)視訊的

用python呼叫呼叫攝像頭儲存視訊

今天需要寫一段程式碼,呼叫攝像頭並儲存視訊。首先是說一下環境配置Below Python packages are to be downloaded and installed to their default locations.1.2. Numpy.1.3. Matplo

phpExcel 讀取資料大資料檔案處理方案

/** * 讀取 Excel 檔案 * @param string $filePath 要讀取的路徑 * @param integer $sheet 要讀取的工作列表 * @return array

從資料庫中讀取資料建立XML檔案並更新維護XML

public class OperateXML { /// <summary> /// 檔案全路徑 /// </summary> private string fullF

.net讀取影象並儲存檔案

{            byte[] mBlob = (byte[])reader["影象"];            System.IO.MemoryStream ms =new System.IO.MemoryStream(mBlob);            System.Drawing.Image 

opencv攝像頭讀寫視訊檔案

opencv從攝像頭讀視訊檔案,並且寫入到本地目錄 程式碼如下: #include "cv.h" #include "highgui.h" int main() { CvCapture *capture = cvCaptureFromCAM