Go to Post Everyone is wrong! - Chris is me [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 08-01-2012, 19:06
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
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 ).

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!
Reply With Quote
  #2   Spotlight this post!  
Unread 08-01-2012, 19:22
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 590
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
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
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
Reply With Quote
  #3   Spotlight this post!  
Unread 08-01-2012, 20:11
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: NI Vision Functions

Quote:
Originally Posted by BradAMiller View Post
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 09-01-2012, 02:31
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: NI Vision Functions

Quote:
Originally Posted by JewishDan18 View Post
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.
Reply With Quote
  #5   Spotlight this post!  
Unread 10-01-2012, 12:09
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
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).
Reply With Quote
  #6   Spotlight this post!  
Unread 10-01-2012, 14:46
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: NI Vision Functions

Quote:
Originally Posted by JewishDan18 View Post
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.
Reply With Quote
  #7   Spotlight this post!  
Unread 12-01-2012, 22:52
shoffing's Avatar
shoffing shoffing is offline
WINriver C++
AKA: Steve Hoffing
FRC #1647
Team Role: Programmer
 
Join Date: Feb 2009
Rookie Year: 2008
Location: Shamong, New Jersey, America
Posts: 10
shoffing is an unknown quantity at this point
Re: NI Vision Functions

Quote:
Originally Posted by JewishDan18 View Post
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?
__________________
---
Team 1647's Software "thing" for 2011
Death-Spin autonomous mode is my favorite.
Reply With Quote
  #8   Spotlight this post!  
Unread 12-01-2012, 23:01
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
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.
Reply With Quote
  #9   Spotlight this post!  
Unread 14-01-2012, 14:01
rudun's Avatar
rudun rudun is offline
Registered User
FRC #0496 (Royals)
Team Role: Coach
 
Join Date: Jan 2009
Rookie Year: 2005
Location: Babylon
Posts: 43
rudun is an unknown quantity at this point
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.

Last edited by rudun : 14-01-2012 at 14:02. Reason: typo
Reply With Quote
  #10   Spotlight this post!  
Unread 14-01-2012, 20:58
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: NI Vision Functions

Quote:
Originally Posted by rudun View Post
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.
Reply With Quote
  #11   Spotlight this post!  
Unread 20-01-2012, 15:47
AjFoster AjFoster is offline
Hydra Robotics - 2425
AKA: AJ
FRC #2425 (Hydra Robotics)
Team Role: Mentor
 
Join Date: Mar 2009
Rookie Year: 2008
Location: Tampa, FL
Posts: 2
AjFoster is an unknown quantity at this point
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!
__________________
Aj Foster

Team 2425 - HYDRA Robotics
Hillsborough High School
Tampa, Florida
Reply With Quote
  #12   Spotlight this post!  
Unread 20-01-2012, 16:18
Patrickwhite's Avatar
Patrickwhite Patrickwhite is offline
May the North be with you
FRC #0610 (The Coyotes)
Team Role: Programmer
 
Join Date: Dec 2008
Rookie Year: 2008
Location: Toronto
Posts: 88
Patrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of lightPatrickwhite is a glorious beacon of light
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.
__________________
while(!going.isTough());
tough.exit();

What will we do tonight, Warfa?
The same thing we do every night, Patrick. Sit and wait for Electrical.
Reply With Quote
  #13   Spotlight this post!  
Unread 20-01-2012, 16:49
ColonelThrtyTwo's Avatar
ColonelThrtyTwo ColonelThrtyTwo is offline
Registered User
FRC #3676
 
Join Date: Jan 2011
Location: Somewhere in Texas
Posts: 13
ColonelThrtyTwo is an unknown quantity at this point
Re: NI Vision Functions

Quote:
Originally Posted by AjFoster View Post
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.
Reply With Quote
  #14   Spotlight this post!  
Unread 20-01-2012, 17:02
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: NI Vision Functions

Quote:
Originally Posted by ColonelThrtyTwo View Post
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
Reply With Quote
  #15   Spotlight this post!  
Unread 20-01-2012, 17:08
JewishDan18's Avatar
JewishDan18 JewishDan18 is offline
Registered User
FRC #1700
Team Role: Engineer
 
Join Date: Feb 2009
Rookie Year: 2007
Location: Sunnyvale, CA
Posts: 185
JewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to beholdJewishDan18 is a splendid one to behold
Re: NI Vision Functions

Quote:
Originally Posted by ColonelThrtyTwo View Post
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.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:04.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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