Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f8dbed0
initial commit
Sep 1, 2025
267b879
Merge branch 'main' into 2-take-photos-with-specified-exposure-settings
Ch1hiro Sep 3, 2025
0f1d34e
Merge branch 'main' into 2-take-photos-with-specified-exposure-settings
Ch1hiro Sep 3, 2025
4d286d9
[WIP]初期化処理を行う関数を作成中
Sep 4, 2025
9705ec0
[Fix]syntax error修正
Sep 4, 2025
d143755
[Add] add vs code file to gitignore
Sep 5, 2025
1ed18ea
[WIP]関数作成中
Sep 5, 2025
5a49484
[Fix]行数長すぎ問題に対応
Sep 5, 2025
ba0be6a
[Fix]return直後のelseを削除
Sep 5, 2025
e3c886d
内部でしか使う予定のないEnumの命名を変更
Sep 5, 2025
17b38fa
[Update]例外クラスを追加し、例外が発生するよう変更
Sep 6, 2025
ecad998
[Update]Thetaに設定できるOptionを定数として登録
Sep 6, 2025
7771fc0
[Update]初期化処理を関数を使って書き直し
Sep 6, 2025
bdb59f4
[delete]ステータス確認コードを削除
Sep 6, 2025
d853ce8
[Update]オプションのEnumにホワイトバランスを追加
Sep 6, 2025
44ae730
[Update]ステータスの確認コードを追加
Sep 6, 2025
5b530f6
[Update]テストキャプチャコードを関数を使って記述
Sep 6, 2025
803e7e4
[Fix]リントエラー修正
Sep 6, 2025
1eace12
[Update]共通するコードフラグメントを関数化
Sep 6, 2025
23ed28d
[Fix]バグの修正
Sep 6, 2025
96eff65
[Fix]updateしていない箇所を修正
Sep 6, 2025
7bbe5e4
[Fix]改行を削除
Sep 6, 2025
51c1ff6
[Fix]docstringの追加
Sep 6, 2025
380785a
[Fix]長い行を改行
Sep 6, 2025
6ce5ee2
[Fix]型が間違っている箇所を修正
Sep 6, 2025
8d83250
[Fix]関数の命名を変更
Sep 6, 2025
d2b11f7
[Update]theta_initの処理を関数として外部から参照可能に変更
Sep 9, 2025
854a23d
[Update]テスト用の関数にLinterのアノテーションを付与
Sep 9, 2025
58c56f3
[Update]関数を用いて記述
Sep 9, 2025
6295342
[Fix]Linterのエラー対応
Sep 9, 2025
e81aa24
[Fix]typo修正
Sep 9, 2025
56d12d2
[Fix]実行環境のPythonバージョンに合わせ変更
Sep 13, 2025
7f5138c
[Fix]型ヒントの書き方を修正
Sep 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.13"]
python-version: ["3.9"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,4 @@ cython_debug/
marimo/_static/
marimo/_lsp/
__marimo__/
.vscode/settings.json
66 changes: 28 additions & 38 deletions theta_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@
import time
import datetime

import requests
import theta_wireless as tw
from theta_wireless import Options
import theta_init

# pylint: disable=duplicate-code

# カメラIP
THETA_IP = "192.168.1.1"
EXECUTE_URL = f"http://{THETA_IP}/osc/commands/execute"
STATUS_URL = f"http://{THETA_IP}/osc/commands/status"

HEADERS = {"Content-Type": "application/json;charset=utf-8"}

# 撮影設定リスト (ISO, shutter_speed, ColorTemperature)
settings_list = [
Expand All @@ -33,38 +27,28 @@

def set_options(iso, shutter_speed, white_balance):
"""オプションを設定"""
options_command = {
"name": "camera.setOptions",
"parameters": {
"options": {
"iso": iso,
"shutterSpeed": shutter_speed,
"whiteBalance": "_colorTemperature",
"colorTemperature": white_balance,
}
},
}
resp = requests.post(EXECUTE_URL, json=options_command, headers=HEADERS, timeout=10)
resp.raise_for_status()
return resp.json()


def take_picture():
"""Theta Web APIを用いて撮影"""
take_command = {"name": "camera.takePicture"}
resp = requests.post(EXECUTE_URL, json=take_command, headers=HEADERS, timeout=10)
resp.raise_for_status()
return resp.json()
tw.set_options(
{
Options.ISO:iso,
Options.SHUTTER_SPEED: shutter_speed,
Options.WHITE_BALANCE: Options.COLOR_TEMPERATURE,
Options.COLOR_TEMPERATURE: white_balance
}
)
resp = tw.get_options(
{
Options.ISO,
Options.SHUTTER_SPEED,
Options.COLOR_TEMPERATURE
}
)
return resp


def wait_for_completion(command_id):
"""撮影完了まで処理を停止"""
while True:
status_resp = requests.post(
STATUS_URL, json={"id": command_id}, headers=HEADERS, timeout=10
)
status_resp.raise_for_status()
status = status_resp.json()
status = tw.check_status(command_id=command_id)
if status.get("state") == "done":
return status.get("results")
time.sleep(0.5)
Expand All @@ -77,7 +61,7 @@ def capture_12():
set_options(**s)
print("設定完了:", s)

result = take_picture()
result = tw.take_picture()
print("撮影コマンド送信:", result)

if "id" in result:
Expand Down Expand Up @@ -119,5 +103,11 @@ def schedule_shoots():
time.sleep(wait_sec / 60)


if __name__ == "__main__":
def main():
"""メイン関数"""
theta_init.init()
schedule_shoots()


if __name__ == "__main__":
main()
48 changes: 29 additions & 19 deletions theta_init.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
"""Script for controlling RICOH THETA camera."""
"""Thetaカメラを初期化します"""

import requests
import theta_wireless
from theta_wireless import Options

# pylint: disable=duplicate-code
def init():
"""Thetaの初期化処理を行います。"""
try:
theta_wireless.set_options(
{
Options.CAPTURE_MODE:"image",
Options.EXPOSURE_PROGRAM:1,
Options.SLEEP_DELAY:65535,
Options.SHUTTER_VOLUME:0
}
)
response = theta_wireless.get_options(
{
Options.CAPTURE_MODE,
Options.EXPOSURE_PROGRAM,
Options.SLEEP_DELAY,
Options.SHUTTER_VOLUME
}
)
print(response)

URL = "http://192.168.1.1/osc/commands/execute"
HEADERS = {"Content-Type": "application/json;charset=utf-8"}
except theta_wireless.CameraInternalError as e:
print(f"Caught OSC API error: {e.code} -> {e.message}")

payload = {
"name": "camera.setOptions",
"parameters": {"options": {"captureMode": "image"}},
}
except theta_wireless.CameraTimeout as e:
print(f"Timeoutしました: {e}")

resp = requests.post(URL, json=payload, headers=HEADERS, timeout=10)
print(resp.json())

payload = {
"name": "camera.setOptions",
"parameters": {"options": {"exposureProgram": 1}},
}

resp = requests.post(URL, json=payload, headers=HEADERS, timeout=10)
print(resp.json())
if __name__ == "__main__":
init()
19 changes: 0 additions & 19 deletions theta_status.py

This file was deleted.

54 changes: 20 additions & 34 deletions theta_test_capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,11 @@

import time

import requests
import theta_wireless as tw
from theta_wireless import Options

# pylint: disable=duplicate-code

# カメラIP
THETA_IP = "192.168.1.1"
EXECUTE_URL = f"http://{THETA_IP}/osc/commands/execute"
STATUS_URL = f"http://{THETA_IP}/osc/commands/status"

HEADERS = {"Content-Type": "application/json;charset=utf-8"}

# 撮影設定リスト (ISO, shutter_speed, f, ColorTemperature)
settings_list = [
Expand All @@ -32,37 +27,28 @@

def set_options(iso, shutter_speed, white_balance):
"""オプションを設定"""
options_command = {
"name": "camera.setOptions",
"parameters": {
"options": {
"iso": iso,
"shutterSpeed": shutter_speed,
"_colorTemperature": white_balance,
}
},
}
resp = requests.post(EXECUTE_URL, json=options_command, headers=HEADERS, timeout=10)
resp.raise_for_status()
return resp.json()


def take_picture():
"""Take a picture using the Theta API"""
take_command = {"name": "camera.takePicture"}
resp = requests.post(EXECUTE_URL, json=take_command, headers=HEADERS, timeout=10)
resp.raise_for_status()
return resp.json()
tw.set_options(
{
Options.ISO:iso,
Options.SHUTTER_SPEED: shutter_speed,
Options.WHITE_BALANCE: Options.COLOR_TEMPERATURE,
Options.COLOR_TEMPERATURE: white_balance
}
)
resp = tw.get_options(
{
Options.ISO,
Options.SHUTTER_SPEED,
Options.COLOR_TEMPERATURE
}
)
return resp


def wait_for_completion(command_id):
"""Wait a few seconds to complete"""
while True:
status_resp = requests.post(
STATUS_URL, json={"id": command_id}, headers=HEADERS, timeout=10
)
status_resp.raise_for_status()
status = status_resp.json()
status = tw.check_status(command_id=command_id)
if status.get("state") == "done":
return status.get("results")
time.sleep(0.5)
Expand All @@ -74,7 +60,7 @@ def wait_for_completion(command_id):
set_options(**s)
print("設定完了:", s)

result = take_picture()
result = tw.take_picture()
print("撮影コマンド送信:", result)

if "id" in result:
Expand Down
Loading