中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁(yè) > news >正文

懷集建設(shè)房管部門網(wǎng)站淘寶美工培訓(xùn)

懷集建設(shè)房管部門網(wǎng)站,淘寶美工培訓(xùn),b2c商城物流模式的比較分析,wordpress 訪問(wèn)日志文件原文:MindPythonMediapipe項(xiàng)目——AI健身之跳繩 - DF創(chuàng)客社區(qū) - 分享創(chuàng)造的喜悅 【項(xiàng)目背景】跳繩是一個(gè)很好的健身項(xiàng)目,為了獲知所跳個(gè)數(shù),有的跳繩上會(huì)有計(jì)數(shù)器。但這也只能跳完這后看到,能不能在跳的過(guò)程中就能看到,…

原文:Mind+Python+Mediapipe項(xiàng)目——AI健身之跳繩 - DF創(chuàng)客社區(qū) - 分享創(chuàng)造的喜悅

【項(xiàng)目背景】
跳繩是一個(gè)很好的健身項(xiàng)目,為了獲知所跳個(gè)數(shù),有的跳繩上會(huì)有計(jì)數(shù)器。但這也只能跳完這后看到,能不能在跳的過(guò)程中就能看到,這樣能讓我們堅(jiān)持跳的更多,更有趣味性。
【項(xiàng)目設(shè)計(jì)】

通過(guò)Mind+Python模式下加載Google的開(kāi)源Mediapipe人工智能算法庫(kù),識(shí)別人體姿態(tài),來(lái)判斷跳繩次數(shù),并通過(guò)Pinpong庫(kù)控制LED燈實(shí)時(shí)顯示次數(shù)。
【測(cè)試程序】
測(cè)試程序中,使用人體姿態(tài)23,24兩坐標(biāo)點(diǎn)中點(diǎn)與標(biāo)準(zhǔn)點(diǎn)的比較來(lái)確認(rèn)跳繩完成程度。
 
  1. import numpy as np
  2. import time
  3. import cv2
  4. import PoseModule as pm
  5. cap = cv2.VideoCapture("tiaosheng.mp4")
  6. detector = pm.poseDetector()
  7. count = 0
  8. dir = 0
  9. pTime = 0
  10. success=True
  11. point_sd=0
  12. while success:
  13. ??success, img = cap.read()
  14. ??if success:
  15. ? ? img = cv2.resize(img, (640, 480))
  16. ? ? img = detector.findPose(img, False)
  17. ? ? lmList = detector.findPosition(img, False)
  18. ? ?
  19. ? ? if len(lmList) != 0:
  20. ? ?? ???
  21. ? ?? ???point = detector.midpoint(img, 24, 23)
  22. ? ?? ???if point_sd==0:
  23. ? ?? ?? ?? ?point_sd=point
  24. ? ?? ?? ?? ?print(point_sd["y"])
  25. ? ?? ???# 計(jì)算個(gè)數(shù)
  26. ? ?? ???print(point["y"])
  27. ? ?? ???if point["y"]> point_sd["y"]+15:
  28. ? ?? ?? ?
  29. ? ?? ?? ?? ?if dir == 0:
  30. ? ?? ?? ?? ?? ? count += 0.5
  31. ? ?? ?? ?? ?? ? dir = 1
  32. ? ?? ???if point["y"]<point_sd["y"]+5:
  33. ? ?? ???
  34. ? ?? ?? ?? ?if dir == 1:
  35. ? ?? ?? ?? ?? ? count += 0.5
  36. ? ?? ?? ?? ?? ? dir = 0
  37. ? ?? ???#print(count)
  38. ? ?? ???cv2.putText(img, str(int(count)), (45, 460), cv2.FONT_HERSHEY_PLAIN, 7,(255, 0, 0), 8)
  39. ? ? cTime = time.time()
  40. ? ? fps = 1 / (cTime - pTime)
  41. ? ? pTime = cTime
  42. ? ? cv2.putText(img, str(int(fps)), (50, 100), cv2.FONT_HERSHEY_PLAIN, 5,(255, 0, 0), 5)
  43. ? ? cv2.imshow("Image", img)
  44. ? ? cv2.waitKey(1)
復(fù)制代碼
【PoseModule.py】

上面程序用到的“PoseModule.py”文件中,在”poseDetector“類中增加了“midpoint”函數(shù),用于求兩點(diǎn)的中點(diǎn)坐標(biāo)。
 
  1. import math
  2. import mediapipe as mp
  3. import cv2
  4. class poseDetector():
  5. ? ? def __init__(self, mode=False, upBody=False, smooth=True,
  6. ? ?? ?? ?? ?? ???detectionCon=0.5, trackCon=0.5):
  7. ? ?? ???self.mode = mode
  8. ? ?? ???self.upBody = upBody
  9. ? ?? ???self.smooth = smooth
  10. ? ?? ???self.detectionCon = detectionCon
  11. ? ?? ???self.trackCon = trackCon
  12. ? ?? ???self.mpDraw = mp.solutions.drawing_utils
  13. ? ?? ???self.mpPose = mp.solutions.pose
  14. ? ?? ???self.pose = self.mpPose.Pose(self.mode, self.upBody, self.smooth,
  15. ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? self.detectionCon, self.trackCon)
  16. ? ? def findPose(self, img, draw=True):
  17. ? ?? ???imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  18. ? ?? ???self.results = self.pose.process(imgRGB)
  19. ? ?? ???if self.results.pose_landmarks:
  20. ? ?? ?? ?? ?if draw:
  21. ? ?? ?? ?? ?? ? self.mpDraw.draw_landmarks(img, self.results.pose_landmarks,
  22. ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? self.mpPose.POSE_CONNECTIONS)
  23. ? ?? ???return img
  24. ? ? def findPosition(self, img, draw=True):
  25. ? ?? ???self.lmList = []
  26. ? ?? ???if self.results.pose_landmarks:
  27. ? ?? ?? ?? ?for id, lm in enumerate(self.results.pose_landmarks.landmark):
  28. ? ?? ?? ?? ?? ? h, w, c = img.shape
  29. ? ?? ?? ?? ?? ? # print(id, lm)
  30. ? ?? ?? ?? ?? ? cx, cy = int(lm.x * w), int(lm.y * h)
  31. ? ?? ?? ?? ?? ? self.lmList.append([id, cx, cy])
  32. ? ?? ?? ?? ?? ? if draw:
  33. ? ?? ?? ?? ?? ?? ???cv2.circle(img, (cx, cy), 5, (255, 0, 0), cv2.FILLED)
  34. ? ?? ???return self.lmList
  35. ? ? def midpoint(self,img,p1,p2,draw=True):
  36. ? ?? ???x1, y1 = self.lmList[p1][1:]
  37. ? ?? ???x2, y2 = self.lmList[p2][1:]
  38. ? ?? ???x3=int((x1+x2)/2)
  39. ? ?? ???y3=int((y1+y2)/2)
  40. ? ?? ???if draw:
  41. ? ?? ?? ?cv2.circle(img, (x3, y3), 10, (0, 0, 255), cv2.FILLED)
  42. ? ?? ?? ?cv2.circle(img, (x3, y3), 15, (0, 0, 255), 2)
  43. ? ?? ???point={"x":x3,"y":y3}
  44. ? ?? ???return point
  45. ? ? def findAngle(self, img, p1, p2, p3, draw=True):
  46. ? ?? ???# Get the landmarks
  47. ? ?? ???x1, y1 = self.lmList[p1][1:]
  48. ? ?? ???x2, y2 = self.lmList[p2][1:]
  49. ? ?? ???x3, y3 = self.lmList[p3][1:]
  50. ? ?? ???# Calculate the Angle
  51. ? ?? ???angle = math.degrees(math.atan2(y3 - y2, x3 - x2) -
  52. ? ?? ?? ?? ?? ?? ?? ?? ?? ???math.atan2(y1 - y2, x1 - x2))
  53. ? ?? ???if angle < 0:
  54. ? ?? ?? ?? ?angle += 360
  55. ? ?? ???# print(angle)
  56. ? ?? ???# Draw
  57. ? ?? ???if draw:
  58. ? ?? ?? ?? ?cv2.line(img, (x1, y1), (x2, y2), (255, 255, 255), 3)
  59. ? ?? ?? ?? ?cv2.line(img, (x3, y3), (x2, y2), (255, 255, 255), 3)
  60. ? ?? ?? ?? ?cv2.circle(img, (x1, y1), 10, (0, 0, 255), cv2.FILLED)
  61. ? ?? ?? ?? ?cv2.circle(img, (x1, y1), 15, (0, 0, 255), 2)
  62. ? ?? ?? ?? ?cv2.circle(img, (x2, y2), 10, (0, 0, 255), cv2.FILLED)
  63. ? ?? ?? ?? ?cv2.circle(img, (x2, y2), 15, (0, 0, 255), 2)
  64. ? ?? ?? ?? ?cv2.circle(img, (x3, y3), 10, (0, 0, 255), cv2.FILLED)
  65. ? ?? ?? ?? ?cv2.circle(img, (x3, y3), 15, (0, 0, 255), 2)
  66. ? ?? ?? ?? ?cv2.putText(img, str(int(angle)), (x2 - 50, y2 + 50),
  67. ? ?? ?? ?? ?? ?? ?? ?? ?cv2.FONT_HERSHEY_PLAIN, 2, (0, 0, 255), 2)
  68. ? ?? ???return angle
復(fù)制代碼
【測(cè)試網(wǎng)絡(luò)視頻】

【存在的問(wèn)題】
測(cè)試結(jié)果令人比較滿意,但這里存在這樣兩個(gè)問(wèn)題:1、標(biāo)準(zhǔn)點(diǎn)point_sd這個(gè)坐標(biāo)是以視頻開(kāi)始第一幀畫面是站在原地未起跳為前提。
2、標(biāo)準(zhǔn)點(diǎn)縱坐標(biāo)的判定區(qū)間(point_sd["y"]+5與 point_sd["y"]+15)是根據(jù)運(yùn)行后的數(shù)據(jù)人為分析出來(lái)的,只對(duì)這一段視頻有效,不具有通用性。
【解決問(wèn)題思路】
1、在正式跳繩計(jì)數(shù)前,先試跳,通過(guò)數(shù)據(jù)分析出標(biāo)準(zhǔn)點(diǎn)、判定區(qū)間(防止數(shù)據(jù)在判定點(diǎn)抖動(dòng),出現(xiàn)錯(cuò)誤計(jì)數(shù))。在上個(gè)程序中判定點(diǎn)為:point_sd["y"]+10。
2、以手勢(shì)控制屏幕上的虛擬按鈕來(lái)分析初始化數(shù)據(jù),并啟動(dòng)跳繩計(jì)數(shù)及終止計(jì)數(shù)。
【解決問(wèn)題步驟】

第一步:實(shí)現(xiàn)手勢(shì)控制屏幕按鈕。
程序中使用了計(jì)時(shí)器,以防止連續(xù)觸發(fā)問(wèn)題。
 
  1. import cv2
  2. import numpy as np
  3. import time
  4. import os
  5. import HandTrackingModule as htm
  6. #######################
  7. brushThickness = 25
  8. eraserThickness = 100
  9. ########################
  10. drawColor = (255, 0, 255)
  11. cap = cv2.VideoCapture(0)
  12. cap.set(3, 640)
  13. cap.set(4, 480)
  14. detector = htm.handDetector(detectionCon=0.65,maxHands=1)
  15. imgCanvas = np.zeros((480, 640, 3), np.uint8)
  16. rect=[(20, 20), (120, 120)]
  17. font = cv2.FONT_HERSHEY_SIMPLEX
  18. cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  19. cv2.putText(imgCanvas, "SET", (45,85), font, 1, drawColor, 2)
  20. bs=0
  21. bs2=0
  22. while True:
  23. # 1. Import image
  24. success, img = cap.read()
  25. if success:
  26. ??img = cv2.flip(img, 1)
  27. # 2. Find Hand Landmarks
  28. ??img = detector.findHands(img)
  29. ??lmList = detector.findPosition(img, draw=False)
  30. ??
  31. ??if len(lmList) !=0:
  32. ??
  33. # tip of index and middle fingers
  34. ? ?x1, y1 = lmList[8][1:]
  35. ? ?x2, y2 = lmList[12][1:]
  36. # 3. Check which fingers are up
  37. ? ?fingers = detector.fingersUp()
  38. # print(fingers)
  39. # 5.??Index finger is up
  40. ? ?if fingers[1] and fingers[2] == False:
  41. ? ? cv2.circle(img, (x1, y1), 15, drawColor, cv2.FILLED)
  42. ? ? if bs2==1:
  43. ? ?? ?if time.time()-time_start>3:
  44. ? ?? ?? ?bs2=0
  45. ? ? else:? ?? ?
  46. ? ???if x1>rect[0][0] and x1<rect[1][0] and y1>rect[0][1] and y1<rect[1][1]:
  47. ? ?? ?if bs==0:
  48. ? ?? ? print("OK")
  49. ? ?? ? imgCanvas = np.zeros((480, 640, 3), np.uint8)
  50. ? ?? ? cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  51. ? ?? ? cv2.putText(imgCanvas, "STOP", (30,85), font, 1, drawColor, 2)
  52. ? ?? ? bs=1
  53. ? ?? ? bs2=1
  54. ? ?? ? time_start=time.time()
  55. ? ?? ?else:
  56. ? ?? ? imgCanvas = np.zeros((480, 640, 3), np.uint8)
  57. ? ?
  58. ??imgGray = cv2.cvtColor(imgCanvas, cv2.COLOR_BGR2GRAY)
  59. ??
  60. ??img = cv2.bitwise_or(img,imgCanvas)
  61. # img = cv2.addWeighted(img,0.5,imgCanvas,0.5,0)
  62. ??cv2.imshow("Image", img)
  63. ??cv2.waitKey(1)
復(fù)制代碼

上面程序引用的“HandTrackingModule.py”文件。
 
  1. import cv2
  2. import mediapipe as mp
  3. import time
  4. import math
  5. import numpy as np
  6. class handDetector():
  7. ? ? def __init__(self, mode=False, maxHands=2, detectionCon=0.8, trackCon=0.5):
  8. ? ?? ???self.mode = mode
  9. ? ?? ???self.maxHands = maxHands
  10. ? ?? ???self.detectionCon = detectionCon
  11. ? ?? ???self.trackCon = trackCon
  12. ? ?? ???self.mpHands = mp.solutions.hands
  13. ? ?? ???self.hands = self.mpHands.Hands(self.mode, self.maxHands,
  14. ? ?? ???self.detectionCon, self.trackCon)
  15. ? ?? ???self.mpDraw = mp.solutions.drawing_utils
  16. ? ?? ???self.tipIds = [4, 8, 12, 16, 20]
  17. ? ? def findHands(self, img, draw=True):
  18. ? ?? ???imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
  19. ? ?? ???self.results = self.hands.process(imgRGB)
  20. ? ? # print(results.multi_hand_landmarks)
  21. ? ?? ???if self.results.multi_hand_landmarks:
  22. ? ?? ?? ?? ?for handLms in self.results.multi_hand_landmarks:
  23. ? ?? ?? ?? ?? ? if draw:
  24. ? ?? ?? ?? ?? ?? ???self.mpDraw.draw_landmarks(img, handLms,
  25. ? ?? ?? ?? ?? ?? ???self.mpHands.HAND_CONNECTIONS)
  26. ? ?? ???return img
  27. ? ? def findPosition(self, img, handNo=0, draw=True):
  28. ? ?? ???xList = []
  29. ? ?? ???yList = []
  30. ? ?? ???bbox = []
  31. ? ?? ???self.lmList = []
  32. ? ?? ???if self.results.multi_hand_landmarks:
  33. ? ?? ?? ?? ?myHand = self.results.multi_hand_landmarks[handNo]
  34. ? ?? ?? ?? ?for id, lm in enumerate(myHand.landmark):
  35. ? ?? ?? ?? ?# print(id, lm)
  36. ? ?? ?? ?? ?? ? h, w, c = img.shape
  37. ? ?? ?? ?? ?? ? cx, cy = int(lm.x * w), int(lm.y * h)
  38. ? ?? ?? ?? ?? ? xList.append(cx)
  39. ? ?? ?? ?? ?? ? yList.append(cy)
  40. ? ?? ?? ?? ?# print(id, cx, cy)
  41. ? ?? ?? ?? ?? ? self.lmList.append([id, cx, cy])
  42. ? ?? ?? ?? ?? ? if draw:
  43. ? ?? ?? ?? ?? ?? ???cv2.circle(img, (cx, cy), 5, (255, 0, 255), cv2.FILLED)
  44. ? ?? ?? ?? ?xmin, xmax = min(xList), max(xList)
  45. ? ?? ?? ?? ?ymin, ymax = min(yList), max(yList)
  46. ? ?? ?? ?? ?bbox = xmin, ymin, xmax, ymax
  47. ? ?? ?? ?? ?if draw:
  48. ? ?? ?? ?? ?? ? cv2.rectangle(img, (xmin - 20, ymin - 20), (xmax + 20, ymax + 20),
  49. ? ?? ???(0, 255, 0), 2)
  50. ? ?? ???return self.lmList
  51. ? ? def fingersUp(self):
  52. ? ?? ???fingers = []
  53. ? ? # Thumb
  54. ? ?? ???if self.lmList[self.tipIds[0]][1] > self.lmList[self.tipIds[0] - 1][1]:
  55. ? ?? ?? ?? ?fingers.append(1)
  56. ? ?? ???else:
  57. ? ?? ?? ?? ?fingers.append(0)
  58. ? ? # Fingers
  59. ? ?? ???for id in range(1, 5):
  60. ? ?? ?? ?? ?if self.lmList[self.tipIds[id]][2] < self.lmList[self.tipIds[id] - 2][2]:
  61. ? ?? ?? ?? ?? ? fingers.append(1)
  62. ? ?? ?? ?? ?else:
  63. ? ?? ?? ?? ?? ? fingers.append(0)
  64. ? ?? ???# totalFingers = fingers.count(1)
  65. ? ?? ???return fingers
  66. ? ? def findDistance(self, p1, p2, img, draw=True,r=15, t=3):
  67. ? ?? ???x1, y1 = self.lmList[p1][1:]
  68. ? ?? ???x2, y2 = self.lmList[p2][1:]
  69. ? ?? ???cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
  70. ? ?? ???if draw:
  71. ? ?? ?? ?? ?cv2.line(img, (x1, y1), (x2, y2), (255, 0, 255), t)
  72. ? ?? ?? ?? ?cv2.circle(img, (x1, y1), r, (255, 0, 255), cv2.FILLED)
  73. ? ?? ?? ?? ?cv2.circle(img, (x2, y2), r, (255, 0, 255), cv2.FILLED)
  74. ? ?? ?? ?? ?cv2.circle(img, (cx, cy), r, (0, 0, 255), cv2.FILLED)
  75. ? ?? ?? ?? ?length = math.hypot(x2 - x1, y2 - y1)
  76. ? ?? ???return length, img, [x1, y1, x2, y2, cx, cy]
復(fù)制代碼第二步,分析數(shù)據(jù),得到判定點(diǎn)縱坐標(biāo)。思路是,坐標(biāo)數(shù)據(jù)是上下波動(dòng),將數(shù)據(jù)中的波峰和波谷分別提取出來(lái)計(jì)算均值,然后取中值,和差值。中值為判定點(diǎn),差值用來(lái)確定判定區(qū)域。波峰和波谷的判定采用的是兩邊數(shù)據(jù)與當(dāng)前數(shù)據(jù)做差值看差值方向,如果方向相反,即為峰值。但這里就存在,Mediapipe識(shí)別準(zhǔn)確度的問(wèn)題,可能在上升或下降的過(guò)程中數(shù)據(jù)不平滑,出現(xiàn)數(shù)據(jù)波動(dòng)。可能在分析時(shí),出現(xiàn)誤判,采集到錯(cuò)誤的峰值。后期可采用濾波算法處理此問(wèn)題。現(xiàn)在看效果,還不錯(cuò)。
 
  1. import numpy as np
  2. import time
  3. import cv2
  4. import PoseModule as pm
  5. import math
  6. def max_min(a):
  7. h = []
  8. l = []
  9. for i in range(1, len(a)-1):
  10. ? ? if(a[i-1] < a[i] and a[i+1] < a[i]):
  11. ? ?? ???h.append(a[i])
  12. ? ? elif(a[i-1] > a[i] and a[i+1] > a[i]):
  13. ? ?? ???l.append(a[i])
  14. if(len(h) == 0):
  15. ? ? h.append(max(a))
  16. if(len(l) == 0):
  17. ? ? l.append(min(a[a.index(max(a)):]))
  18. mid=(np.mean(h)+np.mean(l))/2
  19. print(int(mid),int(np.mean(h)-np.mean(l)))
  20. return(int(mid),int(np.mean(h)-np.mean(l)))
  21. cap = cv2.VideoCapture("tiaosheng.mp4")
  22. detector = pm.poseDetector()
  23. count = 0
  24. dir = 0
  25. pTime = 0
  26. success=True
  27. point=[]
  28. while success:
  29. ??success, img = cap.read()
  30. ??if success:
  31. ? ? img = cv2.resize(img, (640, 480))
  32. ? ? img = detector.findPose(img, False)
  33. ? ? lmList = detector.findPosition(img, False)
  34. ? ?
  35. ? ? if len(lmList) != 0:
  36. ? ?? ???point_tem=detector.midpoint(img, 24, 23)
  37. ? ?? ???point.append(point_tem['y'])
  38. ? ?? ???cv2.putText(img, str(point_tem['y']), (45, 460), cv2.FONT_HERSHEY_PLAIN, 7,(255, 0, 0), 8)
  39. ? ? cTime = time.time()
  40. ? ? fps = 1 / (cTime - pTime)
  41. ? ? pTime = cTime
  42. ? ? cv2.putText(img, str(int(fps)), (50, 100), cv2.FONT_HERSHEY_PLAIN, 5,(255, 0, 0), 5)
  43. ? ? cv2.imshow("Image", img)
  44. ? ? cv2.waitKey(1)
  45. max_min(point)
  46. cap.release()
  47. cv2.destroyAllWindows()
復(fù)制代碼
?
?
最終得到“304 26”為“中值 差值”
?
【完整程序】

將以上分段程序進(jìn)行整合,得到完整程序,并進(jìn)行實(shí)地測(cè)試。(純手工敲碼)
 
  1. import cv2
  2. import numpy as np
  3. import time
  4. import os
  5. import HandTrackingModule as htm
  6. import PoseModule as pm
  7. #計(jì)算判定點(diǎn)
  8. def max_min(a):
  9. h = []
  10. l = []
  11. for i in range(1, len(a)-1):
  12. ? ? if(a[i-1] < a[i] and a[i+1] < a[i]):
  13. ? ?? ???h.append(a[i])
  14. ? ? elif(a[i-1] > a[i] and a[i+1] > a[i]):
  15. ? ?? ???l.append(a[i])
  16. if(len(h) == 0):
  17. ? ? h.append(max(a))
  18. if(len(l) == 0):
  19. ? ? l.append(min(a[a.index(max(a)):]))
  20. mid=(np.mean(h)+np.mean(l))/2
  21. print(int(mid),int(np.mean(h)-np.mean(l)))
  22. return(int(mid),int(np.mean(h)-np.mean(l)))
  23. #######################
  24. brushThickness = 25
  25. eraserThickness = 100
  26. ########################
  27. drawColor = (255, 0, 255)
  28. cap = cv2.VideoCapture(0)
  29. cap.set(3, 640)
  30. cap.set(4, 480)
  31. detector_hand = htm.handDetector(detectionCon=0.65,maxHands=1)
  32. detector_pose = pm.poseDetector()
  33. imgCanvas = np.zeros((480, 640, 3), np.uint8)
  34. rect=[(20, 20), (120, 120)]
  35. font = cv2.FONT_HERSHEY_SIMPLEX
  36. cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  37. cv2.putText(imgCanvas, "SET", (45,85), font, 1, drawColor, 2)
  38. bs=0
  39. bs2=0
  40. bs3=0
  41. point=[]
  42. count=0
  43. pTime = 0
  44. dire=0
  45. while True:
  46. success, img = cap.read()
  47. if success:
  48. ? ?? ?img = cv2.flip(img, 1)
  49. ? ?? ?if bs==1 and bs2==0:
  50. ? ?? ? if bs3==1:
  51. ? ?? ?? ?if time.time()-time_start<4:
  52. ? ?? ?? ? cv2.putText(img, str(3-int(time.time()-time_start)), (300, 240), cv2.FONT_HERSHEY_PLAIN, 10,(255, 255, 0), 5)
  53. ? ?? ?? ?else:
  54. ? ?? ?? ? bs3=0
  55. ? ?? ?? ? time_start=time.time()
  56. ? ?? ? else:
  57. ? ?? ?? ? if time.time()-time_start<11:
  58. ? ?? ?? ?? ?img = detector_pose.findPose(img, False)
  59. ? ?? ?? ?? ?lmList = detector_pose.findPosition(img, False)
  60. ? ?
  61. ? ?? ?? ?? ?if len(lmList) != 0:
  62. ? ?? ?? ?? ?? ? point_tem=detector_pose.midpoint(img, 24, 23)
  63. ? ?? ?? ?? ?? ? point.append(point_tem['y'])
  64. ? ?? ?? ?? ?? ? cv2.putText(img, str(point_tem['y']), (45, 460), cv2.FONT_HERSHEY_PLAIN, 7,(255, 0, 0), 8)
  65. ? ?? ?? ?? ?cv2.putText(img, str(10-int(time.time()-time_start)), (500, 460), cv2.FONT_HERSHEY_PLAIN, 10,(255, 255, 0), 5)
  66. ? ?? ?? ? else:
  67. ? ?? ?? ?? ???point_sd,l=max_min(point)
  68. ? ?? ?? ?? ???bs=2
  69. ? ?? ?? ?? ???cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  70. ? ?? ?? ?? ???cv2.putText(imgCanvas, "START", (30,85), font, 1, drawColor, 2)
  71. ? ?? ?? ?
  72. ? ?? ?if bs==3 and bs2==0:??
  73. ? ?? ? if bs3==1:
  74. ? ?? ?? ?if time.time()-time_start<4:
  75. ? ?? ?? ? cv2.putText(img, str(3-int(time.time()-time_start)), (300, 240), cv2.FONT_HERSHEY_PLAIN, 10,(255, 255, 0), 5)
  76. ? ?? ?? ?else:
  77. ? ?? ?? ? bs3=0
  78. ? ?? ?? ? time_start=time.time()
  79. ? ?? ? else:
  80. ? ?? ?? ? img = detector_pose.findPose(img, False)
  81. ? ?? ?? ? lmList = detector_pose.findPosition(img, False)
  82. ? ?
  83. ? ?? ?? ? if len(lmList) != 0:
  84. ? ?? ?? ?? ?point = detector_pose.midpoint(img, 24, 23)
  85. ? ?? ?? ?? ?if point["y"]> point_sd+l/4:
  86. ? ?? ?? ?
  87. ? ?? ?? ?? ???if dire == 0:
  88. ? ?? ?? ?? ?? ? count += 0.5
  89. ? ?? ?? ?? ?? ? dire = 1
  90. ? ?? ?? ?? ?if point["y"]<point_sd-l/4:
  91. ? ?? ???
  92. ? ?? ?? ?? ???if dire == 1:
  93. ? ?? ?? ?? ?? ? count += 0.5
  94. ? ?? ?? ?? ?? ? dire = 0
  95. ? ?? ?
  96. ? ?? ?? ?? ?cv2.putText(img, str(int(count)), (45, 460), cv2.FONT_HERSHEY_PLAIN, 7,(255, 0, 0), 8)??
  97. ? ?? ?if bs2==1:#等待三秒
  98. ? ?? ?? ?if time.time()-time_start>4:
  99. ? ?? ?? ?? ?bs2=0
  100. ? ?? ?? ?? ?time_start=time.time()
  101. ? ?? ?? ?? ?? ?? ?? ?
  102. ? ?? ?else:
  103. ? ?? ???#手勢(shì)操作
  104. ? ?? ???img = detector_hand.findHands(img)
  105. ? ?? ???lmList = detector_hand.findPosition(img, draw=False)
  106. ? ?? ???if len(lmList) !=0:
  107. ? ?? ?? ?x1, y1 = lmList[8][1:]
  108. ? ?? ?? ?x2, y2 = lmList[12][1:]
  109. ? ?? ?? ?fingers = detector_hand.fingersUp()
  110. ? ?? ?? ?#出示食指
  111. ? ?? ?? ?if fingers[1] and fingers[2] == False:
  112. ? ?? ?? ? cv2.circle(img, (x1, y1), 15, drawColor, cv2.FILLED)? ???
  113. ? ?? ?? ? if x1>rect[0][0] and x1<rect[1][0] and y1>rect[0][1] and y1<rect[1][1]:#食指進(jìn)入按鈕區(qū)域
  114. ? ?? ?? ???if bs==0:
  115. ? ?? ?? ?? ?print("OK")
  116. ? ?? ?? ?? ?imgCanvas = np.zeros((480, 640, 3), np.uint8)
  117. ? ?? ?? ?? ?bs=1
  118. ? ?? ?? ?? ?bs2=1
  119. ? ?? ?? ?? ?bs3=1
  120. ? ?? ?? ?? ?time_start=time.time()
  121. ? ?? ?? ???elif bs==1:
  122. ? ?? ?? ?? ?imgCanvas = np.zeros((480, 640, 3), np.uint8)
  123. ? ?? ?? ?? ?bs2=1
  124. ? ?? ?? ?? ?bs3=1
  125. ? ?? ?? ?? ?time_start=time.time()
  126. ? ?? ?? ???elif bs==2:
  127. ? ?? ?? ?? ?imgCanvas = np.zeros((480, 640, 3), np.uint8)
  128. ? ?? ?? ?? ?cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  129. ? ?? ?? ?? ?cv2.putText(imgCanvas, "STOP", (30,85), font, 1, drawColor, 2)
  130. ? ?? ?? ?? ?bs=3??
  131. ? ?? ?? ?? ?bs2=1
  132. ? ?? ?? ?? ?bs3=1
  133. ? ?? ?? ?? ?time_start=time.time()
  134. ? ?? ?? ???elif bs==3:
  135. ? ?? ?? ?? ?imgCanvas = np.zeros((480, 640, 3), np.uint8)
  136. ? ?? ?? ?? ?cv2.rectangle(imgCanvas, rect[0], rect[1],(0, 255, 0), 2)
  137. ? ?? ?? ?? ?cv2.putText(imgCanvas, "START", (30,85), font, 1, drawColor, 2)
  138. ? ?? ?? ?? ?bs=2??
  139. ? ?? ?? ?? ?bs2=1
  140. ? ?? ?? ?? ?bs3=1
  141. ? ?? ?? ?? ?time_start=time.time()
  142. ? ?? ?cTime = time.time()
  143. ? ?? ?fps = 1 / (cTime - pTime)
  144. ? ?? ?pTime = cTime
  145. ? ?? ?cv2.putText(img, str(int(fps)), (500, 100), cv2.FONT_HERSHEY_PLAIN, 5,(255, 0, 0), 5)
  146. ? ?? ?imgGray = cv2.cvtColor(imgCanvas, cv2.COLOR_BGR2GRAY)
  147. ? ?? ?img = cv2.bitwise_or(img,imgCanvas)
  148. ? ?? ?cv2.imshow("Image", img)
  149. ? ?? ?cv2.waitKey(1)
復(fù)制代碼

【計(jì)數(shù)炫燈】
使用Pinpong庫(kù),連接Micro:bit,控制LED燈隨跳繩次數(shù)增加亮燈數(shù)。



?
http://www.risenshineclean.com/news/39718.html

相關(guān)文章:

  • 江西景德鎮(zhèn)建設(shè)廳網(wǎng)站seo行業(yè)崗位
  • 江西會(huì)昌建設(shè)局網(wǎng)站建站軟件可以不通過(guò)網(wǎng)絡(luò)建設(shè)嗎
  • 網(wǎng)站管理系統(tǒng)后臺(tái)不能發(fā)布文章了網(wǎng)絡(luò)營(yíng)銷顧問(wèn)
  • 石家莊網(wǎng)站制作公司最大的中文搜索引擎
  • 網(wǎng)站設(shè)計(jì)制作系統(tǒng)哪個(gè)好搜索引擎優(yōu)化的根本目的
  • 制作網(wǎng)站哪里好廣告投放方案
  • 網(wǎng)站 切圖中國(guó)疫情最新情況
  • 工業(yè)設(shè)計(jì)和產(chǎn)品設(shè)計(jì)哪個(gè)好seo關(guān)鍵詞優(yōu)化軟件合作
  • 如何查公司的工商注冊(cè)信息網(wǎng)站推廣與優(yōu)化方案
  • 深圳企業(yè)網(wǎng)站制作哪家好百度搜索引擎收錄
  • 做網(wǎng)站人太原網(wǎng)站建設(shè)制作
  • 網(wǎng)站哪個(gè)公司好南寧seo外包要求
  • vue做網(wǎng)站的實(shí)例網(wǎng)絡(luò)培訓(xùn)心得
  • 北關(guān)網(wǎng)站制作百度推廣官方
  • 打字做任務(wù)賺錢的網(wǎng)站什么都不懂能去干運(yùn)營(yíng)嗎
  • 模板網(wǎng)站和定制網(wǎng)站影響排名seo推廣代理
  • 有什么網(wǎng)站可以做初中試題怎么做app推廣和宣傳
  • 做時(shí)時(shí)彩網(wǎng)站百度搜索關(guān)鍵詞排名優(yōu)化技術(shù)
  • 精品課程網(wǎng)站建設(shè)方案安卓aso優(yōu)化工具
  • 有做貨 物的網(wǎng)站嗎今天新聞?lì)^條新聞
  • 建設(shè)什么網(wǎng)站新品推廣活動(dòng)方案
  • 國(guó)內(nèi)做的好的電商網(wǎng)站有哪些方面百度在線使用網(wǎng)頁(yè)版
  • 自己做的網(wǎng)站可以用于百度推廣嗎線上營(yíng)銷推廣方案有哪些
  • nginx wordpress ssl網(wǎng)站排名優(yōu)化外包公司
  • 怎么做監(jiān)測(cè)網(wǎng)站的瀏覽量app推廣地推接單網(wǎng)
  • 溫州網(wǎng)站建設(shè)培訓(xùn)seoul是什么品牌
  • 廣東網(wǎng)站開(kāi)發(fā)搭建搜索推廣競(jìng)價(jià)托管哪家好
  • wordpress指定分類名稱知乎關(guān)鍵詞排名優(yōu)化
  • 湖北做網(wǎng)站的一句話宣傳自己的產(chǎn)品
  • 浙江住建局官方網(wǎng)站上海職業(yè)技能培訓(xùn)機(jī)構(gòu)一覽表