Skip to content

Instantly share code, notes, and snippets.

View ochilab's full-sized avatar

おちラボ ochilab

View GitHub Profile
@ochilab
ochilab / opencvCameraOnFlet.py
Created June 19, 2025 12:20
Fletでopencvのカメラ表示
import cv2
import base64
import threading
import flet as ft
from io import BytesIO
from PIL import Image
# カメラ映像を定期的にキャプチャして画像を更新
def camera_thread(page: ft.Page, image_control: ft.Image):
cap = cv2.VideoCapture(1)
@ochilab
ochilab / sam_sample.py
Last active June 17, 2025 09:36
SAM(Segment Anything)をとりあえず動かした
import cv2
import torch
from segment_anything import sam_model_registry, SamPredictor
import numpy as np
from google.colab.patches import cv2_imshow
# SAMモデルの読み込み(パスは適宜変更)
# sam_checkpoint = "sam_vit_h.pth"
sam_checkpoint = "sam_vit_h_4b8939.pth"
@ochilab
ochilab / py_irt_sample.py
Created June 13, 2025 06:41
IRT(Item Response Theory)のサンプル
import pandas as pd
import torch
from py_irt.models.two_param_logistic import TwoParamLog
class SafeTwoParamLog(TwoParamLog):
def fit_MCMC(self, models, items, responses, num_epochs=1000):
from pyro.infer import MCMC, NUTS
nuts_kernel = NUTS(self.model_vague, adapt_step_size=True)
hmc_posterior = MCMC(
@ochilab
ochilab / getMidiData.py
Created May 20, 2025 12:34
Pythonでmidiデータを取得する
import mido
# 利用可能なMIDI入力ポートの一覧を表示
print("利用可能なMIDI入力ポート:")
ports = mido.get_input_names()
for i, name in enumerate(ports):
print(f"{i}: {name}")
# # 適切なポート名に置き換えてください(例:"MIDI 1")
port_name = mido.get_input_names()[0]
@ochilab
ochilab / gasSample2.gs
Created May 15, 2025 08:39
GAS課題のサンプル(複数対応メソッドあり)
function test(){
var result = getSheetData("001");
Logger.log(result);
}
function doGet(e) {
const keyword = (e.parameter.keyword || "").trim();
if (!keyword) {
return ContentService.createTextOutput(
JSON.stringify({ error: "No keyword provided" })
@ochilab
ochilab / gasClientSample_Flet.py
Created May 14, 2025 11:09
GASから得たJSONをFletで受け取り表示する
import requests
import json
import flet as ft
### Google Apps ScriptのURLを指定
url="ここにGASのURL"
def fetch_data(value):
global url
url2=url+"?keyword=" + value
# Google Apps ScriptのURLを指定
@ochilab
ochilab / helloSampleFlet.py
Last active May 8, 2025 05:06
Flet 動作確認用サンプルコード
import flet as ft
def main(page: ft.Page):
page.title = "Flet Sample"
name_field = ft.TextField(label="あなたの名前")
greeting_text = ft.Text()
def greet(e):
greeting_text.value = f"Hello, {name_field.value}!"
@ochilab
ochilab / sample.gs
Created May 8, 2025 04:58
GASのサンプル(実習課題)
function doGet(e) {
const keyword = (e.parameter.keyword || "").trim();
if (!keyword) {
return ContentService.createTextOutput(
JSON.stringify({ error: "No keyword provided" })
).setMimeType(ContentService.MimeType.JSON);
}
result = getSheetData(keyword);
@ochilab
ochilab / getNetworkCamVideoFrame.py
Last active June 17, 2025 10:00
OpenCVを利用してネットワークカメラの映像をHTTPで取得する
import cv2
# カメラ情報を設定
username = ""
password = ""
ip_address = "192.168.1.2" # カメラのIPアドレス
port = 80 #httpの場合、 httpsなら445
# カメラによってURLの形式は異なるため、マニュアルやメーカーの仕様書を確認(httpか、httpsか)
stream_url = f"http://{username}:{password}@{ip_address}:{port}/axis-cgi/mjpg/video.cgi"
@ochilab
ochilab / create_xapi_statement.py
Created March 12, 2025 08:18
xapiでステートメントを登録する(Learning Locker)
import requests
import json
from datetime import datetime, timezone
from base64 import b64encode
# Learning Locker LRS のエンドポイント情報
LRS_ENDPOINT = "http://localhost:8081/data/xAPI/statements"
LRS_USERNAME = "xxxxxxx"
LRS_PASSWORD = "xxxxxx"