Help us understand the problem. What is going on with this article?

wabカメラからフレームを取得して表示するプログラム(python)

More than 1 year has passed since last update.

概要

PCに接続したwebカメラからフレームを抜いて表示するコードのメモ。余分なものは落として一番シンプルにしたつもり。

実装

とりあえず記述するために適当な名前のファイルを作る。vimは好きではないので、openコマンドで開いて記述していく。

$touch web_camera_code.py
$open web_camera_code.py

中身は以下のように記述

import cv2

cap=cv2.VideoCapture(0)#1台しか接続されていない時は引数0

while(True):
    ret,frame=cap.read()#1フレーム取得

    cv2.imshow('Raw Frame',frame)#画像の表示

    k=cv2.waitKey(1)#キー入力を1秒待つ

    if k==27:#escを押すと閉じる
        break

cap.release()
cv2.destroyAllWindows()

もしimport cv2がないと言われたら

sudo pip3 install opencv-python

とかでインストール。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away