View Single Post
  #2   Spotlight this post!  
Unread 02-04-2016, 11:54 AM
mikhail's Avatar
mikhail mikhail is offline
Registered User
AKA: Mentor of The Software ERRORs
FRC #3130 (ERRORS)
Team Role: Mentor
 
Join Date: Dec 2014
Rookie Year: 2013
Location: Minnesota
Posts: 17
mikhail is an unknown quantity at this point
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"
Reply With Quote