Skip to content

java app crash when calling init(Mat image, Rect boundingBox) method of video module Tracker.java. #19915

@utibenkei

Description

@utibenkei
System information (version)
  • OpenCV => 4.5.2
  • Operating System / Platform => Windows 64 Bit:
  • Compiler => Visual Studio 2017
Detailed description

java app crash when calling init(Mat image, Rect boundingBox) method of video module Tracker.java.

The following code is generated by gen_java.py.
java_bindings_generator\gen\cpp\video.inl.hpp

//
//  void cv::Tracker::init(Mat image, Rect boundingBox)
//

JNIEXPORT void JNICALL Java_org_opencv_video_Tracker_init_10 (JNIEnv*, jclass, jlong, jlong, jint, jint, jint, jint);

JNIEXPORT void JNICALL Java_org_opencv_video_Tracker_init_10
  (JNIEnv* env, jclass , jlong self, jlong image_nativeObj, jint boundingBox_x, jint boundingBox_y, jint boundingBox_width, jint boundingBox_height)
{
    
    static const char method_name[] = "video::init_10()";
    try {
        LOGD("%s", method_name);
        cv::Tracker* me = (cv::Tracker*) self; //TODO: check for NULL
        Mat& image = *((Mat*)image_nativeObj);
        Rect boundingBox(boundingBox_x, boundingBox_y, boundingBox_width, boundingBox_height);
        me->init( image, boundingBox );
    } catch(const std::exception &e) {
        throwJavaException(env, &e, method_name);
    } catch (...) {
        throwJavaException(env, 0, method_name);
    }
}

When I change the code generated by gen_java.py to the following, it works fine. cv::Tracker* -> Ptr<cv::Tracker>*

//
//  void cv::Tracker::init(Mat image, Rect boundingBox)
//

JNIEXPORT void JNICALL Java_org_opencv_video_Tracker_init_10 (JNIEnv*, jclass, jlong, jlong, jint, jint, jint, jint);

JNIEXPORT void JNICALL Java_org_opencv_video_Tracker_init_10
  (JNIEnv* env, jclass , jlong self, jlong image_nativeObj, jint boundingBox_x, jint boundingBox_y, jint boundingBox_width, jint boundingBox_height)
{
    
    static const char method_name[] = "video::init_10()";
    try {
        LOGD("%s", method_name);
        Ptr<cv::Tracker>* me = (Ptr<cv::Tracker>*) self; //TODO: check for NULL
        Mat& image = *((Mat*)image_nativeObj);
        Rect boundingBox(boundingBox_x, boundingBox_y, boundingBox_width, boundingBox_height);
        (*me)->init( image, boundingBox );
    } catch(const std::exception &e) {
        throwJavaException(env, &e, method_name);
    } catch (...) {
        throwJavaException(env, 0, method_name);
    }
}
Steps to reproduce
Tracker tracker = TrackerMIL.create();
tracker.init( mat, rect);
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions