Log in

View Full Version : Vision in Java


craigboez
12-01-2015, 18:26
First, a disclaimer: I am not a programmer. I am a mechanical mentor dipping my toe into the programming side to help set some wheels in motion for a vision system.

My team is 100% Java. For a variety of reasons we have decided to program in it exclusively.

There are lots of choices for implementing a vision system. On the roboRIO vs on the driver station vs on a co-processor. If on the DS, it could be in roboRealm, NI's code, or something else. I'm not familiar with the individual requirements or pros/cons for each of these options.

My question: as a pure Java team, what is the path of least resistance for getting a vision system up and running? We've never done one and I want to make sure we get something implemented this season, even if it is very basic.

Thanks.

SquishyIce
12-01-2015, 21:55
If you're just looking for getting vision on your dashboard with a USB camera, I stripped down the SimpleVision template to 3 lines of code that you run when initializing everything:

CameraServer camera = new CameraServer();
camera.setQuality(50);
camera.startAutomaticCapture("cam0");

When you start up the driver station while connected to a RoboRIO running this code, go to the FRC PC Dashboard. In the bottom left of the "drive" pane, there should be a dropdown menu with the options of no camera, SW camera, HW camera, and IP camera. I believe you set this to SW camera (If that doesn't work, try HW camera. It's one of the two. I honestly cant remember, even though I was using it literally 2 hours ago). This should give you a live camera feed in what was formerly a big empty space of the dashboard. One thing I did notice tonight about that string "cam0"; this does not name the camera, it determines what camera to get the feed from. I believe the first camera you connect is automatically addressed as "cam0". I could be wrong on this, I haven't tested using multiple cameras. I learned this the hard way by replacing "cam0" with "PotatoCam", then not understanding why I couldn't get any feed whatsoever.

Good luck!

Jared
12-01-2015, 21:57
Personally, I love team 341's solution to vision in 2012. They ran it on a dashboard that runs on the driver station. It's written in Java and worked very nicely. In my opinion, 341 was one of the most impressive robots to watch.

Domenic Rodriguez
12-01-2015, 22:11
Personally, I love team 341's solution to vision in 2012. They ran it on a dashboard that runs on the driver station. It's written in Java and worked very nicely. In my opinion, 341 was one of the most impressive robots to watch.

I'd second that statement. 341's system was the inspiration for our vision system last year, which was purely in Java. Instead of writing a SmartDashboard plugin, though, we used the Java bindings for OpenCV and NetworkTables to write a Swing app that ran on the driver station. Here's the code if you're interested: https://github.com/LuNaTeCs-316/LuNaCV

craigboez
13-01-2015, 01:16
Thanks, I'll take a look at the Daisy implementation. I have heard that JavaCV is poorly documented, at least relative to OpenCV. Has that been your experience?

Fauge7
13-01-2015, 02:54
It definitely is not as well documented as it is for c and cpp! I might have a vision solution so if it works I will document it and polish up for other teams to use!

Ben Wolsieffer
13-01-2015, 10:01
Thanks, I'll take a look at the Daisy implementation. I have heard that JavaCV is poorly documented, at least relative to OpenCV. Has that been your experience?

I wouldn't use JavaCV (the old third-party Java wrappers) because they only support OpenCV 2 and there is now an official Java API. It does not have its own documentation but the C++ documentation applies to it as well in most cases.

Ozuru
14-01-2015, 10:00
I wouldn't use JavaCV (the old third-party Java wrappers) because they only support OpenCV 2 and there is now an official Java API. It does not have its own documentation but the C++ documentation applies to it as well in most cases.

This. I've noticed a few changes, specifically that there is no IplImage anymore (Mat is the new storage type of choice) and imread/imwrite is in Imgcodecs.