I think this is best answered by one of the NI guys/gals, but anyone is more than welcome to step in (especially if you know what to do :P).
I was looking through the NIVision.java file, and saw many, many functions for lots of functionality. They look like C++ functions. Some of them are, from what I can tell, implemented in Java as blocking functions. However, the vast majority of them are not. I would like to call some of these functions. Before I start digging into implementing them myself, is there a reason they are not implemented?
My plan is to make my own task executer, and implement my own blocking function in the same style as the ones already implemented. They seem to follow a simple pattern of name and parameters to get from C++ to Java. Does anyone have experience doing this?
Those NI Vision functions are implemented by calling the NI C library. That way you get maximum performance on image transformations. Just be careful, it is allocating C memory for the various image classes and they have to be explicitly deallocated. Look at the documentation or sample programs to see how to do that.
Okay, just to clarify, the structure for calling them would be the same (generally speaking) as the functions that are already implemented? Make a blocking function, assign it to a task executer, then call it?
Alright, I got my first one working! I did the convex hull, since that will be useful to have, and didn’t require any new structures.
private static final BlockingFunction imaqConvexHullFn = NativeLibrary.getDefaultInstance().getBlockingFunction("imaqConvexHull");
static { imaqConvexHullFn.setTaskExecutor(taskExecutor); }
public static void convexHull(Pointer source, Pointer dest, int connectivity8) throws NIVisionException{
assertCleanStatus(imaqConvexHullFn.call3(source.address().toUWord().toPrimitive(), dest.address().toUWord().toPrimitive(), connectivity8));
}
Only thing I am unsure of it that according to the NI docs, connectivity8 is a boolean, so I assume 0 for false (meaning use connectivity to the 4 adjacent pixels) and 1 for true (meaning use connectivity to the 8 adjacent pixels).
If you want to modify the WPILib source code, it can go in the NIVision.java. However, each time the plugins get updated, I believe your changed will get removed. I just put it in my robot class, but for the final code it will go in its own class. To answer your question, it can go anywhere.
So you’ll notice that the first line declares the function “imaqConvexHullFn” as a function to access the C code. Do you have this line? Copy and pasting the relevant sections of code would make it easier.
We’ve been starting to work on camera-tracking code, and we ran into some issues. We thought that it might be a good idea to try the code that was posted here first, and make sure we could get that much to work. This is what we have so far:
public class Camera2012 {
public AxisCamera camera = AxisCamera.getInstance();
private static final BlockingFunction imaqConvexHullFn = NativeLibrary.getDefaultInstance().getBlockingFunction("imaqConvexHull");
static { imaqConvexHullFn.setTaskExecutor(taskExecutor); }
public static void convexHull(Pointer source, Pointer dest, int connectivity8) throws NIVisionException {
assertCleanStatus(imaqConvexHullFn.call3(source.address().toUWord().toPrimitive(), dest.address().toUWord().toPrimitive(), connectivity8));
}
}
We get the following errors:
taskExecutor: cannot find symbol
assertCleanStatus: cannot find symbol
My own experience with Java is limited; could you help us out with this? If you happen to notice anything that might be helpful, we’ll take all suggestions.
Essentially, this means you never created the taskExecutor object. The simplest way (I think) to use that code is to copy NIVision.java to your project, and add Dan’s code into that.
You need to instantiate your own TaskExecutor and pass it to setTaskExecutor. assertCleanStatus is a protected method of the NIVision class, which checks if its argument is nonzero and if so throws an NIVisionException. Why it is protected, I don’t know; you can’t extend the classs because the only constructor is private. Just make your own, or copy+paste the source code from NIVision.java.
Is there any documentation for the imaq functions C-side? Specifically, I would like to use imaqDetectRectangles and need the fields of the RectangleMatch struct.