Youtubeでも活動中

チャンネル登録してくれたら喜びます。
リンクはフリーです。共有・拡散は大歓迎!

このボタンで簡単にチャンネル登録!
PR

RaspberryPIでカメラ動作チェックしようとしてエラー19が出る。【OS:Bullseye】

raspberrypi-bullseye-camera-failed-eyecatch

前回までの記事で、RaspberryPiの最新OSであるBullseyeを
使用した場合のカメラの接続について解説しました。

ひとつ前のBusterからの変更でひと手間必要であることが
わかってもらえたと思います。
とにかく情報が少ない…
というか、Busterまでの内容の解説しか
インターネットにも書籍にもないので探すのが大変です。

この内容も少ない情報から探してきた内容です。
具体的には、カメラの動作を確認するための
libcamera-hello
というテスト用のレビュー機能が動作しなかったんです。

具体的には、こんな感じのエラーが表示されていました。

terminate called after throwing an instance of 'std::runtime_error'
  what():  failed to import fd 19

どこを見ても、libcamera-helloと打つと
一時的にカメラの画像がレビューできますよ。

としか書いていないんです。
でもたしかにわたしのRaspberryPiはエラーを吐き出す…

というわけで対策方法について解説します。

この記事を読むことでわかること

自己紹介

サラリーマンしてます。

主に工場(生産現場)で使用する検査装置のアプリケーション開発してます。

ヒトの作業を自動化して簡略化するアプリケーションを日々開発中。

2022年5月に転職。現役バリバリの技術者です。
現在は超大手企業の新規事業分野で装置の研究・開発をしています。

Youtubeチャンネルにさまざまな動画を上げています

↓↓↓こちらからYoutubeチャンネルにアクセス!! ↓↓↓

注意

本ブログはアフィリエイトを用いた広告を掲載しています。

PR

まずはカメラがRaspberryPiで認識できていることが最低条件。

とにもかくにも、Bullseyeの状態でカメラが認識できていること、
それから、試しに撮影(レビュー無しで)してみて
写真が撮れていることが最低条件です。

試しにレビュー無しで撮影するところまでは、
以前の記事で詳しく解説していますので、
まだ読んでいない場合は、まずはこちら↓から読んでください。

以前書いた記事。これができていることが最低条件。

どんなことをしてどんなエラーがRaspberryPiで起きるか?

さて、具体的にエラーが発生する条件について説明していきましょう。
このエラーが出る再現性の高い要因について解説しましょう。

実行環境について説明する。

まず、RaspberryPi周りの環境についてです。
実行していた環境はこちら↓↓↓

  • RaspberryPi3B+
  • bullseye_5.15.89-v(32bit)
  • カメラのイメージャーは、Omnivision製の5647

この状況で、かつ、bullseye用の設定を
先ほど紹介した記事の通り実行しています。

この状態で何をしたらどんなエラーがでるか?

さて、この実行環境で、
次のコマンドを打ちます。

libcamera-hello

libcameraで用意されている、
カメラ版hello,worldですね。

このコマンドの挙動ですが、
実行されると5秒間カメラの映像がプレビュー画面に出ます。
ただし、私の場合は出なかった…
代わりにエラーが出ました笑

一瞬だけプレビュー用のウィンドウが表示されるのですが、すぐに閉じてエラーが表示されます。

エラーの内容は、こちら↓↓

terminate called after throwing an instance of 'std::runtime_error'
  what():  failed to import fd 19

とりあえずエラーなのはわかりますが、
runtime_errorなので具体的にどうすればいいのかいまいちわかりません。

ただ、一つわかっていたのは、
【プレビュー画面を出さなければエラーが出ずに
ちゃんと写真が撮れる】ということ。

先ほど紹介した記事の最後のほうに、
うまくいくコマンドを紹介していました。
今一度書いておきます。

libcamera-jpeg -n -o test.jpg

通常、-nというのはつけません。
これは、プレビュー画面を出さないオプションです。
つまり、プレビュー画面を出さなければ、
うまく動作するということです。

….結局これだけだと意味わからないですよね。

似たような現象が起きていた方がいたので、
こちらで紹介させていただきます。

【対策方法】こうすればエラーが出ない。

プレビューを出さなければエラー19が出ない。
そこまではわかりましたが、プレビュー画面見たいですよね??

わたしはどうしても見たかったので、
エラーの原因・対策についてまた調べたわけです。

結論から言うと、結構対策は簡単でした。

具体的な対策方法

具体的には、オプションの追加です。
先ほど、-nがプレビュー画面を表示させないオプションとして
登場しましたが、それとは別のオプションです。

それが、

--qt-preview

これです。

これ先ほどのlibcameraのコマンドに足します。
具体的には↓↓

libcamera-hello --qt-preview

これでわたしは解決しました。
この内容は、ここのフォーラムに情報が書いてありました。

libcamera apps on Bullseye running on Pi 0 – 3

libcameraの他の機能を使って遊んでみる。

ここまで出来たら後は、libcameraの機能を使って
存分に遊ぶことができます。

libcameraのコマンドのオプションの一覧を載せておきます。

  -h [ --help ] [=arg(=1)] (=0)         Print this help message
  --version [=arg(=1)] (=0)             Displays the build version number
  --list-cameras [=arg(=1)] (=0)        Lists the available cameras attached to the system.
  --camera arg (=0)                     Chooses the camera to use. To list the available indexes, use the 
                                        --list-cameras option.
  -v [ --verbose ] [=arg(=2)] (=1)      Set verbosity level. Level 0 is no output, 1 is default, 2 is verbose.
  -c [ --config ] [=arg(=config.txt)]   Read the options from a file. If no filename is specified, default to 
                                        config.txt. In case of duplicate options, the ones provided on the command line
                                        will be used. Note that the config file must only contain the long form 
                                        options.
  --info-text arg (=#%frame (%fps fps) exp %exp ag %ag dg %dg)
                                        Sets the information string on the titlebar. Available values:
                                        %frame (frame number)
                                        %fps (framerate)
                                        %exp (shutter speed)
                                        %ag (analogue gain)
                                        %dg (digital gain)
                                        %rg (red colour gain)
                                        %bg (blue colour gain)
                                        %focus (focus FoM value)
                                        %aelock (AE locked status)
                                        %lp (lens position, if known)
                                        %afstate (AF state, if supported)
  --width arg (=0)                      Set the output image width (0 = use default value)
  --height arg (=0)                     Set the output image height (0 = use default value)
  -t [ --timeout ] arg (=5000)          Time (in ms) for which program runs
  -o [ --output ] arg                   Set the output file name
  --post-process-file arg               Set the file name for configuring the post-processing
  --rawfull [=arg(=1)] (=0)             Force use of full resolution raw frames
  -n [ --nopreview ] [=arg(=1)] (=0)    Do not show a preview window
  -p [ --preview ] arg (=0,0,0,0)       Set the preview window dimensions, given as x,y,width,height e.g. 0,0,640,480
  -f [ --fullscreen ] [=arg(=1)] (=0)   Use a fullscreen preview window
  --qt-preview [=arg(=1)] (=0)          Use Qt-based preview window (WARNING: causes heavy CPU load, fullscreen not 
                                        supported)
  --hflip [=arg(=1)] (=0)               Request a horizontal flip transform
  --vflip [=arg(=1)] (=0)               Request a vertical flip transform
  --rotation arg (=0)                   Request an image rotation, 0 or 180
  --roi arg (=0,0,0,0)                  Set region of interest (digital zoom) e.g. 0.25,0.25,0.5,0.5
  --shutter arg (=0)                    Set a fixed shutter speed in microseconds
  --analoggain arg (=0)                 Set a fixed gain value (synonym for 'gain' option)
  --gain arg                            Set a fixed gain value
  --metering arg (=centre)              Set the metering mode (centre, spot, average, custom)
  --exposure arg (=normal)              Set the exposure mode (normal, sport)
  --ev arg (=0)                         Set the EV exposure compensation, where 0 = no change
  --awb arg (=auto)                     Set the AWB mode (auto, incandescent, tungsten, fluorescent, indoor, daylight, 
                                        cloudy, custom)
  --awbgains arg (=0,0)                 Set explict red and blue gains (disable the automatic AWB algorithm)
  --flush [=arg(=1)] (=0)               Flush output data as soon as possible
  --wrap arg (=0)                       When writing multiple output files, reset the counter when it reaches this 
                                        number
  --brightness arg (=0)                 Adjust the brightness of the output images, in the range -1.0 to 1.0
  --contrast arg (=1)                   Adjust the contrast of the output image, where 1.0 = normal contrast
  --saturation arg (=1)                 Adjust the colour saturation of the output, where 1.0 = normal and 0.0 = 
                                        greyscale
  --sharpness arg (=1)                  Adjust the sharpness of the output image, where 1.0 = normal sharpening
  --framerate arg (=-1)                 Set the fixed framerate for preview and video modes
  --denoise arg (=auto)                 Sets the Denoise operating mode: auto, off, cdn_off, cdn_fast, cdn_hq
  --viewfinder-width arg (=0)           Width of viewfinder frames from the camera (distinct from the preview window 
                                        size
  --viewfinder-height arg (=0)          Height of viewfinder frames from the camera (distinct from the preview window 
                                        size)
  --tuning-file arg (=-)                Name of camera tuning file to use, omit this option for libcamera default 
                                        behaviour
  --lores-width arg (=0)                Width of low resolution frames (use 0 to omit low resolution stream
  --lores-height arg (=0)               Height of low resolution frames (use 0 to omit low resolution stream
  --mode arg                            Camera mode as W:H:bit-depth:packing, where packing is P (packed) or U 
                                        (unpacked)
  --viewfinder-mode arg                 Camera mode for preview as W:H:bit-depth:packing, where packing is P (packed) 
                                        or U (unpacked)
  --buffer-count arg (=0)               Number of in-flight requests (and buffers) configured for video, raw, and 
                                        still.
  --viewfinder-buffer-count arg (=0)    Number of in-flight requests (and buffers) configured for preview window.
  --autofocus-mode arg (=default)       Control to set the mode of the AF (autofocus) algorithm.(manual, auto, 
                                        continuous)
  --autofocus-range arg (=normal)       Set the range of focus distances that is scanned.(normal, macro, full)
  --autofocus-speed arg (=normal)       Control that determines whether the AF algorithm is to move the lens as quickly
                                        as possible or more steadily.(normal, fast)
  --autofocus-window arg (=0,0,0,0)     Sets AfMetering to  AfMeteringWindows an set region used, e.g. 
                                        0.25,0.25,0.5,0.5
  --lens-position arg                   Set the lens to a particular focus position, expressed as a reciprocal distance
                                        (0 moves the lens to infinity), or "default" for the hyperfocal distance
  --hdr [=arg(=1)] (=0)                 Enable (1) or disable (0) High Dynamic Range, where supported
  --metadata arg                        Save captured image metadata to a file or "-" for stdout
  --metadata-format arg (=json)         Format to save the metadata in, either txt or json (requires --metadata)
  -q [ --quality ] arg (=93)            Set the JPEG quality parameter
  -x [ --exif ] arg                     Add these extra EXIF tags to the output file
  --timelapse arg (=0)                  Time interval (in ms) between timelapse captures
  --framestart arg (=0)                 Initial frame counter value for timelapse captures
  --datetime [=arg(=1)] (=0)            Use date format for output file names
  --timestamp [=arg(=1)] (=0)           Use system timestamps for output file names
  --restart arg (=0)                    Set JPEG restart interval
  -k [ --keypress ] [=arg(=1)] (=0)     Perform capture when ENTER pressed
  -s [ --signal ] [=arg(=1)] (=0)       Perform capture when signal received
  --thumb arg (=320:240:70)             Set thumbnail parameters as width:height:quality, or none
  -e [ --encoding ] arg (=jpg)          Set the desired output encoding, either jpg, png, rgb, bmp or yuv420
  -r [ --raw ] [=arg(=1)] (=0)          Also save raw file in DNG format
  --latest arg                          Create a symbolic link with this name to most recent saved file
  --immediate [=arg(=1)] (=0)           Perform first capture immediately, with no preview phase
  --autofocus-on-capture [=arg(=1)] (=0)
                                        Switch to AfModeAuto and trigger a scan just before capturing a still

試しに、画質のところですね。
オプションの–qualityをいじってみましょう。

具体的にはこんな感じになります。

libcamera-jpeg -o quality100.jpg --quality 100 --qt-preview

この–qualityの直後の100が画質になります。
デフォルトでは93になっているとのことですが、
今回は、「100」と「5」で比較してみましょう。

実際に撮影した画像はこちら↓↓

libcamera-quality100
libcaemraのオプションで–qualityを100にして撮影した画像。
libcamera-quality5
libcameraのオプション–qualityで5に設定して撮影した画像。

ちゃんと画質が大きく変わっていて安心しました…
ただ、レビュー中は実は画質変わっているように見えなかったんですよね。

blightnessとかいじると、プレビュー画面も真っ白になったりしてたんですが、
画質に関しては、最後の撮影の時だけ画質が変更されるようです。

今回のまとめ

今回は、記事執筆時点での最新OSである、
Bullseyeを使った場合のカメラの接続でした。

オプションのプレビュー無しで撮影すれば画像は取れますが、
それだとプレビューが無いのでちょっと寂しいですよね。

–qt-previewを使うことで、
ソフトウェアレンダリングに切り替わって
RaspberryPi側の負荷が減って正しくプレビュー画面が表示される。
なんて理由らしいですが、
エラー内容的にそんな、負荷がどうとかって書いてないですよね…

とりあえずBullseyeでプレビューありで
カメラを使えたのはデカいですね。

次のOSの時もこの方法が使えるといいのですが…

コメント

タイトルとURLをコピーしました