Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   getting output from opencv onto smartdashboard (http://www.chiefdelphi.com/forums/showthread.php?t=142681)

jreneew2 01-27-2016 10:36 PM

getting output from opencv onto smartdashboard
 
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?

Thanks,
Drew

mikhail 02-04-2016 11:54 AM

Re: getting output from opencv onto 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:
Code:

void CameraFeedCommand::CameraFeedCommand()
{
    image = frcCreateImage(IMAQ_IMAGE_RGB);
}

void CameraFeedCommand::Execute()
{
    frcReadImage(image,"/var/volatile/tmp/opencv-frame.png");
    CameraServer::GetInstance()->SetImage(image);
}

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"

Ben Wolsieffer 02-04-2016 12:41 PM

Re: getting output from opencv onto smartdashboard
 
3 Attachment(s)
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.


All times are GMT -5. The time now is 10:17 AM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi