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.

テスト

Last updated at Posted at 2023-06-01

import PySimpleGUI as sg
import cv2
import threading
import time
import os

各カメラの設定を保存する辞書

cameras = {
'camera1': {'interval': 10, 'folder': './'},
'camera2': {'interval': 10, 'folder': './'},
# 必要なだけカメラを追加
}

def capture_image(camera_id, folder):
cap = cv2.VideoCapture(camera_id)
ret, frame = cap.read()

if ret:
    filename = os.path.join(folder, f'{camera_id}_{time.time()}.jpg')
    cv2.imwrite(filename, frame)

cap.release()

def capture_images():
while True:
for camera_id, camera_info in cameras.items():
capture_image(camera_id, camera_info['folder'])
time.sleep(camera_info['interval'])

def start_capturing():
threading.Thread(target=capture_images, daemon=True).start()

レイアウトを定義

layout = [[sg.Text('Camera1 Folder'), sg.Input(key='-FOLDER1-'), sg.FolderBrowse()],
[sg.Text('Camera1 Interval'), sg.Input(key='-INTERVAL1-')],
[sg.Text('Camera2 Folder'), sg.Input(key='-FOLDER2-'), sg.FolderBrowse()],
[sg.Text('Camera2 Interval'), sg.Input(key='-INTERVAL2-')],
[sg.Button('Start Capturing')]]

ウィンドウを作成

window = sg.Window('Camera App', layout)

while True:
event, values = window.read()

if event == sg.WINDOW_CLOSED:
    break
elif event == 'Start Capturing':
    cameras['camera1']['folder'] = values['-FOLDER1-']
    cameras['camera1']['interval'] = int(values['-INTERVAL1-'])
    cameras['camera2']['folder'] = values['-FOLDER2-']
    cameras['camera2']['interval'] = int(values['-INTERVAL2-'])
    start_capturing()

window.close()

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?