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!
=== : === ==== <syntaxhighlight lang="python"># taiwan_numbers.py ==== === 台灣 1~10 手勢辨識函式庫(給教師 import 使用) === def euclidean(a, b): return ((a[0]-b[0])'''2 + (a[1]-b[1])'''2)'''0.5 def one_or_nine(hand): """ 區別 1 和 9 (pattern 相同,需要判斷彎曲) """ lm = hand["lmList"] mcp = lm[5] pip = lm[6] dip = lm[7] tip = lm[8] d_mcp_tip = euclidean((mcp[0],mcp[1]), (tip[0],tip[1])) poly = ( euclidean((mcp[0],mcp[1]), (pip[0],pip[1])) + euclidean((pip[0],pip[1]), (dip[0],dip[1])) + euclidean((dip[0],dip[1]), (tip[0],tip[1])) ) if d_mcp_tip > 0 and poly / d_mcp_tip > 1.25: return 9, "9" return 1, "1" def taiwan_number(hand, detector): """ 傳入:hand(CVZone hand dict)、detector 回傳:數字, 數字字串 """ fingers = detector.fingersUp(hand) pattern = tuple(fingers) mapping = { (0,1,1,0,0): 2, (1,1,1,0,0): 3, (0,1,1,1,1): 4, (1,1,1,1,1): 5, (1,0,0,0,1): 6, (1,1,0,0,1): 7, (1,1,0,0,0): 8, } if pattern in mapping: n = mapping[pattern] return n, str(n) # pattern 用來判斷 1 / 9 if pattern == (0, 1, 0, 0, 0): return one_or_nine(hand) return None, "Unknown" def taiwan_number_allhands(hands, detector): """ 若兩手都是 5 → 回傳 10 否則只看第一手 """ if len(hands) >= 2: n1, _ = taiwan_number(hands[0], detector) n2, _ = taiwan_number(hands[1], detector) if n1 == 5 and n2 == 5: return 10, "10" return taiwan_number(hands[0], detector) </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)