我就像一个笑话

人生意义在何

虚无、空洞、付出了所有到头来都是一个笑话

这世间或许太过肮脏,而我一直都在自欺欺人。生活从来只是你一个人的事情,任何将寄托放到别人身上的行为终将自毁前程

无休止的浮躁,早已消磨了最初那个踏踏实实的刘桢,自己褪掉了所有盔甲,再想重拾本心何其艰难

"""
    当前我们使用Mediapipe的解决方案
    solutions pose /hand / face / selfie_segmentation
"""
import cv2
import mediapipe as mp
class Hand:
    def __init__(self):
        mpHands = mp.solutions.hands
        self.hands = mpHands.Hands()
        self.img = None
        # 保存左手关键点
        self.leftLandmark = []
    def process(self, img):
        self.img = img
		# 绘制关键点样式 获取关键点
        self.drawLineStyle()
		# 如果没有检测到关键点不需要继续执行
        if len(self.leftLandmark) == 0:
            return
		# 绘制关键点序号
        self.drawPointNum()
        self.gestureNumDetect()

    def drawLineStyle(self):
        img = self.img
        hands = self.hands
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
		# Processes an RGB image and returns the hand landmarks and handedness of each detected hand.
        result = hands.process(imgRGB)
		# 如果没有识别到手部不需要继续执行
        if not result.multi_hand_landmarks:
            return

        conn = mp.solutions.hands_connections
        pointStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0, 255), thickness=2)
        lineStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0, 255), thickness=2)
        hand_landmarks = result.multi_hand_landmarks[0]
        self.leftLandmark = hand_landmarks.landmark     # 保存左手的关键点
        mp.solutions.drawing_utils.draw_landmarks(img,hand_landmarks,conn.HAND_CONNECTIONS,pointStyle,lineStyle)

    def drawPointNum(self):    #绘制关键点的序号
        for idx, lm in enumerate(self.leftLandmark):    # 遍历关键点进行绘制
            x, y = self.indexCvPoint(idx)
            cv2.putText(self.img, str(idx), org=(x - 15, y - 5), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.3, color=(0, 255, 0), thickness=1)
    def indexCvPoint(self, index):
        imgH, imgW = self.img.shape[:2]
        lm = self.leftLandmark[index]    # 通过索引将关键点转换到对应的屏幕坐标
        x = int(lm.x * imgW)
        y = int(lm.y * imgH)
        return x, y



'''  
    手势数字识别

'''
    def gestureNumDetect(self):
        for i in range(2,21,2):
            pointMaxY = self.indexCvPoint
        # point20Y = self.indexCvPoint(20)[1]
        # point18Y = self.indexCvPoint(18)[1]
        # point16Y = self.indexCvPoint(16)[1]
        # point14Y = self.indexCvPoint(14)[1]
        # point12Y = self.indexCvPoint(12)[1]
        # point10Y = self.indexCvPoint(10)[1]
        # point8Y = self.indexCvPoint(8)[1]
        # point6Y = self.indexCvPoint(6)[1]
        point4Y = self.indexCvPoint(4)[1]
        point2Y = self.indexCvPoint(2)[1]
        if point4Y < point2Y and point8Y < point6Y and point12Y < point10Y and point16Y < poin14t and point20Y < point18Y:
            print("0")
        elif point4Y < point2Y and point8Y > point6Y and point12Y < point10Y and point16Y < poin14t and point20Y < point18Y:
            print("1")
        elif point4Y < point2Y and point8Y > point6Y and point12Y > point10Y and point16Y < poin14t and point20Y < point18Y:
            print("2")
        elif point4Y < point2Y and point8Y < point6Y and point12Y > point10Y and point16Y > poin14t and point20Y > point18Y:
            print("3")
        elif point4Y < point2Y and point8Y > point6Y and point12Y > point10Y and point16Y > poin14t and point20Y > point18Y:
            print("4")
        else:
            print("5")

    def gestureNumDectect(self):
        topFigureNums = [4, 8, 12, 16, 20]
        figureStatus = np.zeros((5,), dtype=np.uint8)
        for idx, num in enumerate(topFigureNums):
            if idx == 0:
                topX = self.indexCvPoint(num)[0]
                midX = self.indexCvPoint(num - 1)[0]
                figureStatus[idx] = topX > midX
                continue
            topY = self.indexCvPoint(num)[1]
            midY = self.indexCvPoint(num - 2)[1]
            figureStatus[idx] = topY < midY
        total = np.sum(figureStatus)
        self.showInfo(total)


# 双手数字识别
import cv2
import mediapipe as mp
import numpy as np
import hand_type
class Hand:
    def __init__(self):
        mpHands = mp.solutions.hands
        self.hands = mpHands.Hands()
        self.img = None
        self.leftLandmark = []
        self.rightLandmark = []
        self.mulHands =[]
    def process(self,img):
        img = self.img
        hands = self.hands
        imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
        result = hands.process(imgRGB)
        if not result.multi_hand_landmarks:
            return
        multiHand = []
        self.mulHands = mulHands
        for handedness in result.multi_handedness:
			for classification in handedness.classification:
				# 判断左手或者右手只能出现一次
				if classification.label not in mulHands:
					mulHands.append(classification.label)

			for idx, handType in enumerate(mulHands):
				isRight = handType == hand_type.RIGHT_HAND_TYPE
				if isRight:
					hand_landmarks = result.multi_hand_landmarks[idx]
					conn = mp.solutions.hands_connections
					pointStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 255, 0), thickness=2)
					lineStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 255, 0), thickness=2)

					self.rightLandmark = hand_landmarks.landmark	# 保存右手的关键点
					hand_landmarks = result.multi_hand_landmarks[idx]
					conn = mp.solutions.hands_connections
					pointStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0,
255), thickness=2)
					lineStyle = mp.solutions.drawing_utils.DrawingSpec(color=(0, 0,
255), thickness=2)
					self.leftLandmark = hand_landmarks.landmark
					mp.solutions.drawing_utils.draw_landmarks(img,hand_landmarks,conn.HAND_CONNECTIONS,pointStyle,lineStyle)
	def gestureNumDectect(self, isRight=True):
		topFigureNums = [4, 8, 12, 16, 20]
        figureStatus = np.zeros((5,), dtype=np.uint8)
        for idx, num in enumerate(topFigureNums):
            if idx == 0:
                topX = self.indexCvPoint(num)[0]
                midX = self.indexCvPoint(num - 1)[0]
                figureStatus[idx] = topX > midX
                continue
            topY = self.indexCvPoint(num)[1]
            midY = self.indexCvPoint(num - 2)[1]
            figureStatus[idx] = topY < midY
        total = np.sum(figureStatus)
        self.showInfo(total)
        
	def drawPointNum(self,isRight=True):    #绘制关键点的序号
        if isRight:
            landmark = self.rightLandmark
            color = (0,0,255)
        else:
            lanmark = self.leftLandmark
        	color = (0,0,255)
        for idx, lm in enumerate(landmark):    # 遍历关键点进行绘制
            x, y = self.indexCvPoint(idx,isRight)
            cv2.putText(self.img, str(idx), org=(x - 15, y - 5), fontFace=cv2.FONT_HERSHEY_SIMPLEX, fontScale=0.3, color=(0, 255, 0), thickness=1)
    
    
    def indexCvPoint(self, index, isRight=True):
        if isRight:
            landmark = self.rightLandmark
        else:
            lanmark = self.leftLandmark
        imgH, imgW = self.img.shape[:2]
        lm = landmark[index]    # 通过索引将关键点转换到对应的屏幕坐标
        x = int(lm.x * imgW)
        y = int(lm.y * imgH)
        return x, y
    def showInfo(self, info, color=(0, 0, 255), org=(50, 100), fontScale=3, thickness=2):
		cv2.putText(self.img,str(info),org=org,fontFace=cv2.FONT_HERSHEY_SIMPLEX,
fontScale=fontScale,color=color,thickness=thickness)

没有意义了

猜你喜欢

转载自blog.csdn.net/weixin_44659309/article/details/129905990