-
Notifications
You must be signed in to change notification settings - Fork 744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add/subtract/multiply/divide by Scalar? #1064
Comments
Wrapping them in a Mat should work. Let me know if it doesn't work though.
|
No, it doesn't work, unless I'm doing something wrong: private void applyColors(Mat bgra, Scalar leftColor, Scalar midColor, Scalar rightColor) {
Mat leftRegion = new Mat(bgra, new Rect(0, 0, 175, bgra.rows()));
Mat midRegion = new Mat(bgra, new Rect(175, 0, 175, bgra.rows()));
Mat rightRegion = new Mat(bgra, new Rect(350, 0, 175, bgra.rows()));
multiply(leftRegion, new Mat(leftColor), leftRegion, 1.0 / 255.0, bgra.type());
multiply(midRegion, new Mat(midColor), midRegion, 1.0 / 255.0, bgra.type());
multiply(rightRegion, new Mat(rightColor), rightRegion, 1.0 / 255.0, bgra.type());
} Exception:
|
This works, but if I understand it correctly, it allocates three additional Mats: private void applyColors(Mat bgra, Scalar leftColor, Scalar midColor, Scalar rightColor) {
Mat leftRegion = new Mat(bgra, new Rect(0, 0, 175, bgra.rows()));
Mat midRegion = new Mat(bgra, new Rect(175, 0, 175, bgra.rows()));
Mat rightRegion = new Mat(bgra, new Rect(350, 0, 175, bgra.rows()));
Mat leftMul = new Mat(leftRegion.rows(), leftRegion.cols(), leftRegion.type(), leftColor);
Mat midMul = new Mat(midRegion.rows(), midRegion.cols(), midRegion.type(), midColor);
Mat rightMul = new Mat(rightRegion.rows(), rightRegion.cols(), rightRegion.type(), rightColor);
multiply(leftRegion, leftMul, leftRegion, 1.0 / 255.0, bgra.type());
multiply(midRegion, midMul, midRegion, 1.0 / 255.0, bgra.type());
multiply(rightRegion, rightMul, rightRegion, 1.0 / 255.0, bgra.type());
} |
Ah, I see, that's a regression from commit 2874998. @HGuillemet Could you please fix this? |
I don't think there is a regression
Gives But it seems that when a function taking an In the example above, replacing We could change the |
@HGuillemet I see, I had not confirmed before replying, sorry. So it looks like that function wants a vector. Thanks for checking! @b005t3r Does it work if you give it a vector like that? |
I think I like the Thanks, guys! |
Before we implement such method, can you try to replace the Mat creation in your code with something like |
OK, I tested that and it doesn't crash, but it also doesn't work - there's no color change in the resulting mat. |
I see: And |
Each Scalar has 4 values, but for 1 of those, the size is 1, just like it is in a C/C++ array. |
So |
Yes, that's what it should be returning already...
|
I does not, because of Can you think of a way to enable in Java the polymorphism that the proxy classes |
Ah, right, I had hard coded those methods of
We could map |
…mitive types (issue bytedeco/javacpp-presets#1064) * Throw more accurate `UnsatisfiedLinkError` when `Loader.load()` fails to find JNI libraries
I see, it's because @b005t3r Please give it a try with the snapshots: http://bytedeco.org/builds/ |
It looks like |
I'm not convinced by your commit. You do fix the returned value of
For instance |
Wouldn't it work if we define an empty "tag" interface EDIT: I guess it won't, since the C++ method will treat arguments received this way as instances of the C++ class InputArray while they are not, and it won't create the proxy instances. |
If there is no easy way to pass directly the scalar to methods taking |
Sure, of course, it's not ideal. Ideally, we would be mapping class templates like
Yeah, there's a missing override of
Yes, OpenCV changed how
Right, we'd need to create another API on top of the C++ API.
It'd be confusing to have the default value of that flag depend on the source of data. I think it's fine with |
What about simply inheriting from Pointer and not DoublePointer ?If there are methods of
Ok. |
We need setters and getters.
Actually, while we're at it, we should also update the constructors taking Java arrays to create column vectors instead of row vectors, to make it consistent with (newish) C++ constructors such as |
Hum, |
… of arrays for consistency (issue #1064)
I've changed the constructors for |
Sorry for not being responsive and available for testing things those days. |
Can we consider this "fixed"? What do you think @b005t3r? |
I haven't tested the change yet and I'm not sure when I will, so please mark it as fixed if you think it's fixed enough :) |
Sounds good, please reopen if you encounter with any issues with that the next time. Thanks for reporting! |
Is it even possible to use functions like add() or multiply() with Scalars (e.g. to multiply each element of a Mat by a given Scalar value)? I don't see a way of doing that.
The text was updated successfully, but these errors were encountered: