Hello. We are testing some vision code we wrote on the roboRIO and are using opencv on the RIO. I would like to be able to get the output steam of jpegs from opencv to the c++ smartdashboard.
I have seen you can use CameraServer’s setImage, but how does that work in correlation with the smartdashboard?
SmartDashboard’s and OpenCV’s formats are not compatible with each others but there is a trick. There could be better methods but here’s what worked for me, at least for debugging purposes. Save your cv::Mat, the one you want to see, probably after all the OpenCV processing with marks and numbers on it, using imwrite() somewhere in RoboRIO’s filesystem. I used /var/volatile/tmp/ directory as I guess it’s some kind of a RAM-disk on RoboRIO, so all the IO should happen in-memory. Then create an IMAQ image object, something like “Image image = frcCreateImage(IMAQ_IMAGE_RGB);”, and read your file into it and set it as the current frame with the CameraServer:
PS: Do not run the automatic capture with the CameraServer, feed it the images yourself repeatedly.
PPS: Set the camera mode on the Dashboard to “USB camera HW”
I wrote a MJPG streaming server in Java for our vision system and I have a more limited C++ version of it that I ported for a personal project, but it requires Boost, which might be a little difficult to get working on the roboRIO.
I attached them both to this post, in case they might be helpful.