LoginSignup
6
13

More than 3 years have passed since last update.

Raspberry Pi で、Web カメラを使う

Last updated at Posted at 2017-06-06

コマンドで使う場合
fswebcam をインストールします。

sudo apt install fswebcam

画像のキャプチャー

sudo chmod 666 /dev/video0
fswebcam photo.jpg

Python で使う場合
opencv をインストールします。

sudo apt install libopencv-dev
sudo apt install python3-opencv

実行プログラム

usb_camera.py
#! /usr/bin/python3
# -*- coding: utf-8 -*-
#
#   usb_camera.py
#
#                       Oct/17/2020
# --------------------------------------------------------------------
import sys
import cv2
#
sys.stderr.write("*** 開始 ***\n")
#
cc = cv2.VideoCapture(0)
#
rr, img = cc.read()
cv2.imwrite('photo.jpg', img)
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

次の環境で確認しました。

$ uname -a
Linux violet 5.4.51-v7l+ #1333 SMP Mon Aug 10 16:51:40 BST 2020 armv7l GNU/Linux
$ python3 --version
Python 3.7.3
6
13
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
13