Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Johan Vos
    @johanvos
    If you have good ideas for demos, let me know. Training on device is possible, so demos that take advantage of that are great. And yes, they are pocket warmers :)
    Eduardo Gonzalez
    @wmeddie
    The demo I want to work on is 3d reconstruction from the camera. there’s a couple of papers that do that for simple images, but it’s pretty hard for real world ones. https://paperswithcode.com/paper/soft-rasterizer-a-differentiable-renderer-for
    Johan Vos
    @johanvos
    sounds like a great usecase indeed
    🤔
    Samuel Audet
    @saudet
    They don't give any numbers, but it's probably not 10x faster, maybe 2x
    Eduardo Gonzalez
    @wmeddie
    Kind of cool getting java exceptions in a C++ program. Sure, that’s not crazy or new or anythin but still.
    image.png
    Just need to find the native-image xml files I made last time a long time ago….
    Samuel Audet
    @saudet
    I think @johanvos has what you need
    Johan Vos
    @johanvos
    I'm working on the android and ios parts, but I can maybe publish the desktop versions already
    Nick H
    @nicholashendrickx
    Hi @saudet. I was wondering if you have done any benchmark testing for how long a javacpp native call takes.
    Samuel Audet
    @saudet
    The same as JNI, about 30 ns on average, for example: https://github.com/oracle/graal/issues/885#issuecomment-456299353
    Nick H
    @nicholashendrickx
    thanks, i know what i should be looking out for then!
    Nick H
    @nicholashendrickx
    so i was doing some benchmarking for my use case and I am seeing about 25 microseconds on the average call.
    the timing that I am doing is c++ calling a java object method that i passed to the c++ section. the java object is extending from a pure vitrual c++ class. I originally thought it might have been all of the arguments that was being passed through on the method signature, but then i changed it to just call an empty method with no arguments and I was still seeing about the same timestamps.
    I understand that this is a different use case from what you sent, but it seems like it shouldn't be orders of magnitude slower
    Nick H
    @nicholashendrickx

    I made a very simple program that gives an object created in java from a virtual c++ class to a c++ thread and just have it call a method on the virtual class. the method does nothing and takes no arguments, however it is taking around 14 microseconds to make that call. better then the 25 i mentioned earlier, but still pretty slow. It is also GCing like crazy when i put on gc logging.

    I ran a test that timed empty method calls from java to cpp and i got the results that you posted above... about 30 nanoseconds per call.

    so it seems like that doing callbacks is very expensive. is that something that is expected?

    Samuel Audet
    @saudet
    Callbacks in JNI are an order of magnitude slower, yes. If you're seeing lots of GC going on, you're probably on a thread not created in Java and it's forced to reinitialize it on each call. Make sure that doesn't happen
    Nick H
    @nicholashendrickx
    hmm, that is exactly what I am seeing then. I don't really have control of the thread that is being spawned, just the results of the thread. so then I think the best route to go without having control of the c++ thread then would be to store the results from the c++ initialized thread in a thread safe container in c++, then poll that container from java?
    Samuel Audet
    @saudet
    If the thread is never deallocated, it's possible to tell that to JavaCPP and it will initialize it only once and never detach it by setting the NO_JNI_DETACH_THREAD, for example, this way: https://github.com/bytedeco/javacpp/issues/143#issuecomment-262138799
    Samuel Audet
    @saudet
    Actually, according to various sources, the hack that @tmm1 created for pthreads on Android should also work fine with OpenJDK, so I've enabled that in the commit bytedeco/javacpp@89d6069. As long as you're not on Windows, that should do what you need automatically.
    Nick H
    @nicholashendrickx
    awesome, thanks, ill give that a go
    Nick H
    @nicholashendrickx
    i guess i should have asked this too, but since the callbacks in JNI are slow, does that also mean the return of a value when calling a native method also somewhat slow
    Samuel Audet
    @saudet
    No, calling native functions is fast, but if you mean returning an object, that calls the constructor, so yeah
    Nick H
    @nicholashendrickx
    sounds good, seems about inline with my benchmarkings.
    Nick H
    @nicholashendrickx
    Hi @saudet is there anyway around creating garbage when returning an object from a jni call.
    Samuel Audet
    @saudet
    If you have a function that returns its first argument, it takes the fast path and returns the same Pointer. No new object gets created.
    Nick H
    @nicholashendrickx
    do you mean like if the c++ method is something like
    Object getObject(Object obj)?
    Samuel Audet
    @saudet
    Well, not Object, but Pointer, yes something like that.
    Samuel Audet
    @saudet
    Actually, that works for static functions. For member functions, the "first argument" is this.
    Samuel Audet
    @saudet
    Do you have a specific use case in mind? It might not be too hard to add...
    Nick H
    @nicholashendrickx
    the use case is returning a struct of data from the c++ layer into java without creating a new object on every call
    Samuel Audet
    @saudet
    We can just pass the struct as an argument, right?
    Nick H
    @nicholashendrickx
    right, i was trying that. first with just a void method with the struct passed through to the c++ layer but the struct didnt seem to update, so i am returning a struct as well in the method. I haven't looked to deep into the documentation, but there isn't a struct equivalent that I need to make in java, right? Its just a pointer object
    Samuel Audet
    @saudet
    Well, if you pass an object by value, it's not going to get updated, no. You'll need to pass it by reference or as a pointer, which is how JavaCPP allocates structs, but they can be passed by value when necessary.
    Nick H
    @nicholashendrickx
    I think I was passing it by reference...... but maybe i wasn't
    Nick H
    @nicholashendrickx
    but just so i am understanding you correctly, i dont even need to return the struct like you said originally. I can just do `void populateObject(Object& obj)'
    Samuel Audet
    @saudet
    Yes, that's how passing by reference works in C++. It works pretty much like in Java
    Cotfas VLAD NICOLAE
    @cotfas
    hello
    i have a crash
    Stack: [0x0000700005eeb000,0x0000700005feb000], sp=0x0000700005fe5e80, free space=1003k
    Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
    C [libsystem_platform.dylib+0x929] _platform_memmove$VARIANT$Haswell+0x29
    C [libopencv_core.3.2.dylib+0x614ee] _ZNK2cv3Mat6copyToERKNS_12_OutputArrayE+0xc2e
    C [libopencv_core.3.2.dylib+0x147077] _ZNK2cv11_InputArray6copyToERKNS_12_OutputArrayE+0x387
    C [libopencv_imgproc.3.2.dylib+0x276b7] _ZN2cv8cvtColorERKNS_11_InputArrayERKNS_12_OutputArrayEii+0x257
    C [libjniopencv_imgproc.dylib+0x7be79] Java_org_bytedeco_javacpp_opencv_1imgproc_cvtColor__Lorg_bytedeco_javacpp_opencv_1core_00024Mat_2Lorg_bytedeco_javacpp_opencv_1core_00024Mat_2I+0xf9
    mac os x catalina
        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>opencv-platform</artifactId>
            <version>${javacv.presets.version}</version>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacpp</artifactId>
            <version>${javacv.version}</version>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv</artifactId>
            <version>${javacv.version}</version>
        </dependency>
        <javacv.version>1.3.3</javacv.version>
        <javacv.presets.version>3.2.0-1.3</javacv.presets.version>

    Mat matrix = new OpenCVFrameConverter.ToMat().convert(new Java2DFrameConverter().convert(bufferedImage));
    Mat grayMatrix = new Mat(matrix.size(), CV_8UC1);
    if (matrix.channels() == 4) {
    cvtColor(matrix, matrix, CV_BGRA2BGR); <<< crashing here with SIGSEGV on 6k/9k pixel image
    }

    A fatal error has been detected by the Java Runtime Environment:

    #

    SIGSEGV (0xb) at pc=0x00007fff6f52d929, pid=10594, tid=0x000000000001b923

    #

    JRE version: Java(TM) SE Runtime Environment (8.0_261-b12) (build 1.8.0_261-b12)

    Java VM: Java HotSpot(TM) 64-Bit Server VM (25.261-b12 mixed mode bsd-amd64 compressed oops)

    Problematic frame:

    C [libsystem_platform.dylib+0x929] _platform_memmove$VARIANT$Haswell+0x29

    Samuel Audet
    @saudet
    Please try again with JavaCV 1.5.4.
    trippy22
    @trippy22
    im trying to solve a puzzle with opencv, i have some clean templates that i want to match to, and then some very noisy images (which will be matched to the template)
    no luck though so far i think whatever im doing isnt enough because the images are filled with noise
    Samuel Audet
    @saudet
    Try to match it at a lower scale, such the noise gets smoothed out
    Samuel Audet
    @saudet
    @supergrecko Would you be able to help this guy? https://stackoverflow.com/questions/65634369/llvm-ir-with-java-api