Opencv3.4.0---將視頻中的幀儲存為圖片

來源:互聯網
上載者:User

現在有一個收集人臉的需求,每一張照片只有一個人。我的解決辦法是用收集錄製一段視頻,然後上傳到PC上。在PC上使用OpenCV將圖片中的每一幀儲存為JPG圖片。

以下是代碼:

import timeimport cv2if __name__ == '__main__':    # 填寫視頻的絕對路徑    vidcap = cv2.VideoCapture('/home/shushi/video/獵場.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  的絕對路徑            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檔案同級目錄下,然後運行程式,你就會得到視訊框架對應的JPG圖片了:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.