Görüntü Programlama Stratejileri

Bilgisayarla görmeyi kullanmak, robotunuzun sahadaki unsurlara duyarlı olmasını ve çok daha otonom olmasını sağlamanın harika bir yoludur. Genellikle FRC |reg| oyunlar, topları veya diğer oyun parçalarını kendi kendine hedefe atmak veya sahadaki yerlere gitmek için bonus puanlar vardır. Bilgisayarla görme, bu sorunların çoğunu çözmenin harika bir yoludur. Ve eğer meydan okumayı gerçekleştirebilecek özerk bir kodunuz varsa, o zaman insan sürücülere yardımcı olmak için teleop döneminde de kullanılabilir.

Görüntü işleme için bileşenleri ve görsel denetim programının nerede çalışması gerektiğini seçmek için bir çok seçenek vardır. WPILib ve ilgili araçlar bir dizi seçeneği destekler ve ekiplere ne yapacaklarına karar vermeleri için büyük bir esneklik sağlar. Bu makale, mevcut birçok seçenek ve değiş tokuş hakkında size fikir vermeye çalışacaktır.

Different vision workflows in FRC.

OpenCV Computer Vision Kitaplığı

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’da Görüntü Kodu

The chain from a USB Webcam to roboRIO to Ethernet Switch over a video stream to the driver station computer.

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 sınıfı tarafından sağlanan işlevleri kullanarak, video akışı Shuffleboard gibi gösterge tablolarına gönderilebilir, böylece operatörler kameranın gördüklerini görebilir. Ek olarak, OpenCV komutları bilgi görüntülere eklenebilir, böylece hedefler veya diğer ilginç nesneler gösterge tablosu görünümünde tanımlanabilir.

DS Bilgisayarda Görüntü Kodu

Same as the above diagram but the Driver Station computer must process that video and send NetworkTables updates back to the roboRIO.

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.

Yardımcı İşlemcide Görüntü Kodu

Coprocessor is on same network as the roboRIO so it off loads the compute without having the latency of going to the Driver Station and back.

Raspberry Pi gibi yardımcı işlemciler, görüntü kodunu desteklemek için idealdir (bkz: ref: docs / software / vision-processing / wpilibpi / using-the-raspberry-pi-for-frc: Raspberry Pi for FRC). Avantajı, tam hızda çalışabilmeleri ve robot programına müdahale etmemeleridir. Bu durumda, kamera muhtemelen yardımcı işlemciye veya (Ethernet kameraları olması durumunda) robot üzerindeki bir Ethernet anahtarına bağlıdır. Program herhangi bir dilde yazılabilir; Python, OpenCV ve NetworkTables’a olan basit bağlantıları nedeniyle iyi bir seçimdir. Bazı ekipler, en yüksek hız ve en yüksek çözünürlük için Nvidia Jetson gibi yüksek performanslı görüntü yardımcı işlemcileri kullandı, ancak bu yaklaşım genellikle gelişmiş Linux ve programlama bilgisi gerektiriyor.

Bu yaklaşım, biraz daha fazla programlama uzmanlığı ve az miktarda ek ağırlık gerektirir, ancak aksi takdirde, yardımcı işlemciler roboRIO’dan çok daha hızlı olduğundan ve görüntü işleme ile gerçekleştirilebildiğinden, diğer iki yaklaşıma kıyasla her iki yerin en iyisini minimum gecikme veya bant genişliği kullanımı ile getirir.

Veriler, yardımcı işlemcideki görüntü programından robota NetworkTables veya bir ağ veya seri bağlantı üzerinden özel bir protokol kullanılarak gönderilebilir.

Kamera Seçenekleri

WPILib tarafından desteklenen bir dizi kamera seçeneği vardır. Kameraların çalışmayı etkileyen bir dizi parametresi vardır; örneğin, kare hızı ve görüntü çözünürlüğü alınan görüntülerin kalitesini etkiler, ancak çok yüksek etkili işleme süresi ayarlandığında ve sürücü istasyonuna gönderilirse, sahadaki mevcut bant genişliğini aşabilir.

C ++ ve Java’daki CameraServer sınıfı, robota bağlı kameralarla arayüz oluşturmak için kullanılır. Bir Kaynak nesnesi aracılığıyla yerel işleme için çerçeveleri alır ve akışı orada görüntülemek veya işlemek için sürücü istasyonunuza gönderir.