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!
==== 這支程式會: ==== * 用 cvzone.HandTrackingModule.HandDetector 偵測手 * 取得 hand["lmList"](長度 21 的 list,每個是 [x, y, z]) * 在畫面上: - 把 21 個點畫出來 - 每個點旁邊標上編號 0~20 * 在終端機印出其中幾個重點點位(例如手腕 0、拇指尖 4、食指尖 8…) 非常適合拿來教學生「手部關節座標」跟後續自己算角度、距離。 ==== <syntaxhighlight lang="python">from cvzone.HandTrackingModule import HandDetector ==== import cv2 === 開啟攝影機(如有需要可改成 cv2.VideoCapture(0, cv2.CAP_DSHOW)) === cap = cv2.VideoCapture(0) === 建立手部偵測器 === detector = HandDetector(detectionCon=0.7, maxHands=1) while True: success, img = cap.read() if not success: break # 偵測手部,hands 會是一個 list,裡面每隻手是一個 dict hands, img = detector.findHands(img) # img 會自動畫出骨架 if hands: # 只拿第一隻手 hand = hands[0] # lmList:21 個 landmark 的座標,每個元素是 [x, y, z] lmList = hand["lmList"] # 長度 21 bbox = hand["bbox"] # [x, y, w, h] center = hand["center"] # 手掌中心點 [cx, cy] handType = hand["type"] # "Left" or "Right" # 在畫面左上角顯示手的類型 cv2.putText(img, handType, (10, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 2) # 把 21 個點畫出來並標上 index for i, lm in enumerate(lmList): x, y, z = lm # 畫一個小圓點 cv2.circle(img, (x, y), 5, (0, 0, 255), cv2.FILLED) # 在旁邊寫上編號 cv2.putText(img, str(i), (x + 5, y - 5), cv2.FONT_HERSHEY_PLAIN, 1, (255, 255, 0), 1) # 也可以在終端機印出幾個重點 landmark wrist = lmList[0] # 手腕 thumb_tip = lmList[4] # 拇指尖 index_tip = lmList[8] # 食指尖 middle_tip = lmList[12] # 中指尖 print("手型:", handType) print("手腕(0):", wrist) print("拇指尖(4):", thumb_tip) print("食指尖(8):", index_tip) print("中指尖(12):", middle_tip) print("-" * 30) cv2.imshow("Hand 21 Landmarks (CVZone)", 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)