Just wondering if anyone has had any luck getting OpenCV (or for that matter, any) functions to run in a separate WPILib task / thread on the RoboRIO?
If you had it would be helpful to know how well it works in terms of eliminating latency in your main robot code? We also need help in implementing the task creation. If someone has example code they could point me to for making a new thread (not necessarily OpenCV) that would be great to use as a reference for proper implementation of the WPILib Task functions.
My team has been using tasks for a variety of things for years now. All our tasks are simply based on a class jankyTask. Please see the following post for links to the github code and a write-up I did on how it all works a few years ago.
Yeah, you are ok to use it! We are still refining the vision code for detecting totes though so you should redo that part if you can do it better. For compiling and linking, this is a lengthy process. We used just plain OpenCV2. We followed team 2168’s linking instructions which are a bit vague so I will try and explain.
Download our OpenCV project from our github here. And move the project somewhere safe (we have C:\OpenCV_frc\arm\include\OpenCV\opencv2)
Then I assume you have an existing project for C++ (im not sure if this differs from java) go open eclipse and right click on your project go to Properties->C/C++ Build->Settings. Then go to the tool settings tab and click on Cross G++ Linker and add -rpath,C:\OpenCV_frc\arm\libs\opencv (what ever your directory is). Also make sure you have a comma in between entries.
Then go to C/C++ general and go to paths and symbols. Click on the library paths tab and hit add. Add the directory from your file system and type in C:\OpenCV_frc\arm\libs\opencv (what ever your directory was) hit apply.
Then go to the Libraries tab and add opencv_core,opencv_highgui,opencv_imgproc from C:\OpenCV_frc\arm\libs\opencv (whatever your directory is)
5.Now hit apply and add the cpp and h files in a folder in your project. we have our called Vision2015. Then add the necessary includes and and using namespace cv;
You should be able to compile and run the robot. You might want to see how to run the code on a separate task though because it will slow down drive code if running in a separate task. Our actual robot project in robot.cpp shows how to do that.
Please feel free to reply if you have any questions. Also, if you improve the tote detector in any way, contact us.
Did you get the tracking working on the RoboRio? Last I saw everything was a tote. I am assuming you got it working because Jason had it working on the laptop and this should of been a straight up port. I ask because when I saw it earlier yesterday it was running in the separate thread OK it just wasn’t tracking right yet.
Thanks for the great instructions! However, every time I setup a project (including importing yours and fixing the paths to opencv) I get like 175 errors in opencv2/core/core.hpp. I had the same problem when I tried earlier in the season to get opencv in the project. Any idea why I would get so many errors? Sound like something to do with the index, but I’ve rebuilt in many times.
Edit: followed PaulDavis1968’s suggestion to comment out that line in WPILIB. No idea what that does, but it fixed it!
Yeah, we found that out the hard way. After searching forever through OpenCV and wpilib we found that REAL is defined in both wpilib and OpenCV. Good luck with auto!