工程记录:使用tello edu无人机进行计算机视觉工作(手势识别,yolo3搭载)

dji-sdk/Tello-Python: This is a collection of python modules that interact with the Ryze Tello drone.

参考的是大疆tello edu的官方支持库链接

需要git把其扒下来:

bash 复制代码
git clone https://github.com/dji-sdk/Tello-Python

环境配置:

在win11 x64系统上进行开发。基于python2.7搭建环境,由于python2.7是很老的python版本,故按照其下载文件夹中的.bat文件执行。下载后的python路径在C:\Python27\python.exe,在运行命令的时候需要加入前面的路径来执行。

其中有numpy,opencv,libh264decoder无法下载.

解决办法为:经过测试有效的,下载opencv for python2.7

bash 复制代码
C:\Python27\python.exe -m pip install opencv-python==4.2.0.32

此外关于libh264decoder解决办法是把官方链接中的tello_video_dll(For win64).zip中的全部文件都挨个放在文件夹C:\Python27\lib\site-packages文件夹下面,如下图所示:

而不是仅仅把libh264decoder.pyd文件放在该文件夹下,.pyd文件就相当于一个动态链接库.so文件,还需要dll文件来支持。

下载pose模型

OpenPose人体姿态识别项目是美国卡耐基梅隆大学(CMU)基于卷积神经网络和监督学习并以caffe为框架开发的开源库。可以实现人体动作、面部表情、手指运动等姿态估计。适用于单人和多人,具有极好的鲁棒性。是世界上首个基于深度学习的实时多人二维姿态估计应用,基于它的实例如雨后春笋般涌现。人体姿态估计技术在体育健身、动作采集、3D试衣、舆情监测等领域具有广阔的应用前景,人们更加熟悉的应用就是抖音尬舞机。

这里应当注意的是openpose实际上对于tello python要求下载的那个模型已经在官网上不保留了,需要自己去找资源。

GitCode - 全球开发者的开源社区,开源代码托管平台

在上面的链接中有下载资源。下载好后把pose_iter_160000放在model/pose/mpi中即可。

在原本的代码中要求同时读入proto file(规定了输入的神经网络的层数和每层的特点),还有读入caffemodel参数权重文件。

python 复制代码
        # read the path of the trained model of the neural network for pose recognition
        self.protoFile = "model/pose/mpi/pose_deploy_linevec_faster_4_stages.prototxt"
        self.weightsFile = "model/pose/mpi/pose_iter_160000.caffemodel"
        
        # total number of the skeleton nodes
        self.nPoints = 15
        
        # read the neural network of the pose recognition
        self.net = cv2.dnn.readNetFromCaffe(self.protoFile, self.weightsFile)

搭载yolo3

把简单版本的Yolo3搭载在py2.7环境中捕获输入视频中的物体并圈出来。整体流程是点击yolo按钮后开始识别,然后处理返回的x,y,h,w在图中画出来。

详细代码过程如下。首先是加载yolo3低版本模型的代码:

这里的逻辑是当用户按下tkinter的按钮后yolo_mode设置为True,随后加载yolo3模型的.cfg和.weights文件再获得detections.这里还隐藏了一个保存的功能,去掉taskSnapshot1的注释后可以进行保存。

python 复制代码
                if self.yolo_mode:
                    image = self.frame
                    model = cv2.dnn.readNetFromDarknet('yolo3.cfg', 'yolov3.weights')
                    blob = cv2.dnn.blobFromImage(image, 1/255.0, (416, 416), (0, 0, 0), swapRB=True, crop=False)
                    model.setInput(blob)
                    detections = model.forward()
                    #print(type(detections))
                    for detection in detections:
                        x, y, w, h, confidence = detection[0:5]                       
                        if confidence > 0.05:
                            height,width=image.shape[:2]
                            height=int(height)
                            width=int(width)
                            print("width=",width)
                            print("height=",height)
                            cv2.rectangle(image, (int(width * (x - w/2)), int(height * (y - h/2))), (int(width * (x + w/2)), int(height * (y + h/2))), (0, 255, 0), 2)                    
                            #takeSnapshot1(image)
                            					           print("x=",x,"y=",y,"w=",w,"h=",h,"confidence=",confidence)
                    self.detections=detections

下面是得到yolo返回的检测结果包含框的中心坐标x,y和宽度w,高度h,随后在打开的frame中用cv2.rectangle在图中画出框。此处应该注意返回的x,y,w,h都是归一化后的,应当乘以图像的w和h去反向归一化。

python 复制代码
            if self.yolo_mode:
                height,width=frame.shape[:2]
                height=int(height)
                width=int(width)
    
                for detection in self.detections:
                    x, y, w, h, confidence = detection[0:5]
                    #print("confidence=",confidence)
                    if confidence > 0.05:
                        cv2.rectangle(frame, (int(width * (x - w/2)), int(height * (y - h/2))), (int(width * (x + w/2)), int(height * (y + h/2))), (0, 255, 0), 2)                            
                        #print("x=",x,"y=",y,"w=",w,"h=",h)
                        #print("height=",height,"width=",width)

备注:下载Yolo3模型权重链接为:

YOLOv3模型文件下载:YOLOv3 模型文件下载本仓库提供了YOLOv3模型的核心文件,包括`coco.names`、`yolov3.cfg`和`yolov3.weights` - GitCode

完整代码工程文件在github:

nanfangxiansheng/tello_edu_add_test: 在大疆原有的tello edu库基础上配置环境并适当改进使其支持在py2.7下用opencv加载Yolov3模型进行目标检测

相关推荐
wan5555cn4 小时前
国产电脑操作系统与硬盘兼容性现状分析:挑战与前景评估
人工智能·笔记·深度学习·机器学习·电脑·生活
BullSmall5 小时前
汽车HIL测试:电子开发的关键验证环节
人工智能·机器学习·自动驾驶
woshihonghonga5 小时前
停止Conda开机自动运行方法
linux·人工智能·conda
海洲探索-Hydrovo7 小时前
TTP Aether X 天通透传模块丨国产自主可控大数据双向通讯定位模组
网络·人工智能·科技·算法·信息与通信
触想工业平板电脑一体机7 小时前
【触想智能】工业安卓一体机在人工智能领域上的市场应用分析
android·人工智能·智能电视
墨染天姬8 小时前
【AI】数学基础之矩阵
人工智能·线性代数·矩阵
2401_8414956410 小时前
【计算机视觉】基于复杂环境下的车牌识别
人工智能·python·算法·计算机视觉·去噪·车牌识别·字符识别
倔强青铜三10 小时前
苦练Python第66天:文件操作终极武器!shutil模块完全指南
人工智能·python·面试
倔强青铜三10 小时前
苦练Python第65天:CPU密集型任务救星!多进程multiprocessing模块实战解析,攻破GIL限制!
人工智能·python·面试