added documentation to wrap up ijopencv tests

This commit is contained in:
Guillaume Raffy 2019-04-12 16:28:08 +02:00
parent 14d3535388
commit dcfa11694c
1 changed files with 84 additions and 62 deletions

View File

@ -1,3 +1,87 @@
# This file deals with tests of imagej's ijopencv solution to use opencv in imagej
# https://imagej.net/Jython_Scripting#Using_openCV_in_Jython and https://github.com/joheras/IJ-OpenCV/wiki provides a necessary but (too) basic documentation,
# https://github.com/bytedeco/javacv-examples/blob/master/OpenCV_Cookbook/README.md says :
# "OpenCV (Open Source Computer Vision) is a library of several hundred algorithms for computer vision and video analysis. OpenCV can be us on JVM using two approaches. First are Java wrappers provided by OpenCV. Second are are wrappers based on JavaCPP (C++ wrapper engine for JVM) called OpenCV JavaCPP Presets. There are also JavaCPP presets for other computer vision related libraries like: FFmpeg, libdc1394, PGR FlyCapture, OpenKinect, videoInput, ARToolKitPlus, flandmark, and others. JavaCV combines libraries in JavaCPP Presets and add some additional functionality that makes them easier use on JVM."
# Here's what I've worked out by testing ijopencv :
# 1. ijopencv is a solution based on javacpp (http://bytedeco.org/)
# 2. javacpp provides java wrappers for a lot of c++ libraries such as opencv. A javacpp version is tied with a specific opencv version :
# - javacpp 1.4.2 uses opencv 3.4.2 (https://github.com/bytedeco/javacpp-presets/tree/1.4.2/opencv)
# - javacpp 1.5 uses opencv 4.0.1 (https://github.com/bytedeco/javacpp-presets/tree/1.5/opencv)
# 3. javacpp is not responsible for the python binding
# 4. jython exposes java classes and functions as python classes and functions. As a result, the java api of javacpp is exposed by jython as the python api org.bytedeco.javacpp.* (eg org.bytedeco.javacpp.opencv_core)
# 5. as aresult of 4, javacpp's python api for opencv is not as practical as opencv's python api: for example, it doesn't seem possible to access pixel data using image[x, y]. As a result, a python code written using opencv's javacpp api is not compatible with a python code using opencv vi opencv's python wrappers.
# 6. as a result of 4, the documentation for org.bytedeco.javacpp's functions and arguments can be found in http://bytedeco.org/javacpp/apidocs/ in the form of java functions. As this url only shows the latest version (javacpp 1.5.1), here's a way to find the functions that are available with your javacpp :
# [OK]graffy@pr079234:~/toto[19:20:37]>git clone https://github.com/bytedeco/javacpp-presets.git
# [OK]graffy@pr079234:~/toto[19:21:17]>cd javacpp-presets
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:21:37]>git checkout tags/1.4.2
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:21:57]>git branch
# * (HEAD detached at 1.4.2)
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:18:33]>grep -A 2 "void cvCalcHist" ./opencv/src/main/java/org/bytedeco/javacpp/opencv_imgproc.java
# public static native void cvCalcHist( @Cast("IplImage**") PointerPointer image, CvHistogram hist,
# int accumulate/*=0*/,
# @Const CvArr mask/*=NULL*/ );
# --
# public static native void cvCalcHist( @ByPtrPtr IplImage image, CvHistogram hist );
# public static native void cvCalcHist( @ByPtrPtr IplImage image, CvHistogram hist,
# int accumulate/*=0*/,
# @Const CvArr mask/*=NULL*/ );
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:18:41]>grep -A 2 "void cvCalcHist" ./opencv/src/main/java/org/bytedeco/javacpp/helper/opencv_imgproc.java
# public static void cvCalcHist(IplImage[] arr, CvHistogram hist, int accumulate/*=0*/, CvArr mask/*=null*/) {
# org.bytedeco.javacpp.opencv_imgproc.cvCalcHist(new IplImageArray(arr), hist, accumulate, mask);
# }
# --
# public static void cvCalcHist(IplImageArray arr, CvHistogram hist,
# int accumulate/*=0*/, CvArr mask/*=null*/) {
# org.bytedeco.javacpp.opencv_imgproc.cvCalcArrHist(arr, hist, accumulate, mask);
# 7 javacpp's python api doesn't seem to support keyword arguments
#
# 8 as org.bytedeco.javacpp.opencv* knows nothing about imagej, the package ijopencv provides conversion functions that convert images from imagej's ImageProcessor to org.bytedeco.javacpp.opencv_core.Mat and vice versa
# histogram = opencv_imgproc.calcHist(images=[src_image], channels=[0], mask=None, histSize=[256], ranges=[0, 256])
# histogram = opencv_imgproc.calcHist(src_image, 0, None, 3, [256], [0.0, 256.0], True, False)
# print(dir(opencv_imgproc))
# help(opencv_imgproc.cvCalcHist)
# opencv_imgproc.calcHist(src_image, None, histogram)
# histogram = opencv_imgproc.cvCalcHist(src_image, None, [256], [0.0, 256.0])
# import inspect
# lines = inspect.getsource(opencv_imgproc.calcHist)
# opencv_imgproc.calcHist(src_image, histogram)
# there are 2 calcHist functions in /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2.jar, and they take 6 or 7 arguments :
# jar -xvf /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2.jar
# [1]graffy@pr079234:~/toto/jython[15:18:17]>javap ./org/opencv/imgproc/Imgproc.class | grep calcHist
# public static void calcHist(java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.MatOfInt, org.opencv.core.MatOfFloat, boolean);
# public static void calcHist(java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.MatOfInt, org.opencv.core.MatOfFloat);
#
# jar -xvf /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2-macosx-x86_64.jar
# [OK]graffy@pr079234:~/toto/jython[19:02:28]>grep -A 5 "calcHist(" org/bytedeco/javacpp/macosx-x86_64/include/opencv2/imgproc.hpp
# CV_EXPORTS void calcHist( const Mat* images, int nimages,
# const int* channels, InputArray mask,
# OutputArray hist, int dims, const int* histSize,
# const float** ranges, bool uniform = true, bool accumulate = false );
# /** @overload
# --
# CV_EXPORTS void calcHist( const Mat* images, int nimages,
# const int* channels, InputArray mask,
# SparseMat& hist, int dims,
# const int* histSize, const float** ranges,
# bool uniform = true, bool accumulate = false );
# --
# CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
# const std::vector<int>& channels,
# InputArray mask, OutputArray hist,
# const std::vector<int>& histSize,
# const std::vector<float>& ranges,
# bool accumulate = false );
from ij import IJ # pylint: disable=import-error
from ijopencv.ij import ImagePlusMatConverter # pylint: disable=import-error
from ijopencv.opencv import MatImagePlusConverter # pylint: disable=import-error
@ -112,68 +196,6 @@ def test_opencv_calc_hist():
test_opencv_calc_hist7()
# histogram = opencv_imgproc.calcHist(images=[src_image], channels=[0], mask=None, histSize=[256], ranges=[0, 256])
# histogram = opencv_imgproc.calcHist(src_image, 0, None, 3, [256], [0.0, 256.0], True, False)
# print(dir(opencv_imgproc))
# help(opencv_imgproc.cvCalcHist)
# opencv_imgproc.calcHist(src_image, None, histogram)
# histogram = opencv_imgproc.cvCalcHist(src_image, None, [256], [0.0, 256.0])
# import inspect
# lines = inspect.getsource(opencv_imgproc.calcHist)
# opencv_imgproc.calcHist(src_image, histogram)
# there are 2 calcHist functions in /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2.jar, and they take 6 or 7 arguments :
# jar -xvf /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2.jar
# [1]graffy@pr079234:~/toto/jython[15:18:17]>javap ./org/opencv/imgproc/Imgproc.class | grep calcHist
# public static void calcHist(java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.MatOfInt, org.opencv.core.MatOfFloat, boolean);
# public static void calcHist(java.util.List<org.opencv.core.Mat>, org.opencv.core.MatOfInt, org.opencv.core.Mat, org.opencv.core.Mat, org.opencv.core.MatOfInt, org.opencv.core.MatOfFloat);
#
# jar -xvf /Applications/Fiji.app/jars/opencv-3.4.2-1.4.2-macosx-x86_64.jar
# [OK]graffy@pr079234:~/toto/jython[19:02:28]>grep -A 5 "calcHist(" org/bytedeco/javacpp/macosx-x86_64/include/opencv2/imgproc.hpp
# CV_EXPORTS void calcHist( const Mat* images, int nimages,
# const int* channels, InputArray mask,
# OutputArray hist, int dims, const int* histSize,
# const float** ranges, bool uniform = true, bool accumulate = false );
# /** @overload
# --
# CV_EXPORTS void calcHist( const Mat* images, int nimages,
# const int* channels, InputArray mask,
# SparseMat& hist, int dims,
# const int* histSize, const float** ranges,
# bool uniform = true, bool accumulate = false );
# --
# CV_EXPORTS_W void calcHist( InputArrayOfArrays images,
# const std::vector<int>& channels,
# InputArray mask, OutputArray hist,
# const std::vector<int>& histSize,
# const std::vector<float>& ranges,
# bool accumulate = false );
# git checkout tags/1.4.2
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:21:57]>git branch
# * (HEAD detached at 1.4.2)
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:18:33]>grep -A 2 "void cvCalcHist" ./opencv/src/main/java/org/bytedeco/javacpp/opencv_imgproc.java
# public static native void cvCalcHist( @Cast("IplImage**") PointerPointer image, CvHistogram hist,
# int accumulate/*=0*/,
# @Const CvArr mask/*=NULL*/ );
# --
# public static native void cvCalcHist( @ByPtrPtr IplImage image, CvHistogram hist );
# public static native void cvCalcHist( @ByPtrPtr IplImage image, CvHistogram hist,
# int accumulate/*=0*/,
# @Const CvArr mask/*=NULL*/ );
# [OK]graffy@pr079234:~/toto/javacpp-presets[19:18:41]>grep -A 2 "void cvCalcHist" ./opencv/src/main/java/org/bytedeco/javacpp/helper/opencv_imgproc.java
# public static void cvCalcHist(IplImage[] arr, CvHistogram hist, int accumulate/*=0*/, CvArr mask/*=null*/) {
# org.bytedeco.javacpp.opencv_imgproc.cvCalcHist(new IplImageArray(arr), hist, accumulate, mask);
# }
# --
# public static void cvCalcHist(IplImageArray arr, CvHistogram hist,
# int accumulate/*=0*/, CvArr mask/*=null*/) {
# org.bytedeco.javacpp.opencv_imgproc.cvCalcArrHist(arr, hist, accumulate, mask);
def create_test_image_file(image_file_path):
image = opencv_core.Mat().zeros(128, 128, opencv_core.CV_8U).asMat()