Skip to content

Commit

Permalink
Merge pull request #8 from takpika/main
Browse files Browse the repository at this point in the history
起動しない問題とカーソルが動かせなくなる問題の修正
  • Loading branch information
takeyamayuki authored Oct 10, 2021
2 parents 417b92a + 9135ca1 commit 4355f63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
13 changes: 12 additions & 1 deletion app-s.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
mouse = Controller()
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
screenRes = (0,0)


def tk_arg():
root = tk.Tk()
root.title("First Setup")
root.geometry("300x260")
screenRes = (root.winfo_screenwidth(),root.winfo_screenheight()) # ディスプレイ解像度取得
Val1 = tk.IntVar()
Val2 = tk.IntVar()
Val4 = tk.IntVar()
Expand Down Expand Up @@ -92,7 +94,7 @@ def main(cap_device, mode, kando):
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cap_height)
cfps = int(cap.get(cv2.CAP_PROP_FPS))
# スムージング量(小さい:カーソルが小刻みに動く 大きい:遅延が大)
ran = int(cfps/10)
ran = max(int(cfps/10),1)
hands = mp_hands.Hands(
min_detection_confidence=0.8, # 検出信頼度
min_tracking_confidence=0.8, # 追跡信頼度
Expand Down Expand Up @@ -152,8 +154,17 @@ def main(cap_device, mode, kando):
LiTx.pop(0) # 先頭を削除
LiTy.pop(0)
# カメラ座標をマウス移動量に変換
posx,posy=mouse.position
dx = kando * (sum(LiTx)/ran - preX) * image_width
dy = kando * (sum(LiTy)/ran - preY) * image_height
if posx+dx<0: # カーソルがディスプレイから出て戻ってこなくなる問題の防止
dx = -posx
elif posx+dx>screenRes[0]:
dx = screenRes[0]-posx
if posy+dy<0:
dy = -posy
elif posy+dy>screenRes[1]:
dy = screenRes[1]-posy

# フラグ #########################################################################
# click状態
Expand Down
15 changes: 13 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
hotkey = 'F4'

screenRes = (0,0)

def tk_arg():
global screenRes
root = tk.Tk()
root.title("First Setup")
root.geometry("300x260")
screenRes = (root.winfo_screenwidth(),root.winfo_screenheight()) # ディスプレイ解像度取得
Val1 = tk.IntVar()
Val2 = tk.IntVar()
Val4 = tk.IntVar()
Expand Down Expand Up @@ -94,7 +96,7 @@ def main(cap_device, mode, kando):
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, cap_height)
cfps = int(cap.get(cv2.CAP_PROP_FPS))
# スムージング量(小さい:カーソルが小刻みに動く 大きい:遅延が大)
ran = int(cfps/10)
ran = max(int(cfps/10),1)
hands = mp_hands.Hands(
min_detection_confidence=0.8, # 検出信頼度
min_tracking_confidence=0.8, # 追跡信頼度
Expand Down Expand Up @@ -154,8 +156,17 @@ def main(cap_device, mode, kando):
LiTx.pop(0) # 先頭を削除
LiTy.pop(0)
# カメラ座標をマウス移動量に変換
posx,posy=mouse.position
dx = kando * (sum(LiTx)/ran - preX) * image_width
dy = kando * (sum(LiTy)/ran - preY) * image_height
if posx+dx<0: # カーソルがディスプレイから出て戻ってこなくなる問題の防止
dx = -posx
elif posx+dx>screenRes[0]:
dx = screenRes[0]-posx
if posy+dy<0:
dy = -posy
elif posy+dy>screenRes[1]:
dy = screenRes[1]-posy

# フラグ #########################################################################
# click状態
Expand Down

0 comments on commit 4355f63

Please sign in to comment.