Ask Your Question

jcrist's profile - activity

2020-09-06 08:33:34 -0600 received badge  Nice Question (source)
2020-08-13 22:51:08 -0600 answered a question How to merge nearby rectangles

I found better solution without iterating through contours - by using numpy concatenate() function: concat = np.concate

2018-09-11 04:53:46 -0600 received badge  Popular Question (source)
2017-06-08 13:01:11 -0600 asked a question Guide on adding new types of parameters to opencv java wrappers

Dear OpenCV team!

If I want to extend list of types, which are wrapped automatically by OpenCV Almighty Java Wrapper Generator (let's call it JWG), how would I do that? Is there any documentation, best practices or how-to's?

Appreciate your help on this, I spent some time analyzing how this thing work and, to be honest, I would say that readability the code is not exactly the best possible.

I'd like to understand the proper way of wrapping parameters in the following cases:

  1. Exanple: std::vector<string>. I'd like to map it to List<string> in java
  2. Let's say there is a module xxx in opencv_contrib. which contains the type definition typedef vector<A> B; where vector is the class, which JWG knows how to wrap. However, all methods using arguments of B type are skipped by JWG. What is the right approach for fixing this problem?

I would be really grateful for pointing me at the right documentation were such documentation exist.

Best Regards

2017-06-03 11:38:03 -0600 answered a question Java wrappers for dnn module - missing protobuf headers?

I've made some progress in resolving this issue but not sure if this is the right approach or not. Seems like the problem is related to the way how include paths are configured in CMake for java module. The following changes are leading to successful compilation:

In the file /opencv_contrib/modules/dnn/cmake/OpenCVFindLibProtobuf.cmake, the following line:

set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_CPP_ROOT}/src")

is to be replaced with

set(PROTOBUF_INCLUDE_DIR "${PROTOBUF_CPP_ROOT}/src" PARENT_SCOPE)

The purpose of this change is to make the PROTOBUF_INCLUDE_DIR variable visible for the CMake script in the main repository.

The next step is to locate the following line in the /opencv/modules/java/CMakeLists.txt:

ocv_module_include_directories("${OpenCV_SOURCE_DIR}/include")

and insert the following code below this line:

if(BUILD_PROTOBUF)
    message(STATUS "PROTOBUF_INCLUDE_DIR=${PROTOBUF_INCLUDE_DIR}")
    ocv_module_include_directories("${PROTOBUF_INCLUDE_DIR}")
endif()

After these changes java wrappers are generated successfully for dnn module.

2017-06-03 09:25:38 -0600 asked a question Java wrappers for dnn module - missing protobuf headers?

Dear OpenCV team, need your help.

I'm trying to generate java wrappers for dnn module. I was able to overcome some of the issues but this one is really cumbersome. I get the following exception during compilation of java wrappers:

 In file included from /opencv/build/modules/java/gen/dnn.cpp:17:
/opencv_contrib/modules/dnn/misc/tensorflow/attr_value.pb.h:9:10: fatal error: 'google/protobuf/stubs/common.h' file not found
#include <google/protobuf/stubs/common.h>

It seems like the issue is somehow related to 3rdparty protobuf library, which is building from sources along with OpenCV (BUILD_PROTOBUF=ON). I can find the missing header in the folder /opencv/build/3rdparty/protobuf/protobuf-3.1.0/src/google/protobuf/stubs/common.h but this path seems to be non-visible for the compiler.

Please kindly advise what would be the correct approach to fix this problem.

2017-05-09 03:31:52 -0600 answered a question Java wrappers for OpenCV Text module

Ok, I've made some progress resolving this.

Assume we are to wrap a C++ method like void foo(const Ptr<t>& arg). Whenever gen_java.py meets the function parameter of type const Ptr<t>&, it generates the following JNI code:

java:

public void foo(T arg) {
      foo_0(arg.nativeObj);
      return;
}
private static native void foo_0(long arg_nativeObj);

JNI C wrapper

JNIEXPORT void JNICALL Java_org_opencv_<module>_<class>_foo_10 (JNIEnv* env, jclass jclass, jlong arg_nativeObj) {
      static const char method_name[] = "<module>::foo_10()";
      try{
             LOGD("%s", method_name);
             <module>::foo(Ptr<T>((T*) arg_nativeObj)); // NOTE: crash happens here
      } catch(const std::exception &e) {
             throwJavaException(env, &e, method_name);
      } catch (...) {
             throwJavaException(env, 0, method_name);
      }
      return;
}

The line noted above is leading to Java crash, However, if to replace it with the following, the crash is cured:

<module>::foo(*((Ptr<T> *) arg_nativeObj)); // Works fine

So I guess my question can be transformed to this: what is the scenario when we need to keep the original way of wrapping of const Ptr<t> & arg? Which modules/classes/methods use it?

2017-05-08 07:34:44 -0600 commented question Java wrappers for OpenCV Text module

hi berak, added all components as requested. Seems like nothing extraordinary but I may be missing something ...

2017-05-07 14:36:21 -0600 asked a question Java wrappers for OpenCV Text module

Dear OpenCV team! Need your help again and sorry for such a long question.

I'm trying to generate java wrappers for OpenCV OCR Text/Tesseract module, which is in contrib repository now. Here is what I managed so far (skipping all the trivial stuff like enabling contrib, installing tesseract etc):

  1. Changed modules/text/CMakeLists.txt, added "java".
  2. Added methods to ERFilter as follows:

    CV_EXPORTS_W Ptr<erfilter> createERFilterNM1(const String& filename, int thresholdDelta = 1, float minArea = (float)0.00025, float maxArea = (float)0.13, float minProbability = (float)0.4, bool nonMaxSuppression = true, float minProbabilityDiff = (float)0.1) { return createERFilterNM1(loadClassifierNM1(filename), thresholdDelta, minArea, maxArea, minProbability, nonMaxSuppression, minProbabilityDiff); }

    CV_EXPORTS_W Ptr<erfilter> createERFilterNM2(const String& filename, float minProbability = (float)0.3) { return createERFilterNM2(loadClassifierNM2(filename), minProbability); }

The idea was to merge interfaces loadClassifierNM1 and loadClassifierNM2 with "native" createERFilterNM1 and createERFilterNM2, respectively and get rid of necessity to wrap Ptr<erfilter::callback>& type in Java.

  1. Made ERFilter orphan - removed inheritance from Algorithm. I did not get the reason why it has to be inherited. The side effect of inheritance was - when java wrapper is handling method argumenths of type Ptr_* (like in the function detectRegions), it actually passes nativeObj field through JNI C wrapper. This field is declared as protected in Algorithm so it can be accessed only by children of Algorithm or by classes in the same package. Since Text is in different package and even different repository, the generation of java wrappers fails. Making ERFilter orphan helps to resolve this problem.

After these 3 steps java wrapper for Text module is generated successfully. However! This code crashes java with Exception Type EXC_BAD_ACCESS (SIGABRT):

private List<rect> findContours2(Mat img) { List<rect> boundRects = new ArrayList<rect>();

List<Mat> channels = new ArrayList<>();

Text.computeNMChannels(img, channels);

System.out.println("Extracting Class Specific Extremal Regions from "+channels.size()+" channels ...");

ERFilter erc1 = Text.createERFilterNM1(getClass().getResource(DEFAULT_CLASSIFIER_NM1).getPath(),16,0.00015f,0.13f,0.2f,true,0.1f);
ERFilter erc2 = Text.createERFilterNM2(getClass().getResource(DEFAULT_CLASSIFIER_NM2).getPath(), 0.5f);        

for(Mat channel : channels) {
    List<MatOfPoint> regions = new ArrayList<>();
    Text.detectRegions(channel, erc1, erc2, regions); // **Java fails here with Exception Type:        EXC_BAD_ACCESS (SIGABRT)**
    MatOfRect mor = new MatOfRect();
    Text.erGrouping(image, channel, regions, mor);

    for(Rect r : mor.toArray()) {
        boundRects.add(r);
    }
}

return boundRects;

}

The crash seems to be happening in JNI C layer. Here is the source generated for detectRegions method:

JNIEXPORT void JNICALL Java_org_opencv_text_Text_detectRegions_10 (JNIEnv*, jclass, jlong, jlong, jlong, jlong);

JNIEXPORT void JNICALL Java_org_opencv_text_Text_detectRegions_10
  (JNIEnv* env, jclass , jlong image_nativeObj, jlong er_filter1_nativeObj, jlong er_filter2_nativeObj, jlong regions_mat_nativeObj)
{
    static const char method_name[] = "text::detectRegions_10()";
    try {
        LOGD("%s", method_name);
        std::vector< std::vector<Point> > regions;
        Mat& regions_mat = *((Mat*)regions_mat_nativeObj);
        Mat& image = *((Mat*)image_nativeObj);
        cv::text::detectRegions( image, Ptr<cv::text::ERFilter>((cv::text::ERFilter*)er_filter1_nativeObj), Ptr<cv::text::ERFilter>((cv::text::ERFilter*)er_filter2_nativeObj), regions );
        vector_vector_Point_to_Mat( regions, regions_mat );
        return;
    } catch(const std::exception &e) {
        throwJavaException(env, &e, method_name);
    } catch (...) {
        throwJavaException(env, 0, method_name);
    }
    return;
}

It seems the Ptr pointer is used incorrectly but I can't figure out the correct way ... (more)

2017-02-26 03:59:47 -0600 received badge  Supporter (source)
2016-12-05 14:34:05 -0600 answered a question fatal error: 'jni.h' file not found

Found the answer. For some reason the path to old JDK was preserved in the cmake settings so it was pointing to non-existing folder. Here is the fix:

  1. run ccmake .. in opencv/build folder
  2. toggle advanced mode (press 't')
  3. found and changed JNI paths.

This is just in case if anybody will face the similar problem after upgrade of xcode/jdk.

2016-12-05 14:08:18 -0600 asked a question fatal error: 'jni.h' file not found

Hello,

I encountered really strange issue, which appeared recently most likely due to XCode/Java updates. Here is my setup:

  • OSX EL Capitan 10.11.6
  • Xcode Version 8.1 (8B62)
  • java version "1.8.0_111"
  • Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
  • Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

My codebase is: commit 6c12533160bc5e6de1f09847d9cd6dd548667a55 Merge: 811eb76 bec3479 Author: Alexander Alekhin [email protected] Date: Mon Oct 31 17:35:41 2016 +0000

Previously I was able to build opencv master from sources with no issues but when I'm trying to build it now, it cannot find jni.h!:

/opencv/modules/java/generator/src/cpp/common.h:8:10: fatal error: 'jni.h' file not found
#include <jni.h>

Appreciate any ideas or hints how to fix this? JAVA_HOME is pointing at correct folder and also include folder is there and jni.h is where it should be ...

2016-11-02 09:09:56 -0600 commented question How is OpenCV project being managed?

One good example is Eclipse - I think they put a lot of good thoughts in the contribution process.

2016-11-01 23:19:15 -0600 commented question How is OpenCV project being managed?

Sure. Is there a list of features or may be new modules, which are planned for the next release? When is the tentative date for the next release? Is there a long-term roadmap? Is there a way for community to suggest new modules/new projects and may be vote for it? Another set of questions is related to backward compatibility with previous releases and versioning of algorithms. Take MSER as an example. Without going too deep in details - this algorithm produces totally different results in ver 3.1 compared to 3.0.0-rc-1 to say nothing about 2.4. Is there a way to understand what triggered this change and why the new implementation is better than the one in the previous versions? I ran through the commits - seems like some refactoring was going on but why it impacted results?

2016-11-01 11:38:34 -0600 commented question How is OpenCV project being managed?

By the way, managing roadmaps could be done using opensource tools. Some people advise Redmine - it seems to be good open source project management tool. I don't have much experience with it but it may solve at least problem of managing releases and roadmaps. Integration with git is also a big plus.

2016-11-01 10:11:23 -0600 asked a question How is OpenCV project being managed?

Dear OpenCV team! I have one generic question - is the opencv project being managed by anyone or not really? For example:

  • How is the decision being made on whether particular contribution is inline with OpenCV roadmap or not? Is there any release plan available for public?
  • Who and how decides whether to remove or update an existing interface? I've seen many changes in recent version (3.1), which break previously available interface (3.0.0-rc1 or 2.4.x). I believe such changes should be discussed with community as we humble users )) expect that opencv versions are backward compatible at least within one release.
  • Some of popular algorithms are also changing very dramatically even within one major release. For example, MSER feature detector produces substantially different number of feature points in version 3.0.0-rc1 and 3.1 on the same image. This is very unexpected situation as it is essentially deterring users from upgrading to a newer version. Just an idea - can we have a compiler flag, which enforces backward compatibility on the underlying algorithm level with previous versions? Another alternative is to keep older versions of algorithms with the ability to switch them on or off during compilation from source (for example, MSER 3.0, MSER 3.1 etc).

OpenCV is really cool staff but after playng a bit with it I got an impression (may be totally wrong) that there is no management at all; contributions are sometimes poorly explained and it is not always clear what is driving them.

2016-11-01 09:31:17 -0600 commented question VideoCapture is not working after building opencv 3.1 in Java

This looks like the old issue, should be already fixed in the upstream. capture.release() is not yet fixed.

2016-10-17 13:19:22 -0600 commented question VideoCapture is not working after building opencv 3.1 in Java

when exactly your code is crashing? Is it at the moment when the capture is released or earlier?

2016-10-15 04:43:37 -0600 asked a question FAST + BRIEF test case is failing

I stumbled upon this issue when trying to revive java autotests for OpenCV 3.1. The test case BruteForceHammingDescriptorMatcherTest.testRadiusMatchMatListOfListOfDMatchFloat is failing and I'm trying to understand why. I hope it was working a few releases of OpenCV ago so this may mean that we have regression issue.

The test case is simple - it generates 2 similar images ("query" and "train"), calculates descriptors for them using FAST feature detection and BRIEF extractor and then applies BFMatcher with norm = BRUTEFORCE_HAMMING. Expected result is 4 matches with the radius = 50 but in fact no matches are detected on the latest build of OpenCV 3.1 (upstream/master (4ed40fd6946269ea36c58e5c76a277e7a871c269).

Code generating query image:

private static Mat getQueryImg(int matSize) {
    Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
    Imgproc.line(img, new Point(40, matSize - 40), 
                        new Point(matSize - 50, 50), new Scalar(0), 8);
    return img;
}

Resulting image is like this (matSize=300):

image description Screen Shot 2016-10-15 at 12.56.20 PM.png

and with detected keypoints:

image description Screen Shot 2016-10-15 at 12.56.26 PM.png

Code generating "train" image:

private static Mat getTrainImg(int matSize) {
    Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
    Imgproc.line(img, new Point(40, 40), 
                        new Point(matSize - 40, matSize - 40), new Scalar(0), 8);
    return img;
}

Resulting image (matSize=300):

image description Screen Shot 2016-10-15 at 12.55.26 PM.png

and with keypoints

image description Screen Shot 2016-10-15 at 12.55.35 PM.png

The resulting descriptors for "query" and "train" both have 4 vectors, like this:

query:

Mat [ 4*32*CV_8UC1, isCont=true, isSubmat=false, nativeObj=0x7ffdfbe81990, dataAddr=0x7ffdfbc7f640 ]

Element size=1 Total elements=128 24.0 0.0 76.0 9.0 44.0 171.0 68.0 193.0 148.0 170.0 24.0 128.0 40.0 140.0 6.0 156.0 102.0 248.0 26.0 145.0 1.0 136.0 201.0 24.0 196.0 216.0 68.0 106.0 240.0 200.0 72.0 103.0 176.0 49.0 48.0 193.0 32.0 233.0 65.0 147.0 150.0 90.0 80.0 35.0 64.0 1.0 28.0 149.0 168.0 112.0 38.0 129.0 216.0 144.0 251.0 128.0 208.0 92.0 69.0 224.0 80.0 209.0 77.0 44.0 160.0 168.0 78.0 8.0 30.0 98.0 86.0 42.0 16.0 235.0 21.0 147.0 142.0 96.0 79.0 180.0 92.0 66.0 148.0 94.0 37.0 33.0 192.0 221.0 4.0 105.0 192.0 40.0 5.0 232.0 226.0 197.0 165.0 56.0 31.0 11.0 8.0 100.0 66.0 50.0 138.0 106.0 21.0 231.0 15.0 18.0 223.0 181.0 216.0 64 ... (more)

2016-10-08 06:25:23 -0600 received badge  Self-Learner (source)
2016-10-08 06:23:23 -0600 answered a question Java tests for OpenCV 3.1 desktop

Here is what I found but I'm not sure if this is the right way or not. The make process actually prints out the jar name of the junit tests for OpenCV java wrappers (opencv-test.jar). Here is how to run it.

  1. Install JRE for your platform. I have Mac so further examples will work for unix and the likes. MS Win I guess works in the similar fashion, just need to use proper path syntax.
  2. Navigate to /opencv/build folder and run the following command:

    java -cp ./modules/java/pure_test/.build/lib/junit-4.11.jar:./modules/java/pure_test/.build/build/jar/opencv-test.jar:./bin/opencv-310.jar -Djava.library.path="./lib" junit.textui.TestRunner org.opencv.test.opencv-package-name.test-class-name

opencv-package-name stands for the name of the corresponding opencv module, for example calib3d, core, features2d, highgui, imgproc, objdetect, photo, utils, video etc.

test-class-name can be any class from that package, which inherits from OpenCVTestCase. For example:

java -cp ./modules/java/pure_test/.build/lib/junit-4.11.jar:./modules/java/pure_test/.build/build/jar/opencv-test.jar:./bin/opencv-310.jar -Djava.library.path="./lib" junit.textui.TestRunner org.opencv.test.utils.ConvertersTest

will produce the following output:

.........................................

Time: 0.295

OK (41 tests)

UPDATE: as expected things are much more simple than we think of them initially )) OpenCV good team did great job already - all tests including java tests can be run from the build directory by this command:

python ../modules/ts/misc/run.py

more information is here. The only confusing part of documentation - seems like this command actually runs all tests so it can be used not only for performance control.

2016-10-08 04:12:35 -0600 commented answer Java tests for OpenCV 3.1 desktop

Thank you berak, will try to dig it a beet deeper and will let you know.

2016-10-08 01:09:27 -0600 commented answer Java tests for OpenCV 3.1 desktop

Thank you for the prompt answer! Is there any guideline how build and run them locally?

2016-10-08 01:08:59 -0600 marked best answer Java tests for OpenCV 3.1 desktop

Are there any automated tests included in nightly builds for testing java wrappers? What is the process of contributing tests to OpenCV?