Skip to content

Commit

Permalink
Merge branch 'dev_bellalarm'
Browse files Browse the repository at this point in the history
  • Loading branch information
TakashiIjiri committed Aug 28, 2020
2 parents b43260f + d160879 commit 26ec9c9
Show file tree
Hide file tree
Showing 15 changed files with 216 additions and 89 deletions.
63 changes: 0 additions & 63 deletions README

This file was deleted.

77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# Lepton Viewer
サーモカメラ Lepton 3.5 の可視化ツールです.
サーモグラフィ画像表示,閾値以上の画素のハイライト,閾値以上の画素が検出された際のアラーム音提示機能を持ちます.
Windows PC用です.

![LeptonViewer](https://github.com/InteractiveGraphicsLab/LeptonViewer/blob/dev_bellalarm/imgs/leptonviewer.gif "LeptonViewer")



## 実行方法 (exeファイルを利用)
- Lepton 3.5 または Lepton 3.0 がUSB接続されたWindows PCを用意してください
- このリポジトリのリリースより,最新版のzipファイルをダウンロードし,展開してください
- Visual studio runtimeのインストール
- 展開したフォルダ内のInstallフォルダを開きVC_redist.x64.exeをダブルクリックしてください
- すでに新しいバージョンがインストール済み,の表示があればインストール不要です
- dllファイルのアクセス許可
- 展開したフォルダ内のx64フォルダを開いてください
- フォルダ内dllを右クリックしプロパティを開いてください
- 「このファイルは他のコンピューターから取得したものです...」の表示があれば「ブロックの解除」をチェックしてください
- すべてのdllファイルにこの処理を行ってください
- ※なければ何もしなくて良いです
- 展開したフォルダ内のLeptonViewer.exeをダブルクリックするとLeptonViewerが起動します.



## 実行方法(Pythonを利用する方法,開発者向け)

LocalのPythonを利用する場合は以下の手順に従ってください.
インストール不要なものについては随時読み飛ばしてください.

### 1. Visual studio runtimeのインストール
- LeptonViewer\SDK\Lepton-SDK_PureThermal_Windows10_1.0.2\Redistributables\VC_redist.x64.exeをダブルクリック
- すでに新しいバージョンがインストール済み,の表示があればキャンセルして良い

### 2. dllの利用許可
- LeptonViewer\src\x64下のすべてのdllファイルを右クリックしてプロパティを開く
- 「このファイルは他のコンピューターから取得したものです...」の表示があれば「ブロックの解除」をチェック
- ※なければ何もしなくて良い

### 3. 実行環境の構築
- pythonをインストール(python 3.7とanaconda1.5.1で開発)
- Pycharm (コミュニティ)をインストール
- PycharmでLeptonViewerプロジェクトを開く
- Interpreterを追加:
- File > Settings > Project: LeptonViewer > Project Interpreter > ギアマーク
- Add > New environment > (virtual environmentが初めから選択されているはず) > OK
- パッケージをインストール:
- File > Settings > Project: LeptonViewer > Project Interpreter > プラスマーク
- それぞれを検索してInstall Packageを押す:
- opencv-python(自動でnumpyもインストールされるはず)
- Pillow
- pythonnet

- ソースコードをプロジェクトへ追加 :
- File > Settings > Project: プロジェクト名※ > Project Structure > add content root
- srcフォルダを選択(mark as sourcesを指定) > OK
- --> Project windowにsrcフォルダが配置される



#### 4. 実行
- viewer.pyを右クリック > Run



### 5. exeファイル化
- パッケージをインストールと同様にPyInstallerをインストール
- PycharmのTerminalを開く
- .\venv\Scripts\pyinstaller.exe -w .\viewer.spec
- (あるいは .\venv\Scripts\pyinstaller.exe -F -w --hidden-import=clr -i .\src\logo.ico .\src\viewer.py)
- ビルド結果が.\distに生成される
- 実行時に必要なファイル(x64, x86, config.ini, default.ini, logo.ico)をコピーすれば他のwindowsマシンで実行可能





Binary file added imgs/case.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/leptonviewer.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added imgs/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/__pycache__/import_clr.cpython-38.pyc
Binary file not shown.
Binary file modified src/__pycache__/lepton_control.cpython-38.pyc
Binary file not shown.
Binary file modified src/__pycache__/params.cpython-38.pyc
Binary file not shown.
Binary file added src/bell1.wav
Binary file not shown.
Binary file added src/bell2.wav
Binary file not shown.
Binary file added src/bell3.wav
Binary file not shown.
Binary file added src/bell4.wav
Binary file not shown.
9 changes: 9 additions & 0 deletions src/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,12 @@ show_cam_temperature = True
offset = 0.0
coefficient = 0.05

[ROI_RECT]
x = 50
y = 10
w = 700
h = 399

[BELL_TYPE]
bell = 4

99 changes: 94 additions & 5 deletions src/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
# visualization window size
W_SIZE = [800, 600]

# ROI (x,y,W,H)
ROI_RECT = [0, 0, 800, 600]

# Bell Type 0, 1, or 2
BELL_TYPE = 1

# flag for flipping image
FLIP = True

Expand All @@ -28,8 +34,9 @@
COEFFICIENT = 0.05



def init():
global W_SIZE, FLIP, ROTATE, TONE_MIN, TONE_MAX, THRESHOLD, SHOW_MAXTEMP, SHOW_CAMTEMP, OFFSET, COEFFICIENT
global W_SIZE, FLIP, ROTATE, TONE_MIN, TONE_MAX, THRESHOLD, SHOW_MAXTEMP, SHOW_CAMTEMP, OFFSET, COEFFICIENT, ROI_RECT, BELL_TYPE
config = configparser.ConfigParser()
config.read("./config.ini")

Expand All @@ -46,6 +53,13 @@ def init():
OFFSET = float(config['CALIBRATION']['offset'])
COEFFICIENT = float(config['CALIBRATION']['coefficient'])

ROI_RECT[0] = int(config['ROI_RECT']['x'])
ROI_RECT[1] = int(config['ROI_RECT']['y'])
ROI_RECT[2] = int(config['ROI_RECT']['w'])
ROI_RECT[3] = int(config['ROI_RECT']['h'])

BELL_TYPE = int(config['BELL_TYPE']['bell'])


def save_setting():
config = configparser.RawConfigParser()
Expand All @@ -68,12 +82,32 @@ def save_setting():
config.set('CALIBRATION', 'offset', str(OFFSET))
config.set('CALIBRATION', 'coefficient', str(COEFFICIENT))

config.add_section('ROI_RECT')
config.set('ROI_RECT', 'x', str(ROI_RECT[0]))
config.set('ROI_RECT', 'y', str(ROI_RECT[1]))
config.set('ROI_RECT', 'w', str(ROI_RECT[2]))
config.set('ROI_RECT', 'h', str(ROI_RECT[3]))

config.add_section('BELL_TYPE')
config.set('BELL_TYPE', 'bell', int(BELL_TYPE))

with open('./config.ini', 'w') as configfile:
config.write(configfile)


class SettingDlg:
def get_bellpath():
if BELL_TYPE == 1:
return "./bell1.wav"
if BELL_TYPE == 2:
return "./bell2.wav"
if BELL_TYPE == 3:
return "./bell3.wav"
if BELL_TYPE == 4:
return "./bell4.wav"
return None


class SettingDlg:
def __init__(self, camera_is_tlinear):
top = tk.Toplevel()
top.resizable(0, 0)
Expand Down Expand Up @@ -149,17 +183,55 @@ def __init__(self, camera_is_tlinear):
self.spin_tonemin.grid(row=0, column=1, padx=5, pady=5)
self.spin_tonemax.grid(row=0, column=3, padx=5, pady=5)

# ROI rectangle --------------------------------------------------------------------------------
lf_roi = tk.LabelFrame(top, text="最大温度計測領域(ROI)")
lf_roi.pack(fill="both", expand="yes", padx=10, pady=5)
roi_label1 = tk.Label(lf_roi, text="位置 (x, y)")
roi_label2 = tk.Label(lf_roi, text="大きさ(W, H)")
roi_label1.grid(row=0, column=0, padx=5, pady=5)
roi_label2.grid(row=1, column=0, padx=5, pady=5)
self.var_roix = tk.StringVar()
self.var_roiy = tk.StringVar()
self.var_roiw = tk.StringVar()
self.var_roih = tk.StringVar()
self.var_roix.set(ROI_RECT[0])
self.var_roiy.set(ROI_RECT[1])
self.var_roiw.set(ROI_RECT[2])
self.var_roih.set(ROI_RECT[3])
self.spin_roix = tk.Spinbox(lf_roi, from_=0, to=1200, increment=1, textvariable=self.var_roix, width=6, command=self.update)
self.spin_roiy = tk.Spinbox(lf_roi, from_=0, to=1200, increment=1, textvariable=self.var_roiy, width=6, command=self.update)
self.spin_roiw = tk.Spinbox(lf_roi, from_=1, to=1200, increment=1, textvariable=self.var_roiw, width=6, command=self.update)
self.spin_roih = tk.Spinbox(lf_roi, from_=1, to=1200, increment=1, textvariable=self.var_roih, width=6, command=self.update)
self.spin_roix.grid(row=0, column=1, padx=2, pady=2)
self.spin_roiy.grid(row=0, column=2, padx=2, pady=2)
self.spin_roiw.grid(row=1, column=1, padx=2, pady=2)
self.spin_roih.grid(row=1, column=2, padx=2, pady=2)

# threshold --------------------------------------------------------------------------------
lf_threshold = tk.LabelFrame(top, text="Threshold - 超過温度可視化")
lf_threshold.pack(fill="both", expand="yes", padx=10, pady=5, ipady=5)

label_threshold = tk.Label(lf_threshold, text=" 閾値温度[℃] ")
label_threshold.pack(side=tk.LEFT)
label_bell_type = tk.Label(lf_threshold, text=" bell type")
self.var_threshold = tk.StringVar()
self.var_threshold.set(THRESHOLD)
self.spin_threshold = tk.Spinbox(lf_threshold, from_=-100, to=500, format="%.2f", increment=0.1, width=6,
textvariable=self.var_threshold, command=self.update)
self.spin_threshold.pack(side=tk.LEFT)
self.var_belltype = tk.IntVar()
self.var_belltype.set(BELL_TYPE)
b0 = tk.Radiobutton(lf_threshold, text="off", value=0, variable=self.var_belltype, command=self.update)
b1 = tk.Radiobutton(lf_threshold, text="1", value=1, variable=self.var_belltype, command=self.update)
b2 = tk.Radiobutton(lf_threshold, text="2", value=2, variable=self.var_belltype, command=self.update)
b3 = tk.Radiobutton(lf_threshold, text="3", value=3, variable=self.var_belltype, command=self.update)
b4 = tk.Radiobutton(lf_threshold, text="4", value=4, variable=self.var_belltype, command=self.update)
label_threshold.grid(row=0, column=0, padx=0, pady=5)
self.spin_threshold.grid(row=0, column=1, padx=0, pady=5)
label_bell_type.grid(row=1, column=0, padx=0, pady=5)
b0.grid(row=1, column=1, padx=0, pady=5)
b1.grid(row=1, column=2, padx=0, pady=5)
b2.grid(row=1, column=3, padx=0, pady=5)
b3.grid(row=1, column=4, padx=0, pady=5)
b4.grid(row=1, column=5, padx=0, pady=5)

# calibration --------------------------------------------------------------------------------
lf_calibration = tk.LabelFrame(top, text="Calibration")
Expand Down Expand Up @@ -196,18 +268,35 @@ def __init__(self, camera_is_tlinear):
btn_save.pack(side=tk.RIGHT)

def update(self):
global FLIP, ROTATE, W_SIZE, SHOW_MAXTEMP, SHOW_CAMTEMP, TONE_MIN, TONE_MAX, THRESHOLD, OFFSET, COEFFICIENT
global FLIP, ROTATE, W_SIZE, SHOW_MAXTEMP, SHOW_CAMTEMP, TONE_MIN, TONE_MAX, THRESHOLD, OFFSET, COEFFICIENT, \
ROI_RECT, BELL_TYPE
FLIP = bool(self.var_flip.get())
SHOW_MAXTEMP = bool(self.var_maxtemp.get())
SHOW_CAMTEMP = bool(self.var_camtemp.get())
ROTATE = self.var_rot.get()
BELL_TYPE = self.var_belltype.get()
W_SIZE[0] = int(self.spin_size.get())
W_SIZE[1] = int(W_SIZE[0] * 3 // 4)

TONE_MIN = float(self.spin_tonemin.get())
TONE_MAX = float(self.spin_tonemax.get())

ROI_RECT[0] = int(self.spin_roix.get())
ROI_RECT[1] = int(self.spin_roiy.get())
ROI_RECT[2] = int(self.spin_roiw.get())
ROI_RECT[3] = int(self.spin_roih.get())
if ROTATE % 2 == 0:
w, h = W_SIZE[0], W_SIZE[1]
else:
w, h = W_SIZE[1], W_SIZE[0]
print(W_SIZE, w, h)
ROI_RECT[0] = np.clip(ROI_RECT[0], 0, w-2)
ROI_RECT[1] = np.clip(ROI_RECT[1], 0, h-2)
ROI_RECT[2] = np.clip(ROI_RECT[2], 1, w )
ROI_RECT[3] = np.clip(ROI_RECT[3], 1, h )

THRESHOLD = float(self.spin_threshold.get())

OFFSET = float(self.spin_ofst.get())
COEFFICIENT = float(self.spin_coef.get())

Loading

0 comments on commit 26ec9c9

Please sign in to comment.