|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
Method From ColorImage
So the code for the threshold method is:
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: |
|
#2
|
||||
|
||||
|
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(); |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
Re: Method From ColorImage
Quote:
|
|
#5
|
||||
|
||||
|
Re: Method From ColorImage
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
}
|
|
#6
|
||||
|
||||
|
Re: Method From ColorImage
Quote:
As for an actual answer, you're not supposed to initialize a BinaryImage. You get them from methods like this one. |
|
#7
|
||||
|
||||
|
Re: Method From ColorImage
Quote:
Quote:
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? Last edited by euhlmann : 25-06-2016 at 18:14. |
|
#8
|
||||
|
||||
|
Re: Method From ColorImage
Quote:
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. |
|
#9
|
|||
|
|||
|
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?
|
|
#10
|
||||
|
||||
|
Re: Method From ColorImage
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.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|