Go to Post They were designed that way so they would be compatible with the water-based ga.... oops, sorry, we aren't supposed to say anything about that. Never mind. - dlavery [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 22-06-2016, 17:20
Ouroboroz Ouroboroz is offline
Registered User
AKA: Kevin
FRC #2554 (The Warhawks)
Team Role: Programmer
 
Join Date: Apr 2016
Rookie Year: 2014
Location: Edison NJ
Posts: 8
Ouroboroz is an unknown quantity at this point
Method From ColorImage

So the code for the threshold method is:

private BinaryImage threshold(NIVision.ColorMode colorMode, int low1, int high1, int low2,
int high2, int low3, int high3) throws NIVisionException {
BinaryImage res = new BinaryImage();
NIVision.Range range1 = new NIVision.Range(low1, high1);
NIVision.Range range2 = new NIVision.Range(low2, high2);
NIVision.Range range3 = new NIVision.Range(low3, high3);
NIVision.imaqColorThreshold(res.image, image, 1, colorMode, range1, range2, range3);
res.free();
range1.free();
range2.free();
range3.free();
return res;
}
I'm confused on the part where res is freed and the returned afterwards. If I read correctly, free() releases the memory for the image. So would return still give back the image.

PS How do I initialize a Binary Image? The constructor is not public. D:
Reply With Quote
  #2   Spotlight this post!  
Unread 22-06-2016, 23:40
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Method From ColorImage

1. Yeah, that doesn't make a lot of sense. Maybe free() doesn't always do what we think it does? (not likely)

2. Reflection!
Code:
Constructor<BinaryImage> ct = BinaryImage.class.getDeclaredConstructor();
ct.setAccessible(true);
BinaryImage img = ct.newInstance();
Or modify WPILib and compile it together with your project, probably a solution that makes more sense.
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #3   Spotlight this post!  
Unread 23-06-2016, 13:50
Peter Johnson Peter Johnson is offline
WPILib Developer
FRC #0294 (Beach Cities Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Redondo Beach, CA
Posts: 243
Peter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud ofPeter Johnson has much to be proud of
Re: Method From ColorImage

1. It's a bug, introduced in https://github.com/wpilibsuite/allwp...70d994ed36ff86 ... originally the res.free() was only called if an exception was raised.

2. By calling ColorImage.threshold(), clearly

Please feel free to create issues on github for these.
__________________
Author of ntcore - WPILib NetworkTables for 2016+
Creator of RobotPy - Python for FRC

2010 FRC World Champions (294, 67, 177)
2007 FTC World Champions (30, 74, 23)
2001 FRC National Champions (71, 294, 125, 365, 279)
Reply With Quote
  #4   Spotlight this post!  
Unread 25-06-2016, 16:05
Ouroboroz Ouroboroz is offline
Registered User
AKA: Kevin
FRC #2554 (The Warhawks)
Team Role: Programmer
 
Join Date: Apr 2016
Rookie Year: 2014
Location: Edison NJ
Posts: 8
Ouroboroz is an unknown quantity at this point
Re: Method From ColorImage

Quote:
Originally Posted by euhlmann View Post
1. Yeah, that doesn't make a lot of sense. Maybe free() doesn't always do what we think it does? (not likely)

2. Reflection!
Code:
Constructor<BinaryImage> ct = BinaryImage.class.getDeclaredConstructor();
ct.setAccessible(true);
BinaryImage img = ct.newInstance();
Or modify WPILib and compile it together with your project, probably a solution that makes more sense.
Wait would casting MonoImage into BinaryImage work too?
Reply With Quote
  #5   Spotlight this post!  
Unread 25-06-2016, 16:35
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Method From ColorImage

Quote:
Originally Posted by Ouroboroz View Post
Wait would casting MonoImage into BinaryImage work too?
No, because you can only downcast an object if it was that type to begin with.

Code:
class A {}
class B extends A {}

public static void main(String[] args){
    A a1 = new B();
    B a1_b = (B) a1; // ok

    A a2 = new A();
    B a2_b = (B) a2; // ClassCastException
}
More info: https://docs.oracle.com/javase/tutor...ubclasses.html
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
Reply With Quote
  #6   Spotlight this post!  
Unread 25-06-2016, 17:46
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Captain
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 143
nickbrickmaster is an unknown quantity at this point
Re: Method From ColorImage

Quote:
Originally Posted by euhlmann View Post
2. Reflection!
Code:
Constructor<BinaryImage> ct = BinaryImage.class.getDeclaredConstructor();
ct.setAccessible(true);
BinaryImage img = ct.newInstance();
Or modify WPILib and compile it together with your project, probably a solution that makes more sense.
Ew. If it's not visible, it's not meant to be accessible. Reflection is not a tool that should be used in this context. If it's an API, it's not meant to be modified and compiled with your project. Use the tools correctly, and your problems will decrease. Use them incorrectly, and they will multiply.

As for an actual answer, you're not supposed to initialize a BinaryImage. You get them from methods like this one.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #7   Spotlight this post!  
Unread 25-06-2016, 18:04
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Method From ColorImage

Quote:
Originally Posted by nickbrickmaster View Post
Ew. If it's not visible, it's not meant to be accessible. Reflection is not a tool that should be used in this context.
Yes, reflection is only to be used when you know what you're doing, hence my suggestion to modify WPILib instead.
Quote:
Originally Posted by nickbrickmaster View Post
If it's an API, it's not meant to be modified and compiled with your project. Use the tools correctly, and your problems will decrease. Use them incorrectly, and they will multiply.
The WPILib people actually have instructions on screensteps for compiling WPILib with your project. I don't think they would do that if they didn't want you to modify WPILib.

Quote:
Originally Posted by nickbrickmaster View Post
As for an actual answer, you're not supposed to initialize a BinaryImage. You get them from methods like this one.
I don't really think that's a good answer. The C++ IMAQ API (although different from this java wrapper) allows creating binary images. Why shouldn't the Java API allow that?
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org

Last edited by euhlmann : 25-06-2016 at 18:14.
Reply With Quote
  #8   Spotlight this post!  
Unread 25-06-2016, 18:48
nickbrickmaster's Avatar
nickbrickmaster nickbrickmaster is offline
Captain
AKA: Nick Schatz
FRC #3184 (Blaze Robotics)
Team Role: Programmer
 
Join Date: Jan 2015
Rookie Year: 2014
Location: Eagan MN
Posts: 143
nickbrickmaster is an unknown quantity at this point
Re: Method From ColorImage

Quote:
Originally Posted by euhlmann View Post
The WPILib people actually have instructions on screensteps for compiling WPILib with your project. I don't think they would do that if they didn't want you to modify WPILib.
My answer was more about general API usage than WPILib, I guess. You shouldn't need to modify an API to get a function working that was part of the library initially.

Quote:
Originally Posted by euhlmann View Post
I don't really think that's a good answer. The C++ IMAQ API (although different from this java wrapper) allows creating binary images. Why shouldn't the Java API allow that?
I didn't know that, sorry. I'm not too well versed in WPILib vision, and a cursory glance through the docs made it look as if this was the way to do things. My sincere apologies.
__________________
I have approximate knowledge of many things.

FRC 3184: 2014-, FTC 10648: 2015-
Reply With Quote
  #9   Spotlight this post!  
Unread 25-06-2016, 22:09
Ouroboroz Ouroboroz is offline
Registered User
AKA: Kevin
FRC #2554 (The Warhawks)
Team Role: Programmer
 
Join Date: Apr 2016
Rookie Year: 2014
Location: Edison NJ
Posts: 8
Ouroboroz is an unknown quantity at this point
Re: Method From ColorImage

Okay so from reading what above ^. I'm assuming the best way to create work with ColorImage.threshold() and initializing a BinaryImage is to compile WPI?
Reply With Quote
  #10   Spotlight this post!  
Unread 26-06-2016, 13:40
euhlmann's Avatar
euhlmann euhlmann is offline
CTO, Programmer
AKA: Erik Uhlmann
FRC #2877 (LigerBots)
Team Role: Leadership
 
Join Date: Dec 2015
Rookie Year: 2015
Location: United States
Posts: 298
euhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud ofeuhlmann has much to be proud of
Re: Method From ColorImage

Quote:
Originally Posted by Ouroboroz View Post
Okay so from reading what above ^. I'm assuming the best way to create work with ColorImage.threshold() and initializing a BinaryImage is to compile WPI?
Well the point is that if you need to be able to construct a BinaryImage yourself, you should get your own copy of the wpilib source, make a public constructor for BinaryImage, and compile it together with your project.
__________________
Creator of SmartDashboard.js, an extensible nodejs/webkit replacement for SmartDashboard


https://ligerbots.org
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 09:35.

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