视觉编程策略
使用计算机视觉是使您的机器人对现场的元素做出反应并使其更加自动化的一种好方法。通常在FRC | reg |比赛中,可以通过自动将球或其他比赛物件射入目标,或导航到场地上获得奖励分数。计算机视觉是解决其中许多问题的好方法。而且,如果您拥有可以实现这一操作的自动代码,那么它也可以在遥控操作期间使用,以帮助驾驶员。
视觉处理系统的的组件以及视觉程序应该运行的位置有多种选项。WPILib和相关的工具也支持多种选项,并为团队的决定提供了很大的灵活性。本文将让您了解许多可用的选择和权衡。
OpenCV计算机视觉库
OpenCV is an open source computer vision library that is widely used throughout academia and industry. It has support from hardware manufactures providing GPU accelerated processing, it has bindings for a number of languages including C++, Java, and Python. It is also well documented with many web sites, books, videos, and training courses so there are lots of resources available to help learn how to use it. The C++ and Java versions of WPILib include the OpenCV libraries, there is support in the library for capturing, processing, and viewing video, and tools to help you create your vision algorithms. For more information about OpenCV see https://opencv.org.
在roboRIO上运行视觉代码
Vision code can be embedded into the main robot program on the roboRIO. Building and running the vision code is straightforward because it is built and deployed along with the robot program. The vision code can be written in C++, Java, or Python. The disadvantage of this approach is that having vision code running on the same processor as the robot program can cause performance issues. This is something you will have to evaluate depending on the requirements for your robot and vision program.
In this approach, the vision code simply produces results that the robot code directly uses. Be careful about synchronization issues when writing robot code that is getting values from a vision thread. The VisionRunner class in WPILib make this easier.
使用CameraServer类提供的函数,视频流可以发送到仪表盘,比如Shuffleboard,这样操作手就可以看到摄像头看到的内容。此外,可以使用OpenCV命令将注释添加到图像中,以便在仪表盘视图中识别目标或其他感兴趣的对象。
DS计算机上的视觉代码
When vision code is running on the DS computer, the video is streamed back to the Driver Station laptop for processing. Even the older Classmate laptops are substantially faster at vision processing than the roboRIO. You can write your own vision program using a language of your choosing. Python makes a good choice since there is a native NetworkTables implementation and the OpenCV bindings are very good.
After the images are processed, the key values such as the target position, distance, or anything else you need can be sent back to the robot with NetworkTables. This approach generally has higher latency, as delay is added due to the images needing to be sent to the laptop. Bandwidth limitations also limit the maximum resolution and FPS of the images used for processing.
The video stream can be displayed on Shuffleboard or SmartDashboard.
协处理器上的视觉代码
像Raspberry Pi这样的协处理器是支持视觉代码的理想选择(参见:ref: ‘ docs/software/vision-processing/frcvision/ using-raspberry - pie -for- FRC:Using the Raspberry Pi for FRC ‘)。优点是它们可以全速运行,不干扰机器人程序。在这种情况下,摄像机可能连接到协处理器,或者(对于以太网摄像机来说)机器人上的一个以太网开关。该程序可以用任何语言编写;Python是一个很好的选择,因为它可以简单地绑定到OpenCV和NetworkTables。一些团队使用高性能的视觉协同处理器,如Nvidia Jetson,以获得最快的速度和最高的分辨率,尽管这种方法通常需要高级的Linux和编程知识。
与其他两种方法相比,这种方法需要更多的编程专业知识和少量的额外权重,但除此之外,它带来了两个方面的最佳效果,因为协处理器比roboRIO快得多,并且图像处理可以以最小的延迟或带宽使用进行。
据可以通过网络或串行连接从协处理器上的视觉程序发送到机器人。
相机选择
WPILib支持多种摄像机选项。 摄像机有许多影响操作的参数;例如,帧频和图像分辨率影响接收图像的质量,但当设置过高的影响处理时间时,如果发送到操控站,可能会超过现场的可用带宽。
c++和Java中的CameraServer用于与连接到机器人的摄像机进行对接。它通过源对象检索用于本地处理的帧,并将流发送到您的操控站,以便在那里查看或处理。