0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Raspberry Pi用1.3インチLCDでオールドカメラをデジカメ化(2)

Last updated at Posted at 2022-06-07

Raspberry Pi用1.3インチLCDでOLDカメラをデジカメ化(1)では1.3inch LCDの設定とAnalog mouseの起動設定まで行いました。
今回はRaspberry Piでのプログラミングについてです。
Raspberry Piには無料で読める雑誌Magpiというのがあり、そこが出しているCamera Guideという本が参考になります。
今回こちらの雑誌にあるサンプルコードを利用します。
P28からPythonでの使用方法が記載してあります。まずTerminalを開いて以下のコマンドを入力しPythonでカメラを使えるようにします。

sudo apt-get update
sudo apt-get install pythin-pycamera python3-picamera

次にチャプター6 「Stop-motion and selfies」のサンプルコードch7listing.pyをP37のリンクからダウンロードします。
このサンプルコードではGPIO 14、15(GND)にボタンスイッチを接続し、スイッチを押すとシャッターが切れ、「pic+タイムスタンプ.jpg」というファイル名で保存するものです。
今回使用1.3inch LCDは以下のようにボタンやジョイスティックが割り振られています。

P21:KEY1
P20:KEY2
P16:KEY3
P6:Joystick UP
P19:Joystick Down
P5:Joystick Left
P26:Joystick Right
P13:Joystick Press
P11:SCLK
P10:MOSI
P8:CS
P25:DC
P27:RST
P24:BL

アナログマウスを起動しているため、KEY1は左クリックとして使用しますので、今回はKEY2のP20をシャッターとして使用します。解像度は「pc.resolution=(1024,768)」となっていますが、HQカメラを使用しているので、せっかくなので「pc.resolution = (2592, 1944)」に変更しておきます。サンプルコードではプレビューの画面が大きいので、「pc.start_preview(fullscreen=False,window=(50,20,500,500))」としておきます。このくらいだとウィンドウの閉じるボタンをなんとかマウスで押せます。解像度設定の直後に「pc.awb_mode = 'incandescent'」と入れておきます。今回私はHQカメラのCCD部分のみを使用しているため、マウントに付属されているローパスフィルターを外しています。その場合「pc.awb_mode = 'auto'」としておくと色がピンクっぽくなってしまうので、それを防ぐために変更しています。感度を自動設定とするため「pc.iso=0」としてあります。保存するファイル名に日付を付与したいので、「pc.capture('pic'+str(datetime.now())+'jpg')」としておきます。

camera.py
#importing the necessary modules
from datetime import datetime
from gpiozero import Button
import picamera
import time

#Button MAP 1.3LCD
b=Button(20) #KEY2
#b=Button(21) #KEY1
#b=Button(20) #KEY2
#b=Button(16) #KEY3
#b=Button(6)  #Stick UP
#b=Button(19) #Stick DOWN
#b=Button(26) #Stick RIGHT
#b=Button(5)  #Stick LEFT
#b=Button(13) #Stick PRESS

pc=picamera.PiCamera()
running = True
pc.resolution = (2592, 1944)
pc.awb_mode = 'incandescent'
pc.iso=0


def picture():
    pc.capture('pic'+str(datetime.now())+'.jpg') #taking the picture

pc.start_preview(fullscreen=False,window=(50,20,500,500)) #running the preview

try:
    while running:
        print('Active') #displaying 'active' to the shell
        b.when_pressed=picture
        time.sleep(1)

#we detect Ctrl-C then quit the program
except KeyboardInterrupt:
    pc.stop_preview()
    running = False
    

私はこのファイルをデスクトップのcameraというフォルダにいれ、マウスでThonny Python IDEを起動し、実行ボタンを押すことで使用していますが、このプログラムはキーボードからCTLR+Cで停止するまでずっと起動したままです。今回キーボードを接続していないので、プログラムを停止させるためにウィンドウサイズを500×500にしています。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?