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!
==== 這一版是「刻意留空」,讓學生填入距離 / 角度 / 判斷條件。 ==== 你可以把 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> :
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)