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!
==== 設計概念: ==== * 螢幕左上角顯示:「請比出: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)