IJ-opencv - crash when converting from PointRoi to KeypointVector

jython
imagej
opencv

#1

I found out that the conversion from KeypointVector to PointRoi works but the opposite makes Fiji to crash.
I dont really see what can make Fiji crash in the source code, some dependencies maybe ?

#@ ImagePlus imp 
'''
Detect keypoints in an image using SIFT via opencv 
The function works only on 8-bit images 
'''
from ij 										import IJ
from ijopencv.ij                                import ImagePlusMatConverter , PointRoiKeyPointVectorConverter
from ijopencv.opencv                            import KeyPointVectorPointRoiConverter
from ij.gui 									import PointRoi
from org.bytedeco.javacpp						import opencv_xfeatures2d
from org.bytedeco.javacpp.opencv_core			import Mat, KeyPoint, KeyPointVector, CV_8UC1

# Comvert to 8-bit image
IJ.run(imp, "8-bit", "");

# Convert image to an opencv matrix 
ImConverter = ImagePlusMatConverter() 
ImCV = ImConverter.toMat(imp.getProcessor()) 
 
# Initialise recipient variables 
KpCV = KeyPointVector() 
Des	 = Mat() 
Mask = Mat().ones(ImCV.arrayHeight(),ImCV.arrayWidth(),CV_8UC1).asMat() # use a matrix of ones for the mask 
 
# Detect and describe keypoint 
SIFT = opencv_xfeatures2d.SIFT.create() 
SIFT.detectAndCompute(ImCV,Mask,KpCV,Des)   

# Convert detected keypoints to point roi
kp2roi = KeyPointVectorPointRoiConverter()

# Both options work, the first one is a bit cleaner (less bracket)
MultiPointRoi = kp2roi.convert(KpCV, PointRoi().__class__) 
MultiPointRoi = kp2roi.convert(KpCV, type(PointRoi()))
print MultiPointRoi

# Testing opposite conversion (from Fiji to opencv)
roi2kp = PointRoiKeyPointVectorConverter()
NewKp  = roi2kp.convert(MultiPointRoi, KeyPointVector().__class__) # crashes

The crash report in fiji.app is quite long but here is an extract :

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  org.bytedeco.javacpp.opencv_core$KeyPointVector.put(JLorg/bytedeco/javacpp/opencv_core$KeyPoint;)Lorg/bytedeco/javacpp/opencv_core$KeyPointVector;+0
j  ijopencv.ij.PointRoiKeyPointVectorConverter.convert(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;+68
v  ~StubRoutines::call_stub
J 4675  sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (0 bytes) @ 0x0000000003e789bf [0x0000000003e78940+0x7f]
J 4674 C1 sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (104 bytes) @ 0x0000000004522afc [0x0000000004521900+0x11fc]
J 6349 C2 java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object; (62 bytes) @ 0x000000000498d234 [0x000000000498d180+0xb4]
j  org.python.core.PyReflectedFunction.__call__(Lorg/python/core/PyObject;[Lorg/python/core/PyObject;[Ljava/lang/String;)Lorg/python/core/PyObject;+217
j  org.python.core.PyReflectedFunction.__call__([Lorg/python/core/PyObject;[Ljava/lang/String;)Lorg/python/core/PyObject;+43
j  org.python.core.PyObject.__call__(Lorg/python/core/PyObject;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+20
j  org.python.core.PyObject.__call__(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+5
j  org.python.core.PyMethod.__call__(Lorg/python/core/ThreadState;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+33
j  org.python.pycode._pyx0.f$0(Lorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;+241
j  org.python.pycode._pyx0.call_function(ILorg/python/core/PyFrame;Lorg/python/core/ThreadState;)Lorg/python/core/PyObject;+24
J 7757 C1 org.python.core.PyTableCode.call(Lorg/python/core/ThreadState;Lorg/python/core/PyFrame;Lorg/python/core/PyObject;)Lorg/python/core/PyObject; (373 bytes) @ 0x0000000004edcb7c [0x0000000004edc000+0xb7c]
j  org.python.core.PyCode.call(Lorg/python/core/ThreadState;Lorg/python/core/PyFrame;)Lorg/python/core/PyObject;+4
j  org.python.core.Py.runCode(Lorg/python/core/PyCode;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+154
j  org.python.core.__builtin__.eval(Lorg/python/core/PyObject;Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+53
j  org.python.core.__builtin__.eval(Lorg/python/core/PyObject;Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+3
j  org.python.util.PythonInterpreter.eval(Lorg/python/core/PyObject;)Lorg/python/core/PyObject;+9
j  org.python.jsr223.PyScriptEngine.eval(Lorg/python/core/PyCode;Ljavax/script/ScriptContext;)Ljava/lang/Object;+166
j  org.python.jsr223.PyScriptEngine.eval(Ljava/lang/String;Ljavax/script/ScriptContext;)Ljava/lang/Object;+8
j  javax.script.AbstractScriptEngine.eval(Ljava/lang/String;)Ljava/lang/Object;+6
j  org.scijava.script.ScriptModule.run()V+217
j  org.scijava.module.ModuleRunner.run()V+144
j  org.scijava.module.ModuleRunner.call()Lorg/scijava/module/Module;+1
j  org.scijava.module.ModuleRunner.call()Ljava/lang/Object;+1
j  org.scijava.thread.DefaultThreadService$3.call()Ljava/lang/Object;+28
j  java.util.concurrent.FutureTask.run()V+42
j  java.util.concurrent.ThreadPoolExecutor.runWorker(Ljava/util/concurrent/ThreadPoolExecutor$Worker;)V+95
j  java.util.concurrent.ThreadPoolExecutor$Worker.run()V+5
j  java.lang.Thread.run()V+11
v  ~StubRoutines::call_stub

#2

Just in case, as an alternative for the conversion from PointRoi to KeypointVector, this piece of code can be used :

from org.bytedeco.javacpp.opencv_core	import KeyPoint, KeyPointVector

def RoiToKp(MultiPointRoi): # -> return a KpVector
	'''
	Convert a multi point ROI to an openCV keypoint vector
	'''
	ListPt = MultiPointRoi.getContainedPoints()
	ListKp = [KeyPoint(point.x, point.y, 1) for point in ListPt]

	return KeyPointVector(ListKp)

#3

This was fixed by @joheras (thanks!) see the GitHub issue