-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcamera.py
75 lines (57 loc) · 1.98 KB
/
camera.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from rembg import remove
import playsound
import cv2
import numpy as np
import time
cap = cv2.VideoCapture(0)
start_time = time.time()
right_click = False
# def shot_COUNTER(interval):
# if interval <= 10:
# return "number_1"
# elif interval <= 20:
# return "number_2"
# elif interval <= 30:
# return "number_3"
def onMouseClick(event, x, y, flags, param):
global right_click
right_click = False
if event == cv2.EVENT_LBUTTONDOWN:
print('左クリックされました')
right_click = True
def removeBG():
cnt = 0
save_interval = 10 # 保存間隔(秒)
while True:
ret, frame = cap.read()
current_time = time.time()
# # テキスト分岐
# text_to_show = shot_COUNTER(save_interval)
text_to_show = "Click to shot : " + str(cnt + 1)
# # テキスト描画
cv2.putText(frame, text_to_show, (29, 50),
cv2.FONT_HERSHEY_PLAIN, 3, (0, 255, 0), 3, cv2.LINE_AA)
# カメラ映像と処理後の画像を表示
# cv2.imshow('Camera', cv2.flip(frame, 1))
cv2.imshow('Camera', frame)
cv2.setMouseCallback('Camera', onMouseClick)
# 一定の時間が経過したらprocessed_frameを保存してアプリを終了
if right_click == True:
playsound.playsound('./SE/Camera-Phone01-1.mp3')
# rembgで背景を除去
processed_frame = remove(frame)
save_filename = f"processed_frame_{int(current_time)}.png"
# cv2.imwrite(save_filename, processed_frame)
cv2.imwrite('./Image/' + save_filename, processed_frame)
# print(f"Processed frame saved as {save_filename}")
cnt += 1
if cnt == 3:
break
# ESCキーでアプリを終了
key = cv2.waitKey(10)
if key == 27:
break
if __name__ == '__main__':
removeBG()
cap.release()
cv2.destroyAllWindows()