Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Java (http://www.chiefdelphi.com/forums/forumdisplay.php?f=184)
-   -   NI Vision Functions (http://www.chiefdelphi.com/forums/showthread.php?t=99536)

JewishDan18 08-01-2012 19:06

NI Vision Functions
 
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?

Thanks a bunch!

BradAMiller 08-01-2012 19:22

Re: NI Vision Functions
 
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.

Brad

JewishDan18 08-01-2012 20:11

Re: NI Vision Functions
 
Quote:

Originally Posted by BradAMiller (Post 1099854)
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.

Brad

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?

jhersh 09-01-2012 02:31

Re: NI Vision Functions
 
Quote:

Originally Posted by JewishDan18 (Post 1099918)
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?

That is correct.

JewishDan18 10-01-2012 12:09

Re: NI Vision Functions
 
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.

Code:

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).

jhersh 10-01-2012 14:46

Re: NI Vision Functions
 
Quote:

Originally Posted by JewishDan18 (Post 1101541)
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).

That should be correct.

shoffing 12-01-2012 22:52

Re: NI Vision Functions
 
Quote:

Originally Posted by JewishDan18 (Post 1101541)
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.

Code:

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).

Where would this code go? In NIVision.java or in your main robot class file?

JewishDan18 12-01-2012 23:01

Re: NI Vision Functions
 
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.

rudun 14-01-2012 14:01

Re: NI Vision Functions
 
We try adding it to our own class and tried extending it. We are getting the following error. cannot find symbol variable imaqConvexHullFn

We imported import com.sun.cldc.jna.*; is there anything else we need to import or do we need to extend the class or something.

JewishDan18 14-01-2012 20:58

Re: NI Vision Functions
 
Quote:

Originally Posted by rudun (Post 1105361)
We try adding it to our own class and tried extending it. We are getting the following error. cannot find symbol variable imaqConvexHullFn

We imported import com.sun.cldc.jna.*; is there anything else we need to import or do we need to extend the class or something.

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.

AjFoster 20-01-2012 15:47

Re: NI Vision Functions
 
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:

Code:

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.

Thanks so much!

Patrickwhite 20-01-2012 16:18

Re: NI Vision Functions
 
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.

ColonelThrtyTwo 20-01-2012 16:49

Re: NI Vision Functions
 
Quote:

Originally Posted by AjFoster (Post 1109853)
We get the following errors:

taskExecutor: cannot find symbol
assertCleanStatus: cannot find symbol

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.

jhersh 20-01-2012 17:02

Re: NI Vision Functions
 
Quote:

Originally Posted by ColonelThrtyTwo (Post 1109894)
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.

Look in C:\Program Files\National Instruments\Vision\Documentation\NIVisionCVI.chm

-Joe

JewishDan18 20-01-2012 17:08

Re: NI Vision Functions
 
Quote:

Originally Posted by ColonelThrtyTwo (Post 1109894)
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.

The way I did it was to make a new executer, and copy and past the assertCleanStatus function from the NIVision.java.

AjFoster 20-01-2012 23:07

Re: NI Vision Functions
 
Thanks so much for the tips - everything runs error-free now.

Would it be possible to see an example of convexHull() being properly called (for an image which I've already used an HSL threshold on)?

JewishDan18 21-01-2012 20:28

Re: NI Vision Functions
 
Quote:

Originally Posted by AjFoster (Post 1110223)
Thanks so much for the tips - everything runs error-free now.

Would it be possible to see an example of convexHull() being properly called (for an image which I've already used an HSL threshold on)?

Sure, here is an example of how I call it:

Code:

convexHull(binaryImage.image,binaryImage.image,1);
That will find the convex hull of binaryImage and put it in binaryImage

rudun 21-01-2012 20:40

You may want to check out this post. They have wrapped it into the library as of today. http://www.chiefdelphi.com/forums/sh...d.php?t=100792

JewishDan18 21-01-2012 22:29

Re: NI Vision Functions
 
Yeah, but there are still many many functions upwrapped :P

BradAMiller 22-01-2012 11:19

Re: NI Vision Functions
 
Quote:

Originally Posted by JewishDan18 (Post 1110911)
Yeah, but there are still many many functions upwrapped :P

What would you like to see? Please be specific.

Brad

JewishDan18 25-01-2012 11:21

Re: NI Vision Functions
 
Currently, the only other one I am using is imaqSubtractFn, but in an ideal world I would like to play with the edge detection and the detect lines functions. Also, I've rewritten a bunch of the stuff with the particle reports, to get more data and because the sorted vector is slow.

Adamsmasher23 28-01-2012 14:11

Re: NI Vision Functions
 
Quote:

Originally Posted by BradAMiller (Post 1111116)
What would you like to see? Please be specific.

Brad

We would like the Linear Averages function, so that we can calculate a hollowness score.

codes02 12-02-2012 18:16

Re: NI Vision Functions
 
Does anyone know if there is full documentation of the NIVision C functions anywhere to make this process easier?

Greg McKaskle 13-02-2012 07:13

Re: NI Vision Functions
 
Program Filles/National Instruments/Vision/Documentation.

Specifically, you should look at the CVI document.

Greg Mckaskle

jhersh 13-02-2012 14:02

Re: NI Vision Functions
 
Quote:

Originally Posted by codes02 (Post 1125147)
Does anyone know if there is full documentation of the NIVision C functions anywhere to make this process easier?

http://www.chiefdelphi.com/forums/sh...4&postcount=14


All times are GMT -5. The time now is 11:15.

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