广告

OpenCV手势识别方案--基于米尔全志T527开发板

2024-12-13 米尔电子 阅读:
基于米尔电子MYD-LT527开发板(米尔基于全志 T527开发板)的OpenCV手势识别方案测试

本文将介绍基于米尔电子MYD-LT527开发板(米尔基于全志 T527开发板)的OpenCV手势识别方案测试。摘自优秀创作者-小火苗kPeednc

kPeednc

米尔基于全志T527开发板

一、软件环境安装

1.安装OpenCV

sudo apt-get install libopencv-dev python3-opencvkPeednc

kPeednc

2.安装pip

sudo apt-get install python3-pipkPeednc

kPeednc

OpenCV手势识别步骤kPeednc

1.图像获取:从摄像头或其他图像源获取手部图像。使用OpenCV的VideoCapture类可以捕获视频流,或者使用imread函数加载图像。kPeednc

2.图像预处理:对图像进行预处理,以提高特征提取的准确性。常用的预处理操作包括灰度化、滤波、边缘检测、二值化、噪声去除和形态学处理等。kPeednc

灰度化:将彩色图像转换为灰度图像,去除颜色信息,简化图像。kPeednc

滤波:使用滤波器去除图像中的噪声。kPeednc

边缘检测:使用边缘检测算法提取图像中的边缘信息。kPeednc

二值化:将灰度图像转换为二值图像,将像素值分为黑色和白色。kPeednc

形态学处理:使用形态学操作增强手势轮廓。kPeednc

3.特征提取:从预处理后的图像中提取手部特征。常用的特征包括形状特征、纹理特征和运动轨迹特征等。kPeednc

形状特征:提取手部轮廓、面积、周长、质心等形状特征。kPeednc

纹理特征:提取手部皮肤纹理、皱纹等纹理特征。kPeednc

运动轨迹特征:提取手部运动轨迹、速度、加速度等运动轨迹特征。kPeednc

4.分类和识别:使用机器学习算法对提取的特征进行分类,以识别特定的手势。kPeednc

代码实现

# -*- coding: utf-8 -*-kPeednc

import cv2kPeednc

def reg(x):kPeednc

    o1 = cv2.imread('paper.jpg',1)kPeednc

    o2 = cv2.imread('rock.jpg',1)kPeednc

    o3 = cv2.imread('scissors.jpg',1)  kPeednc

    gray1 = cv2.cvtColor(o1,cv2.COLOR_BGR2GRAY) kPeednc

    gray2 = cv2.cvtColor(o2,cv2.COLOR_BGR2GRAY) kPeednc

    gray3 = cv2.cvtColor(o3,cv2.COLOR_BGR2GRAY) kPeednc

    xgray = cv2.cvtColor(x,cv2.COLOR_BGR2GRAY) kPeednc

    ret, binary1 = cv2.threshold(gray1,127,255,cv2.THRESH_BINARY) kPeednc

    ret, binary2 = cv2.threshold(gray2,127,255,cv2.THRESH_BINARY) kPeednc

    ret, binary3 = cv2.threshold(gray3,127,255,cv2.THRESH_BINARY) kPeednc

    xret, xbinary = cv2.threshold(xgray,127,255,cv2.THRESH_BINARY) kPeednc

    contours1, hierarchy = cv2.findContours(binary1,kPeednc

                                                  cv2.RETR_LIST,kPeednc

                                                  cv2.CHAIN_APPROX_SIMPLE)  kPeednc

    contours2, hierarchy = cv2.findContours(binary2,kPeednc

                                                  cv2.RETR_LIST,kPeednc

                                                  cv2.CHAIN_APPROX_SIMPLE)  kPeednc

    contours3, hierarchy = cv2.findContours(binary3,kPeednc

                                                  cv2.RETR_LIST,kPeednc

                                                  cv2.CHAIN_APPROX_SIMPLE)  kPeednc

    xcontours, hierarchy = cv2.findContours(xbinary,kPeednc

                                                  cv2.RETR_LIST,kPeednc

                                                  cv2.CHAIN_APPROX_SIMPLE)  kPeednc

    cnt1 = contours1[0]kPeednc

    cnt2 = contours2[0]kPeednc

    cnt3 = contours3[0]kPeednc

    x = xcontours[0]kPeednc

    ret=[]kPeednc

    ret.append(cv2.matchShapes(x,cnt1,1,0.0))kPeednc

    ret.append(cv2.matchShapes(x,cnt2,1,0.0))kPeednc

    ret.append(cv2.matchShapes(x,cnt3,1,0.0))kPeednc

    max_index = ret.index(min(ret))  #计算最大值索引kPeednc

    if max_index==0:kPeednc

        r="paper"kPeednc

    elif max_index==1:kPeednc

        r="rock"kPeednc

    else:kPeednc

        r="sessiors"kPeednc

    return rkPeednc

t1=cv2.imread('test1.jpg',1)kPeednc

t2=cv2.imread('test2.jpg',1)kPeednc

t3=cv2.imread('test3.jpg',1)kPeednc

# print(reg(t1))kPeednc

# print(reg(t2))kPeednc

# print(reg(t3))kPeednc

# ===========显示处理结果==================kPeednc

org=(0,60)kPeednc

font = cv2.FONT_HERSHEY_SIMPLEXkPeednc

fontScale=2kPeednc

color=(255,255,255)kPeednc

thickness=3kPeednc

cv2.putText(t1,reg(t1),org,font,fontScale,color,thickness)kPeednc

cv2.putText(t2,reg(t2),org,font,fontScale,color,thickness)kPeednc

cv2.putText(t3,reg(t3),org,font,fontScale,color,thickness)kPeednc

cv2.imshow('test1',t1)kPeednc

cv2.imshow('test2',t2)kPeednc

cv2.imshow('test3',t3)kPeednc

cv2.waitKey()kPeednc

cv2.destroyAllWindows()kPeednc

实践

1.程序运行

kPeednc

2、原始图像包含训练图像

kPeednc

识别结果

识别到了 剪刀 石头 布kPeednc

kPeednc

原始图片kPeednc

kPeednc

米尔T527开发板7折起,点击链接了解更多:kPeednc

https://detail.tmall.com/item.htm?id=758523182967kPeednc

责编:Demi
文章来源及版权属于米尔电子,EDN电子技术设计仅作转载分享,对文中陈述、观点判断保持中立,不对所包含内容的准确性、可靠性或完整性提供任何明示或暗示的保证。如有疑问,请联系Demi.xia@aspencore.com
  • 微信扫一扫
    一键转发
  • 最前沿的电子设计资讯
    请关注“电子技术设计微信公众号”
广告
广告
热门推荐
广告
广告
EE直播间
在线研讨会
广告
面包芯语
广告
向右滑动:上一篇 向左滑动:下一篇 我知道了