Air Keyboard
Air Keyboard
import cv2
import cvzone
from cvzone.HandTrackingModule import HandDetector
from time import sleep
import numpy as np
from pynput.keyboard import Controllercap = cv2.VideoCapture(0) # 获取实时输入
cap.set(3, 1280)
cap.set(4, 720)detector = HandDetector(detectionCon=0.8, maxHands=2)
keyboard_keys = [["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"],["A", "S", "D", "F", "G", "H", "J", "K", "L", ";"],["Z", "X", "C", "V", "B", "N", "M", ",", ".", "/"]]final_text = ""keyboard = Controller() # 初始化键盘控制器def draw(img, buttonList): # 接受两个参数,图像和按钮列表并返回图像for button in buttonList:x, y = button.posw, h = button.size # cornerRect函数在每个键的角落绘制矩阵边缘cvzone.cornerRect(img, (button.pos[0], button.pos[1],button.size[0], button.size[0]), 50, rt=0)cv2.rectangle(img, button.pos, (int(x + w), int(y + h)), (0, 0, 0), cv2.FILLED)cv2.putText(img, button.text, (x + 20, y + 65),cv2.FONT_HERSHEY_PLAIN, 4, (255, 255, 255), 4)return imgdef transparent_layout(img, buttonList): # 自定义键盘imgNew = np.zeros_like(img, np.uint8)for button in buttonList:x, y = button.poscvzone.cornerRect(imgNew, (button.pos[0], button.pos[1],button.size[0], button.size[0]), 50, rt=0)cv2.rectangle(imgNew, button.pos, (x + button.size[0], y + button.size[1]),(0, 0, 0), cv2.FILLED)cv2.putText(imgNew, button.text, (x + 20, y + 65),cv2.FONT_HERSHEY_PLAIN, 4, (255, 255, 255), 4)out = img.copy()alpha = 1mask = imgNew.astype(bool)print(mask.shape)out[mask] = cv2.addWeighted(img, alpha, imgNew, 1-alpha, 0)[mask]return outclass Button(): # 位置 ,文本,大小def __init__(self, pos, text, size=[80, 80]):self.pos = posself.size = sizeself.text = textbuttonList = []
# mybutton = Button([100, 100], "Q")
for k in range(len(keyboard_keys)):for x, key in enumerate(keyboard_keys[k]):buttonList.append(Button([100 * x + 90, 100 * k + 400], key))while True:success, img = cap.read()if success == True:img = cv2.flip(img, 180) # 镜像翻转img = detector.findHands(img)lmList, bboxInfo = detector.findPosition(img)img = draw(img, buttonList) # change the draw funtion to transparent_layout for transparent keysif lmList:for button in buttonList:x, y = button.posw, h = button.sizeif x < lmList[8][0]<x+w and y < lmList[8][1] < y+h:cv2.rectangle(img, button.pos, (x + w, y + h),(0, 255, 255), cv2.FILLED)cv2.putText(img, button.text, (x + 20, y + 65),cv2.FONT_HERSHEY_PLAIN, 4, (0, 0, 0), 4)l, _, _ = detector.findDistance(8,12, img, draw=False) # 食指和中指之间的定点之间的距离print(l)if l < 25: # 点之间的距离非常小,可以使用press()FQH函数来按下按键keyboard.press(button.text) # button.text显示按下的键cv2.rectangle(img, button.pos, (x + w, y + h),(0, 255, 0), cv2.FILLED)cv2.putText(img, button.text, (x + 120, y + 165),cv2.FONT_HERSHEY_PLAIN, 4, (0, 0, 0), 4)final_text += button.textsleep(0.50)#cv2.rectangle(img, (25,350), (700, 450),# (255, 255, 255), cv2.FILLED)#cv2.putText(img, final_text, (60, 425),# cv2.FONT_HERSHEY_PLAIN, 4, (0, 0, 0), 4)# cv2.rectangle(img, (100,100), (200,200),# (100, 255, 0), cv2.FILLED)# cv2.putText(img, 'Q', (120,180), cv2.FONT_HERSHEY_PLAIN, 5,# (0, 0, 0), 5)# img = mybutton.draw(img)cv2.imshow("Air Keyboard", img)if cv2.waitKey(1) & 0xFF == ord(' '):break
Air Keyboard相关推荐
- 装了激光雷达的iPad Pro,还能用鼠标了:苹果新键盘、新iPad Pro、新MacBook Air来了...
鱼羊 发自 凹非寺 量子位 报道 | 公众号 QbitAI iPad Pro也装上激光雷达了. 苹果产品,再次上新,带来终于可以用"鼠标"的新一代iPad Pro,和终于256G起 ...
- 使用air进行移动app开发常见功能和问题(二)
1. Air如何判断android.ios 平台网络连接状态? Android,使用as3原生api: [javascript] view plaincopy if(NetworkInfo.isSu ...
- AIR中文帮助 第十章. 窗体(Windows)和菜单
屏幕 根据AIR screen API可以获得系统桌面显示屏幕的信息. 屏幕简介 screen API包含一个简单类,Screen,获得系统屏幕信息和屏幕的详细描述. 计算机系统可能有多个监视器或显示 ...
- Notes on how to use Webots, especially how to make a robot fly in the air
How to create a new project Wizard - New project directory Scene Tree Scene tree is a representation ...
- 苹果推出新款iPad Air和iPad mini,升级A12处理器
新iPad均支持一代Apple Pencil进行笔触操作,新款iPad Air还支持Smart Keyboard,屏幕都是全贴合设计. 提起iPad Air和iPad mini这两款设备,大家都不陌生 ...
- air android 后台运行,AIR Android:使用模拟器运行程序
安装和运行程序 生成apk包后,对开发者来说还有一个重要的环节,那就是把程序放在设备上运行起来.这一节我们将分别在模拟器和真机上运行FlipIt游戏,看看效果如何. 使用模拟器运行程序(1) 使用An ...
- 破天荒!苹果终于对 MacBook Air 大更新,还有全新 iPad Pro 和 Mac mini
本文由 I/O 与 王刚 合作完成. 2018 年对于苹果的 iPad 来说,是一个特殊的年份,因为苹果罕见地在同一年为这一产品线举办了两场发布会,而且这两场发布会都不在硅谷.第一场举行于 2018 ...
- 苹果推出新款iPad Air和iPad mini,升级A12处理器 1
新iPad均支持一代Apple Pencil进行笔触操作,新款iPad Air还支持Smart Keyboard,屏幕都是全贴合设计. 提起iPad Air和iPad mini这两款设备,大家都不陌生 ...
- Flex Air 实现桌面尺子(Ruler)工具
最近在使用Flex Air写桌面应用,因为有个测量的需求,就想着自己写个尺子来用.经过琢磨,写了个简陋版,希望大家指正. 先上图: 以下是代码: <?xml version="1.0& ...
- adobe air 工程师_了解Adobe AIR,第I部分:构建Note存储应用
adobe air 工程师 The Adobe Integrated Runtime (AIR) platform changes the game for web developers, takin ...
最新文章
- C 入门 第八节 指针
- 写给那些在技术路上奔跑的人们!!!!!
- java double框架简介
- MATLAB作二维傅里叶变换所需要注意和知道的东西(im2double、fft2、abs、imshow、二维傅里叶变换的物理意义)
- 眼界大开 声临其境丨胡宜峰:视频深度伪造检测技术在内容安全领域的探索与实践
- ABAP 在被访问的程序中获取访问程序的全局变量
- 中科院单细胞分析算法开发博士带你做单细胞转录组分析
- Java CyclicBarrier介绍
- ceph rbd双挂载导致ext4文件系统inode链接数据污染
- android每秒 1,在Android 5.1中调度每秒的警报
- 学计算机要学工图吗,工程图学及计算机绘图: 非机类
- 多媒体前端技术入门指南
- 运行bat时隐藏cmd窗口的方法(bat隐藏窗口 隐藏运行bat文件)
- 董明珠接连直播背后:格力的线上焦虑
- 冰桶挑战”的火爆程度与朋友圈?
- 深扒人脸识别技术,原理、算法深度解析
- MSP430初学:MSP430单片机C语言基础(二)
- antd右侧菜单栏点击更换icon
- Java第三天笔记01——流程控制语句
- 为什么一般公司面试结束后会说「回去等消息」,而不是直接告诉面试者结果?
热门文章
- 网络和计算机加密驱动,如何解决笔记本电脑连接不上加密无线网络的问题
- python把英语句子成分字母_英语基础(一)句子成分和结构
- 能让你「情商暴涨」的6个聊天小技巧
- fprom预测结果内容_启动子分析预测数据库
- 小米允许安装未知来源不用sim卡_视频能独立通话的小米手表,会像小米手机一样好用吗?...
- javascript调用php函数_JavaScript怎么调用PHP函数?
- 短视频如何有效涨粉?三个小技巧来帮忙,吸粉引流也不难
- Win10登陆界面卡住,进去后无法打开网络相关的设置,谷歌浏览器无法上网
- 自家主机建云服务器_用云主机还是自己建服务器好
- F - Pasha and Phone CodeForces - 595B(数学)