import java.io.File;
import static com.googlecode.javacv.cpp.opencv_core.*;import static com.googlecode.javacv.cpp.opencv_features2d.*;import static com.googlecode.javacv.cpp.opencv_highgui.*;public final class Ex2FAST {public static void main(String[] args) {// Read input imagefinal File file = new File("church01.jpg");final CvMat image = cvLoadImageM("church01.jpg", 0);if (image == null) {System.out.println("Couldn't load source image: " + file.getAbsolutePath());System.exit(1);}final FastFeatureDetector ffd = new FastFeatureDetector(40, true);final CvArr imageA = new CvArr(image);final KeyPoint keyPoints = new KeyPoint();ffd.detect(imageA, keyPoints, new CvArr());System.out.println("keyPoints: " + keyPoints.capacity());}
}
# A fatal error has been detected by the Java Runtime Environment:## EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x66099fc9, pid=7892, tid=7912#…
"new CvArr()" should work, but please try to use "null" instead, and the
same for "imageA", please try to replace that with "image". Maybe there
is a bug related with this kind of weird usage... Let me know if it
changes anything, thanks
Samuel
On 2011-08-10 11:08, Jarek Sacha wrote:
> I am trying to run examples from OpenCV 2 book using javacv. Many of
> them work quite fine when accessing through �C� API. I got stuck on
> FastFeatureDetector, looks that it only has �C++� API. However it
> crashes JVM. I am trying code like this:
>
> import java.io.File;
>
> import static com.googlecode.javacv.cpp.opencv_core.*;
> import static com.googlecode.javacv.cpp.opencv_features2d.*;
> import static com.googlecode.javacv.cpp.opencv_highgui.*;
>
> public final class Ex2FAST {
> public static void main(String[] args) {
> // Read input image
> final File file = new File("church01.jpg");
> final CvMat image = cvLoadImageM("church01.jpg", 0);
> if (image == null) {
> System.out.println("Couldn't load source image: " +
> file.getAbsolutePath());
> System.exit(1);
> }
>
> final FastFeatureDetector ffd = new FastFeatureDetector(40,
> true);
> final CvArr imageA = new CvArr(image);
> final KeyPoint keyPoints = new KeyPoint();
> ffd.detect(imageA, keyPoints, new CvArr());
>
> System.out.println("keyPoints: " + keyPoints.capacity());
> }
>
> }
>
>
> It crashes on lineffd.detect(�) with message:
>
> # A fatal error has been detected by the Java Runtime Environment:
> #
> # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x66099fc9,
> pid=7892, tid=7912
> #
> �
final CvMat image = cvLoadImageM(file.getAbsolutePath(), 0);
final FastFeatureDetector ffd = new FastFeatureDetector(40, true);
final KeyPoint keyPoints = new KeyPoint();
ffd.detect(image, keyPoints, null)
JVM still crashes, part of the log:
Stack: [0x00230000,0x00280000], sp=0x0027f45c, free space=317k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code,
C=native code)
C [opencv_features2d230.dll+0x29fbd]
cv::OpponentColorDescriptorExtractor::OpponentColorDescriptorExtractor+0xa1d
C [opencv_features2d230.dll+0x45232] cv::Mat::MStep::operator unsigned
int+0x22e2
C [opencv_features2d230.dll+0x45413] cv::FAST+0x193
C [opencv_features2d230.dll+0x2eb4d]
cv::FastFeatureDetector::detectImpl+0x8d
C [opencv_features2d230.dll+0x30272] cv::FeatureDetector::detect+0x212
C [jniopencv_features2d3837367272959595118.dll+0x2ce61]
Java_com_googlecode_javacv_cpp_opencv_1features2d_00024FeatureDetector_detect__Lcom_googlecode_javacv_cpp_opencv_1core_00024CvArr_2Lcom_googlecode_javacv_cpp_opencv_1features2d_00024KeyPoint_2Lcom_googlecode_javacv_cpp_opencv_1core_00024CvArr_2+0x1c1
Do you have an example of using FeatureDetector interface?
Hum, it looks like MSVC 2010 isn't fully compatible with MSVC 2008.. It
seems to work fine with the prebuilt DLLs in the "vc9" directory of
OpenCV 2.3.0, so be sure to try those..
Otherwise, you could try to recompile everything with your favorite
compiler. That will work for sure.
Samuel
I assume that you are talking about recompiling javacv. How do I do that
on Windows 7 64-bit with VS2010?
I got javacpp and javacv project sources next to each other. Somehow I
need to let the javacv build know where OpenCV is, I am getting an error
when executing javacv build:
fatal error C1083: Cannot open include file: 'opencv2/core/core.hpp':
Thanks,
Jarek
Stack: [0x00380000,0x003d0000], sp=0x003cf2a8, free space=316k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code,
C=native code)
C [ntdll.dll+0x33280] RtlImageNtHeader+0x11c
C [ntdll.dll+0x33587] RtlImageNtHeader+0x423
C [ntdll.dll+0x33472] RtlImageNtHeader+0x30e
C [kernel32.dll+0x114dd] HeapFree+0x14
C [MSVCR90.dll+0x63c1b] free+0xcd
C [opencv_features2d230.dll+0x24c58]
cv::SurfDescriptorExtractor::computeImpl+0xd48
The precompiled binaries of both work fine for me, so unless I can reproduce it, I won't be able to fix it.
To recompile, just set all the paths on the command line as usual, and type “ant“ as usual...
Samuel
Stack: [0x00000000023c0000,0x00000000024c0000], sp=0x00000000024be820,
free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code,
C=native code)
C [ntdll.dll+0x53332] RtlFreeHeap+0x132
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j
com.googlecode.javacv.cpp.opencv_features2d$FeatureDetector.detect(Lcom/googlecode/javacv/cpp/opencv_core$CvArr;Lcom/googlecode/javacv/cpp/opencv_features2d$KeyPoint;Lcom/googlecode/javacv/cpp/opencv_core$CvArr;)V+0
j name.laganiere.opencv2book.chapter8.Ex2FAST.main([Ljava/lang/String;)V+80
v ~StubRoutines::call_stub
j
sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0
j
sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+87
j
sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+6
j
java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+57
j
com.intellij.rt.execution.application.AppMain.main([Ljava/lang/String;)V+140
v ~StubRoutines::call_stub
On 8/15/2011 8:19 PM, Samuel Audet wrote:
>
> The precompiled binaries of both work fine for me, so unless I can
> reproduce it, I won't be able to fix it.
>
> To recompile, just set all the paths on the command line as usual, and
> type �ant� as usual...
>
And this with both JavaCV and OpenCV recompiled with the same exact C++ compiler??
>> type �ant� as usual...
>>
Hum, never thought about that.. You may modify the compiler options, but
since JavaCPP generates very little code I doubt very much there is a
problem with either that or OpenCV for that matter (have you tried
calling what you need from a program in C++ BTW?). It works just fine in
both Linux and Windows here. You probably just have incompatible
libraries lying around or OpenCV was compiled with MSVC 10.00001 or
something, where Microsoft decided to break compatibility with the exact
thing you need here.. So, this is why I am suggesting to recompile
everything with the same exact compiler, same exact cl.EXE file, with
the same exact libraries, DLLs, etc. in the path and same exact
everything: This is C++ we are talking about here, it's not Java. There
exists no "standard C++" whatever they may say
Samuel
I did rebuild OpenCV and JavaCV with the same compiler, still the same
crashes. I have tested C++ using VS2010 and the same OpenCV binaries, no
problems. Note that I can ran parts of JavaCV. For instance, I can run
function track1() below but not track2() - the JVM crashes on
gftt.detect(...). Note that native part of crash stack is very short
(details at the end), only
C [ntdll.dll+0x53332] RtlFreeHeap+0x132
As is JNI part was making wrong calls. Something with convertingKeyPoint
to std::vector<cv::KeyPoint>?Windows 7 issue?
My idea was to "translate" examples from the OpenCV2 book to JVM and
make them available as part of a JavaCV tutorial. I have many things
working, for instance, complete Chapter 4 on morphological operations
and parts of others that I tried. I got stuck on Chapter 8 "Detecting
and Matching Interest Points", with JVM crashes. I really want to make
it work, though not sure what to do next to resolve it.
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_features2d.*;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static
com.googlecode.javacv.cpp.opencv_imgproc.cvGoodFeaturesToTrack;
public final class Ch08_ex01_GoodFeaturesToTrack {
private static void track1(final IplImage image) {
final IplImage eigImage = cvCreateImage(cvGetSize(image),
IPL_DEPTH_32F, 1);
final IplImage tempImage = cvCreateImage(cvGetSize(image),
IPL_DEPTH_32F, 1);
final int maxCorners = 500;
final CvPoint2D32f corners = new CvPoint2D32f(maxCorners);
final int[] cornerCount = new int[]{maxCorners};
cvGoodFeaturesToTrack(image, eigImage, tempImage, corners,
cornerCount, 0.01, 10, null, 3, 1, 0.04);
System.out.println("cornerCount: " + cornerCount[0]);
}
private static void track2(final IplImage image) {
final GoodFeaturesToTrackDetector gftt = new
GoodFeaturesToTrackDetector(500, 0.01, 10.0, 3, false, 0.04);
final KeyPoint keyPoints = new KeyPoint();
gftt.detect(image, keyPoints, null);
System.out.println("keyPoints: " + keyPoints.capacity());
}
public static void main(String[] args) {
final IplImage image = cvLoadImage("church01.jpg", 0);
// track1(image);
track2(image);
}
}
Stack: [0x00000000025e0000,0x00000000026e0000], sp=0x00000000026de890,
free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code,
C=native code)
C [ntdll.dll+0x53332] RtlFreeHeap+0x132
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j
com.googlecode.javacv.cpp.opencv_features2d$FeatureDetector.detect(Lcom/googlecode/javacv/cpp/opencv_core$CvArr;Lcom/googlecode/javacv/cpp/opencv_features2d$KeyPoint;Lcom/googlecode/javacv/cpp/opencv_core$CvArr;)V+0
j
name.laganiere.opencv2book.chapter8.Ch08_ex01_GoodFeaturesToTrack.track2(Lcom/googlecode/javacv/cpp/opencv_core$IplImage;)V+34
j
name.laganiere.opencv2book.chapter8.Ch08_ex01_GoodFeaturesToTrack.main([Ljava/lang/String;)V+12
I will be releasing a new version soon for OpenCV 2.3.1 and I am
compiling it with MSVC 10 this time. Your code still works just fine
here with the precompiled binaries, so just wait for it I guess...
> problems. Note that I can ran parts of JavaCV. For instance, I can run
> function track1() below but not track2() - the JVM crashes on
Right, your track1() uses C functions, while the track2() uses C++. Two
different standards entirely. The C standard is good, the C++, not so
much... That's why most people use Java :)
> My idea was to "translate" examples from the OpenCV2 book to JVM and
> make them available as part of a JavaCV tutorial. I have many things
that would be great! Keep up informed of your progress
Samuel
I released it a few hours ago. Let me know if you hit any problems with
that version, thanks!
Samuel
By the way. I have created a project
http://code.google.com/p/javacv-examples/ and stated uploading examples
that I verified to work. So far uploaded a couple of Scala examples for
chapter 5 of the OpenCV2 Cookbook (morphological filters). I will make
an official announcement once I write a description how to setup an IDE
to easily run them.
Strange.. let me know if you figure out something
> different stack trace. Tested 2.3.0 on Ubuntu 32 and worked fine. What
> OS are you using?
Windows XP x64
> By the way. I have created a project
> http://code.google.com/p/javacv-examples/ and stated uploading examples
> that I verified to work. So far uploaded a couple of Scala examples for
> chapter 5 of the OpenCV2 Cookbook (morphological filters). I will make
> an official announcement once I write a description how to setup an IDE
> to easily run them.
Great! But wouldn't it make more sense to add the material directly to
JavaCV's project page?
Samuel
I have just tested it on my crappy 32-bit Vista, and behold, it fails!
The trace always differs yes. Seems like it's trying to dereference
uninitialized memory for some reason. In any case, it looks like a
common problem with no solution:
http://stackoverflow.com/questions/1144034/how-to-diagnose-java-jni-exception-access-violation-errors-in-windows-vista
As one of the answers suggest, we should try to compile OpenCV and
JavaCV using the same compiler as the JRE, i.e.: MS VC++ 7.1 ...
Hum ... good luck with that :) Let me know if you find a solution
> Glad to move it into a module within a JavaCV projects. I would keep
> OpenCV2 Cookbook examples separate from other code as it is intended to
> be a companion to the book. Renamed current OpenCV_Cookbook module to
> OpenCV2_Cookbook_Examples, or opencv2_cookbook_examples (suggestions?).
> I will need commit access to JavaCV source and wiki.
Sure that sounds great! I added you as a contributor. Let me know before
making any "big" changes... thanks
Samuel
This suggests that the compiler options used by JavaCPP on Windows needs
to be adjusted to defaults used by Visual Studio 2010 DLL project.
So it works with the Debug build options, but not the Release ones?
thanks for looking into this!
Samuel
Hum, thanks for testing. I do not have Visual Studio 2010 myself, just
using the Windows SDK, so I do not know what options it may be using..
Knowing Microsoft, they probably try to hide it, but if you figure it
out, let me know, thanks
> All 7 examples work fine except Ex4WatershedSegmentation
> http://code.google.com/p/javacv-examples/source/browse/trunk/OpenCV2_Cookbook/src/main/scala/opencv2_cookbook/chapter05/Ex4WatershedSegmentation.scala
>
> There is some suspicious thing with cvConvertScale or cvCreateImage
> after line 48, images are corrupted and corruption patters changes from
> run to run. If i remember the same problem was on Linux too. May need to
> write some stress test to see if the corruption shows up after repeated
> calls to cvConvertScale or cvCreateImage or it may be in
> WatershedSegmenter.process()
It's probably in C++ functions, I'm pretty sure all C functions work
just fine.
Thank you very much for all the work on this!!
Samuel