Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
13
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

Raspberry Pi で、Web カメラを使う

コマンドで使う場合
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
Why not register and get more from Qiita?
  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
13
Help us understand the problem. What are the problem?