Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/692fcfd8-4b44-800f-a184-fa098175a6d5
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: 好,我一次把四樣都給你,直接可以拿去上課/改作業用 👇 === 好,我一次把四樣都給你,直接可以拿去上課/改作業用 👇 ==== ### ==== : ===== 1. 左側大圖:一隻手的示意圖 - 建議用白底線條風格的手掌圖(掌心朝鏡頭)。 - 在每個關節位置畫出圓點 + 編號:0~20。 - 點的顏色: - 手腕 0:深藍 - 拇指 1–4:橘色 - 食指 5–8:綠色 - 中指 9–12:紫色 - 無名指 13–16:紅色 - 小指 17–20:藍色 ===== # 右側表格:Landmark 對照表(可以做成 2 欄或 3 欄) | | | | | --- | --- | --- | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | # 下方說明區(運算思維連結) - 小標題:「電腦怎麼看你的手?」 - 文字建議: - 電腦不會直接「看懂手勢」,它只看見 21 個點的座標 (x, y)。 - 透過「距離」、「角度」、「相對位置」,我們可以自己設計規則, 讓電腦判斷:手指是彎的?直的?兩指靠很近? - 這就是從「資料 → 計算 → 規則 → 判斷」的 運算思維。 ==== 你可以直接貼到 Word / Google Docs,調整行距即可: ==== ===== #### ===== # 問題一: (1)請先執行老師提供的程式,觀察畫面中手上的 編號 0~20。 (2)請在下圖或空白處,畫出一隻手,並標出你觀察到的 3 個重要點(寫出編號與位置說明)。 - 重要點 1:編號 **''',位置說明:''''''______________________ - 重要點 2:編號 '''''',位置說明:''''''______________________ - 重要點 3:編號 '''''',位置說明:'''**______________________ # 問題二: 當你伸出食指時,哪幾個點看起來特別重要?請圈選: ☐ 5 ☐ 6 ☐ 7 ☐ 8 ☐ 其它:__________ 為什麼?______________________________________________________ ====== 1. 問題三: 如果我要判斷「食指是伸直還是彎曲」, 你覺得只需要哪 3 個點 就夠用?請寫出編號: - 點 A(起點):______ - 點 B(中間關節):______ - 點 C(末端):______ ====== # 問題四: 請用自己的話說明:「為什麼只要用這 3 個點,就可以判斷食指有沒有彎曲?」 ====== 1. 問題五(距離): 老師示範用公式 (x1−x2)2+(y1−y2)2(x1 - x2)^2 + (y1 - y2)^2(x1−x2)2+(y1−y2)2 的平方根當作「兩點距離」。 請試著寫出 「拇指尖 (4) 到 食指尖 (8) 的距離」 的計算式(只需寫概念,不用真的算值): 距離 d = _________________________________________________ ====== # 問題六(角度): 老師示範「夾角越大 → 越直;夾角越小 → 越彎」。 請用文字或圖畫說明:「在點 B 處(例如食指第 1 關節),如何用三個點 A、B、C 來決定角度?」 ====== 1. 問題七: 如果我們用「角度 > 150 度當作伸直」, 「角度 < 120 度當作彎曲」, 請完成下表: | | | | | --- | --- | --- | | | | | | | | | | | | | ====== # 問題八(設計自己的規則): 請你自己設計一個「捏住東西(Pinch)」的判斷條件,例如: - 兩點:拇指尖 (4)、食指尖 (8) - 當距離 d < ______ 像素時,顯示文字「Pinch!」 請在下面寫出你的規則說明: ====== 1. 問題九: 你覺得「電腦看手勢」比較像: ☐ 自己看一張照片、立刻懂意思 ☐ 看很多數字,再用數學和規則算出來 為什麼?______________________________________________________ ====== # 問題十: 你覺得這樣的「用資料 + 規則讓電腦做判斷」的想法, 可以應用在哪些地方?至少寫出兩個例子。 - 例子 1:__________________________________ - 例子 2:__________________________________ ==== 這一版是「刻意留空」,讓學生填入距離 / 角度 / 判斷條件。 ==== 你可以把 TODO 故意留著,當回家作業或課堂練習。 <syntaxhighlight lang="python">from cvzone.HandTrackingModule import HandDetector import cv2 import math === ===== TODO:請學生完成 ===== === def dist2d(a, b): """ TODO1: 計算 2D 距離 提示:用 (x1 - x2)^2 + (y1 - y2)^2 再開根號 a, b: (x, y) """ # 在這裡完成程式碼 # return ... return 0 # 先放假值,避免整支當掉 def angle_between(p1, p2, p3): """ TODO2: 計算三點 ∠p1-p2-p3 的角度 提示:使用內積公式:cosθ = (v1·v2)/(|v1||v2|),再用 math.acos 反三角 """ # 在這裡完成程式碼 # 回傳角度(單位:度) return 0.0 # 先放假值 cap = cv2.VideoCapture(0) detector = HandDetector(detectionCon=0.7, maxHands=1) while True: success, img = cap.read() if not success: break hands, img = detector.findHands(img) info_lines = [] if hands: hand = hands[0] lmList = hand["lmList"] # 手腕到食指尖的距離示範 wrist = lmList[0] index_tip = lmList[8] d_wrist_index = dist2d((wrist[0], wrist[1]), (index_tip[0], index_tip[1])) # TODO3: 設計一個距離門檻,當距離小於某值時顯示「靠很近」 # 例如:if d_wrist_index < 100: state = "靠很近" else: state = "很遠" state_distance = "請同學自己設計規則" info_lines.append("手腕-食指尖距離: {:.1f} ({})" .format(d_wrist_index, state_distance)) # 食指彎曲角度示範(用 5,6,7) p5 = (lmList[5][0], lmList[5][1]) p6 = (lmList[6][0], lmList[6][1]) p7 = (lmList[7][0], lmList[7][1]) ang_index = angle_between(p5, p6, p7) # TODO4: 設計「伸直 / 彎曲 / 中間」的門檻 # 例如:>150 伸直、<120 彎曲、其它中間 state_angle = "請同學自己設計規則" info_lines.append("食指角度: {:.1f} 度 ({})" .format(ang_index, state_angle)) # 顯示畫面上的文字 y0 = 30 for line in info_lines: cv2.putText(img, line, (10, y0), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2) y0 += 25 cv2.imshow("運算思維作業版:請同學完成 TODO", img) if cv2.waitKey(1) & 0xFF == ord("q"): break cap.release() cv2.destroyAllWindows() </syntaxhighlight> : ==== 設計概念: ==== * 螢幕左上角顯示:「請比出:X」(X 為 1~5 或 1~8,也可以改 1~10) * 使用前面「台灣數字手勢」中的 fingersUp 規則 * 學生比出正確手勢 → 顯示「✔ 正確!」,得分 +1,換下一題 * 10 秒內連對幾題可以顯示「Combo!」之類(你可再加) 下面先做一個 1~5 簡化版(讓學生較容易成功),你之後可以擴充到 1~8 或 1~10: <syntaxhighlight lang="python">import cv2 import random import time from cvzone.HandTrackingModule import HandDetector cap = cv2.VideoCapture(0) detector = HandDetector(detectionCon=0.7, maxHands=1) === 題目目前只用 1~5(方便學生) === valid_numbers = [1, 2, 3, 4, 5] current_target = random.choice(valid_numbers) last_change_time = time.time() score = 0 feedback = "" # 顯示「正確 / 再試一次」 def classify_taiwan_number(fingers): """ 台灣手勢簡化版 1~5: 這裡先用 fingersUp 的 pattern: 1: [0,1,0,0,0] 2: [0,1,1,0,0] 3: [1,1,1,0,0] 4: [0,1,1,1,1] 5: [1,1,1,1,1] 其它回傳 None """ pattern = tuple(fingers) mapping = { (0,1,0,0,0): 1, (0,1,1,0,0): 2, (1,1,1,0,0): 3, (0,1,1,1,1): 4, (1,1,1,1,1): 5, } return mapping.get(pattern, None) while True: success, img = cap.read() if not success: break hands, img = detector.findHands(img) detected_number = None if hands: hand = hands[0] fingers = detector.fingersUp(hand) detected_number = classify_taiwan_number(fingers) # 在畫面顯示目前辨識到的數字(debug 用) if detected_number is not None: cv2.putText(img, f"你現在的手勢:{detected_number}", (10, 100), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 255), 2) else: cv2.putText(img, "無法辨識為 1~5 手勢", (10, 100), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 255, 255), 2) # 判斷是否答對 if detected_number == current_target: feedback = "✔ 正確!" score += 1 # 換下一題 current_target = random.choice(valid_numbers) last_change_time = time.time() else: # 只有在有偵測到數字時才顯示錯誤 if detected_number is not None: feedback = "再試一次!" # 顯示題目 cv2.putText(img, f"請比出:{current_target}", (10, 40), cv2.FONT_HERSHEY_SIMPLEX, 1.0, (0, 255, 0), 2) # 顯示得分 cv2.putText(img, f"Score: {score}", (10, 80), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 255, 255), 2) # 顯示回饋 if feedback: cv2.putText(img, feedback, (10, 140), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 255), 2) cv2.imshow("數字手勢訓練遊戲 (1~5)", img) if cv2.waitKey(1) & 0xFF == ord("q"): break cap.release() cv2.destroyAllWindows() </syntaxhighlight> : 如果你願意,我也可以幫你把: * 完整版 1~10 台灣手勢判斷函式 抽成一個獨立 .py(讓學生 import 使用) * 或幫你把上述學習單排成「正式 A4 版(含題號、配分建議)」的文字草稿,再貼進 Word 排版。
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)