LoginSignup
7
8

More than 3 years have passed since last update.

Jetson Nano に Raspberry Pi用 カメラをつけて写真を撮ってみる

Last updated at Posted at 2019-04-29

TL;DR

Jetson Nanoにラズパイのカメラをつけて、動画(写真)が撮れることを確認します

事前準備

Jetson NanoにOpenCVを入れます。

入れ方はいろいろありますが、私の方法だとこちら

Jetson Nanoにカメラを取り付けます

私はこちらを参考にしました。同じカメラを買って取り付けています

写真を撮ってみる

スクリプトの中身

環境はpython3です

camera-to-img.py

import os
import cv2

GST_STR = 'nvarguscamerasrc \
        ! video/x-raw(memory:NVMM), width=3280, height=2464, format=(string)NV12, framerate=(fraction)30/1 \
        ! nvvidconv ! video/x-raw, width=(int)1920, height=(int)1080, format=(string)BGRx \
        ! videoconvert \
        ! appsink'

dir_path = 'images'
base_path = 'images/pic'
ext = 'jpg'

def main():
    cap = cv2.VideoCapture(GST_STR, cv2.CAP_GSTREAMER)

    os.makedirs(dir_path, exist_ok=True)

    n = 0
    while True:
        ret, frame = cap.read()
        cv2.imwrite('{}_{}.{}'.format(base_path, n, ext), frame)
        n += 1

if __name__ == "__main__":
    main()

スクリプトの実行


python3 camera-to-img.py

GST_ARGUS: Creating output stream
CONSUMER: Waiting until producer is connected...
GST_ARGUS: Available Sensor modes :
GST_ARGUS: 3280 x 2464 FR = 21.000000 fps Duration = 47619048 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 3280 x 1848 FR = 28.000001 fps Duration = 35714284 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1920 x 1080 FR = 29.999999 fps Duration = 33333334 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 59.999999 fps Duration = 16666667 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: 1280 x 720 FR = 120.000005 fps Duration = 8333333 ; Analog Gain range min 1.000000, max 10.625000; Exposure Range min 13000, max 683709000;

GST_ARGUS: Running with following settings:
   Camera index = 0 
   Camera mode  = 0 
   Output Stream W = 3280 H = 2464 
   seconds to Run    = 0 
   Frame Rate = 21.000000 
GST_ARGUS: PowerService: requested_clock_Hz=53037600
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.

10秒後くらいに Ctrl + C でスクリプトを止めて、カレントディレクトリにできた「images」ディレクトリの中にjpegファイルがたくさんできていると思います。


ls
pic_0.jpg   pic_13.jpg  pic_17.jpg  pic_20.jpg  pic_24.jpg  pic_28.jpg  pic_31.jpg  pic_35.jpg  pic_3.jpg  pic_7.jpg
pic_10.jpg  pic_14.jpg  pic_18.jpg  pic_21.jpg  pic_25.jpg  pic_29.jpg  pic_32.jpg  pic_36.jpg  pic_4.jpg  pic_8.jpg
pic_11.jpg  pic_15.jpg  pic_19.jpg  pic_22.jpg  pic_26.jpg  pic_2.jpg   pic_33.jpg  pic_37.jpg  pic_5.jpg  pic_9.jpg
pic_12.jpg  pic_16.jpg  pic_1.jpg   pic_23.jpg  pic_27.jpg  pic_30.jpg  pic_34.jpg  pic_38.jpg  pic_6.jpg

そのうち一枚を見てみると、こんな感じで写真が撮れていることが分かります。
変なアングルですいません
image.png

トラブルシューティング

こんな感じで video としてカメラは登録されているのですが、

v4l2-ctl -d /dev/video0 --list-formats
ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'RG10'
        Name        : 10-bit Bayer RGRG/GBGB

opencvのサンプルスクリプトでよく見られる

cv2.VideoCapture(0)

とやってもカメラに接続することができず、スクリプトのようにすることでopencvからようやくカメラに接続できました。

7
8
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
7
8