360网站推广电话,网站制作 徐州,网站中有一个非常著名的原则,成都哪家公司做网站比较好演示效果 需要安装的第三方库#xff1a; pip install pygame # 加载音乐 pip install pillow # 加载图片 pip install mediapipe # 判断手势的模型 pip install opencv # 模型要用来处理图形
建议有独显和摄像头的可以尝试#xff01; 想着升级一下玩法#xff0c;只有真敲…演示效果 需要安装的第三方库 pip install pygame # 加载音乐 pip install pillow # 加载图片 pip install mediapipe # 判断手势的模型 pip install opencv # 模型要用来处理图形
建议有独显和摄像头的可以尝试 想着升级一下玩法只有真敲才能真积徳于是找了个能判断手势的模型。
源码开启摄像头后按Q退出
import time
import tkinter
from tkinter import messagebox
import threading
import pygame # pip install pygame
from PIL import Image, ImageTk # pip install pillowclass window(tkinter.Tk):def __init__(self):super().__init__()# 初始化功德self.gongde0# 准备音频self.pygamepygameself.pygame.mixer.init()self.pygame.mixer.music.load(敲.mp3)# 准备图片self.qiaomuyutupianImageTk.PhotoImage(file敲木鱼.jpg) # 转化为tkinter可以使用的图片self.qiaomuyutupian2ImageTk.PhotoImage(file敲木鱼2.jpg) # 转化为tkinter可以使用的图片# 启动界面self.base_top()def base_top(self):self.title(敲木鱼加功德)self.geometry(410x400)self.configure(bgblack)# 标签self.label1tkinter.Label(self,text积攒功德str(self.gongde),font(华文新魏,15),fgwhite,bgblack,width18)self.label1.place(x100,y70)# 按钮self.button1tkinter.Button(self,imageself.qiaomuyutupian,reliefridge,commandself.qiaomuyu)self.button1.place(x100,y100)# 按钮self.button2tkinter.Button(self,text互动,width10,commandself.thread_hudong)self.button2.place(x160,y315)# 消息self.text1tkinter.Text(self,width10,height5,bgblack,bd0,foregroundwhite)self.text1.place(x125,y115)def showplus(self):# 文字浮动for i in range(4):self.text1.insert(insert, \n)else:self.text1.insert(insert, 功德 1)for i in range(5):time.sleep(0.04)self.text1.delete(1.0, 2.0)# 功德1self.gongdeself.gongde1self.label1.config(text积攒功德str(self.gongde))def changetupian(self):self.button1.config(imageself.qiaomuyutupian2)time.sleep(0.1)self.button1.config(imageself.qiaomuyutupian)def qiaomuyu(self):# 多线程启动解决延时虽然延迟足够小但为了更有效果ththreading.Thread(targetself.pygame.mixer.music.play)th.start()th2threading.Thread(targetself.showplus)th2.start()th3threading.Thread(targetself.changetupian)th3.start()def thread_hudong(self):th4threading.Thread(targetself.hudong)th4.start()self.frametkinter.Frame(self,width200,height40,bgwhite)self.frame.place(x103,y350)self.label2tkinter.Label(self.frame,text正在摄像头中请稍等...,bgwhite)self.label2.place(x33,y10)def hudong(self):import cv2import mediapipe as mpmp_hands mp.solutions.handshands mp_hands.Hands()mp_drawing mp.solutions.drawing_utils# coding:utf-8cap cv2.VideoCapture(0) # 打开摄像头mark_one0while True:self.frame.destroy()ret, frame cap.read() # 读取视频帧if not ret:breakimage cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) # 转换颜色空间results hands.process(image) # 手势识别# 处理识别结果if results.multi_hand_landmarks:for hand_landmarks in results.multi_hand_landmarks:mp_drawing.draw_landmarks(frame,hand_landmarks,mp_hands.HAND_CONNECTIONS) # 用于指定地标如何在图中连接。for point in hand_landmarks.landmark:x int(point.x * frame.shape[1])y int(point.y * frame.shape[0])if y 200:mark_one1if y 400:if 1 - mark_one 0:self.qiaomuyu()mark_one0cv2.circle(frame, (x, y), 5, (0, 255, 0), -1) # 画出关键点cv2.imshow(Gesture Recognition, frame) # 显示结果if cv2.waitKey(1) 0xFF ord(q):breakcap.release()cv2.destroyAllWindows()if __name__ __main__:topwindow()top.mainloop()