We tried to convert the c++ Code from Detection of coins (and fit ellipses) on an image into Java. After solving the first problem in the thread Problems with OpenCV ellipse detection in Java, starting the program with the parameters
2 PathToThePicture
leads to following fatal error
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000005addc330, pid=1700, tid=1472
#
# JRE version: Java(TM) SE Runtime Environment (7.0_45-b18) (build 1.7.0_45-b18)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.45-b08 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [msvcr100.dll+0x3c330]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# PathToTheProject\hs_err_pid1700.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Error report:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x670d26df, pid=2832, tid=5672
#
# JRE version: Java(TM) SE Runtime Environment (7.0_51-b13) (build 1.7.0_51-b13)
# Java VM: Java HotSpot(TM) Client VM (24.51-b03 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [msvcr100.dll+0x26df]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
--------------- T H R E A D ---------------
Current thread (0x004eb800): JavaThread "main" [_thread_in_native, id=5672, stack(0x00570000,0x005c0000)]
siginfo: ExceptionCode=0xc0000005, writing address 0x00000000
Registers:
EAX=0x00000000, EBX=0x005bfb7c, ECX=0x00000016, EDX=0x00000000
ESP=0x005bfaf4, EBP=0x005bfb18, ESI=0x004eb930, EDI=0x00000000
EIP=0x670d26df, EFLAGS=0x00010202
Top of Stack: (sp=0x005bfaf4)
0x005bfaf4: 00000000 670c1eb2 00000000 00000000
0x005bfb04: 00000058 004eb800 34a45f90 34a45f90
0x005bfb14: 004eb930 005bfb60 0226a9dd 004eb930
0x005bfb24: 005bfb68 005bfb7c 00000000 00000058
0x005bfb34: 00000000 004ec15c 004ec15c 005bfb40
0x005bfb44: 34a45f90 005bfb7c 34aaf550 00000000
0x005bfb54: 34a45f90 00000000 005bfb70 005bfba0
0x005bfb64: 0226339a 24ef55f8 022688e6 00000058
Instructions: (pc=0x670d26df)
0x670d26bf: 83 c7 01 83 e9 01 75 f6 8b c8 c1 e0 08 03 c1 8b
0x670d26cf: c8 c1 e0 10 03 c1 8b ca 83 e2 03 c1 e9 02 74 06
0x670d26df: f3 ab 85 d2 74 0a 88 07 83 c7 01 83 ea 01 75 f6
0x670d26ef: 8b 44 24 08 5f c3 8b 44 24 04 c3 90 90 90 90 90
Register to memory mapping:
EAX=0x00000000 is an unknown value
EBX=0x005bfb7c is pointing into the stack for thread: 0x004eb800
ECX=0x00000016 is an unknown value
EDX=0x00000000 is an unknown value
ESP=0x005bfaf4 is pointing into the stack for thread: 0x004eb800
EBP=0x005bfb18 is pointing into the stack for thread: 0x004eb800
ESI=0x004eb930 is an unknown value
EDI=0x00000000 is an unknown value
Stack: [0x00570000,0x005c0000], sp=0x005bfaf4, free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [msvcr100.dll+0x26df]
j com.googlecode.javacpp.Pointer.memset(Lcom/googlecode/javacpp/Pointer;IJ)Lcom/googlecode/javacpp/Pointer;+0
j com.googlecode.javacpp.Pointer.fill(I)Lcom/googlecode/javacpp/Pointer;+107
j com.googlecode.javacpp.Pointer.zero()Lcom/googlecode/javacpp/Pointer;+2
j com.googlecode.javacv.cpp.opencv_core$CvSeq.<init>()V+9
j com.googlecode.javacv.cpp.opencv_core$CvContour.<init>()V+1
j Dieter.main([Ljava/lang/String;)V+67
v ~StubRoutines::call_stub
V [jvm.dll+0x13f35a]
V [jvm.dll+0x202c6e]
V [jvm.dll+0x13f3dd]
V [jvm.dll+0xc9945]
V [jvm.dll+0xd45e7]
C [javaw.exe+0x2070]
C [javaw.exe+0xa5b1]
C [javaw.exe+0xa63b]
C [KERNEL32.DLL+0x1495d]
C [ntdll.dll+0x498ee]
C [ntdll.dll+0x498c4]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.googlecode.javacpp.Pointer.memset(Lcom/googlecode/javacpp/Pointer;IJ)Lcom/googlecode/javacpp/Pointer;+0
j com.googlecode.javacpp.Pointer.fill(I)Lcom/googlecode/javacpp/Pointer;+107
j com.googlecode.javacpp.Pointer.zero()Lcom/googlecode/javacpp/Pointer;+2
j com.googlecode.javacv.cpp.opencv_core$CvSeq.<init>()V+9
j com.googlecode.javacv.cpp.opencv_core$CvContour.<init>()V+1
j Dieter.main([Ljava/lang/String;)V+67
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x00826800 JavaThread "Service Thread" daemon [_thread_blocked, id=7436, stack(0x044e0000,0x04530000)]
0x00820c00 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=6644, stack(0x04450000,0x044a0000)]
0x0081fc00 JavaThread "Attach Listener" daemon [_thread_blocked, id=1156, stack(0x043c0000,0x04410000)]
0x0081c800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=1820, stack(0x04330000,0x04380000)]
0x007b0400 JavaThread "Finalizer" daemon [_thread_blocked, id=5456, stack(0x042a0000,0x042f0000)]
0x007ae800 JavaThread "Reference Handler" daemon [_thread_blocked, id=2588, stack(0x00de0000,0x00e30000)]
=>0x004eb800 JavaThread "main" [_thread_in_native, id=5672, stack(0x00570000,0x005c0000)]
Other Threads:
0x007ad400 VMThread [stack: 0x00d50000,0x00da0000] [id=3176]
0x0083e000 WatcherThread [stack: 0x04570000,0x045c0000] [id=4452]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 4928K, used 1323K [0x24a20000, 0x24f70000, 0x29f70000)
eden space 4416K, 18% used [0x24a20000, 0x24aeafe8, 0x24e70000)
from space 512K, 100% used [0x24ef0000, 0x24f70000, 0x24f70000)
to space 512K, 0% used [0x24e70000, 0x24e70000, 0x24ef0000)
tenured generation total 10944K, used 370K [0x29f70000, 0x2aa20000, 0x34a20000)
the space 10944K, 3% used [0x29f70000, 0x29fccb38, 0x29fccc00, 0x2aa20000)
compacting perm gen total 12288K, used 912K [0x34a20000, 0x35620000, 0x38a20000)
the space 12288K, 7% used [0x34a20000, 0x34b04270, 0x34b04400, 0x35620000)
ro space 10240K, 41% used [0x38a20000, 0x38e52050, 0x38e52200, 0x39420000)
rw space 12288K, 52% used [0x39420000, 0x39a66800, 0x39a66800, 0x3a020000)
Card table byte_map: [0x00c40000,0x00cf0000] byte_map_base: 0x00b1af00
Polling page: 0x004c0000
Code Cache [0x02260000, 0x02320000, 0x04260000)
total_blobs=266 nmethods=113 adapters=90 free_code_cache=32016Kb largest_free_block=32785344
Compilation events (10 events):
Event: 0.214 Thread 0x00820c00 108 java.util.AbstractList$Itr::hasNext (20 bytes)
Event: 0.214 Thread 0x00820c00 nmethod 108 0x02319d48 code [0x02319e50, 0x02319f0c]
Event: 0.215 Thread 0x00820c00 110 com.googlecode.javacpp.Loader$ClassProperties::addAll (183 bytes)
Event: 0.216 Thread 0x00820c00 nmethod 110 0x0231a248 code [0x0231a490, 0x0231ac68]
Event: 0.216 Thread 0x00820c00 111 java.lang.String::indexOf (25 bytes)
Event: 0.216 Thread 0x00820c00 nmethod 111 0x0231b488 code [0x0231b590, 0x0231b65c]
Event: 0.217 Thread 0x00820c00 112 java.lang.Character::toLowerCase (6 bytes)
Event: 0.217 Thread 0x00820c00 nmethod 112 0x0231b748 code [0x0231b850, 0x0231b8f8]
Event: 0.218 Thread 0x00820c00 113 java.util.Hashtable$Enumerator::hasMoreElements (53 bytes)
Event: 0.218 Thread 0x00820c00 nmethod 113 0x0231b988 code [0x0231ba80, 0x0231bb60]
GC Heap History (2 events):
Event: 0.204 GC heap before
{Heap before GC invocations=0 (full 0):
def new generation total 4928K, used 4416K [0x24a20000, 0x24f70000, 0x29f70000)
eden space 4416K, 100% used [0x24a20000, 0x24e70000, 0x24e70000)
from space 512K, 0% used [0x24e70000, 0x24e70000, 0x24ef0000)
to space 512K, 0% used [0x24ef0000, 0x24ef0000, 0x24f70000)
tenured generation total 10944K, used 0K [0x29f70000, 0x2aa20000, 0x34a20000)
the space 10944K, 0% used [0x29f70000, 0x29f70000, 0x29f70200, 0x2aa20000)
compacting perm gen total 12288K, used 887K [0x34a20000, 0x35620000, 0x38a20000)
the space 12288K, 7% used [0x34a20000, 0x34afdfc8, 0x34afe000, 0x35620000)
ro space 10240K, 41% used [0x38a20000, 0x38e52050, 0x38e52200, 0x39420000)
rw space 12288K, 52% used [0x39420000, 0x39a66800, 0x39a66800, 0x3a020000)
Event: 0.206 GC heap after
Heap after GC invocations=1 (full 0):
def new generation total 4928K, used 512K [0x24a20000, 0x24f70000, 0x29f70000)
eden space 4416K, 0% used [0x24a20000, 0x24a20000, 0x24e70000)
from space 512K, 100% used [0x24ef0000, 0x24f70000, 0x24f70000)
to space 512K, 0% used [0x24e70000, 0x24e70000, 0x24ef0000)
tenured generation total 10944K, used 370K [0x29f70000, 0x2aa20000, 0x34a20000)
the space 10944K, 3% used [0x29f70000, 0x29fccb38, 0x29fccc00, 0x2aa20000)
compacting perm gen total 12288K, used 887K [0x34a20000, 0x35620000, 0x38a20000)
the space 12288K, 7% used [0x34a20000, 0x34afdfc8, 0x34afe000, 0x35620000)
ro space 10240K, 41% used [0x38a20000, 0x38e52050, 0x38e52200, 0x39420000)
rw space 12288K, 52% used [0x39420000, 0x39a66800, 0x39a66800, 0x3a020000)
}
Deoptimization events (0 events):
No events
Internal exceptions (10 events):
Event: 0.177 Thread 0x004eb800 Threw 0x24e2f6d8 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.177 Thread 0x004eb800 Threw 0x24e33ec8 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.203 Thread 0x004eb800 Threw 0x24e569d8 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.206 Thread 0x004eb800 Threw 0x24a27c80 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.207 Thread 0x004eb800 Threw 0x24a2ad28 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.207 Thread 0x004eb800 Threw 0x24a2dc90 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.207 Thread 0x004eb800 Threw 0x24a314d0 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.208 Thread 0x004eb800 Threw 0x24a5f148 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.216 Thread 0x004eb800 Threw 0x24acf300 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Event: 0.217 Thread 0x004eb800 Threw 0x24ad3248 at C:\re\jdk7u51\527\hotspot\src\share\vm\prims\jvm.cpp:1244
Events (10 events):
Event: 0.207 loading class 0x0462fa78
Event: 0.207 loading class 0x0462fa78 done
Event: 0.208 loading class 0x0462fe38
Event: 0.208 loading class 0x0462fe38 done
Event: 0.216 loading class 0x0083ef48
Event: 0.216 loading class 0x0083ef48 done
Event: 0.217 loading class 0x0083f338
Event: 0.217 loading class 0x0083f338 done
Event: 0.218 loading class 0x3a040448
Event: 0.218 loading class 0x3a040448 done
Dynamic libraries:
0x00e30000 - 0x00e5f000 C:\Program Files (x86)\Java\jre7\bin\javaw.exe
0x76ed0000 - 0x77038000 C:\Windows\SYSTEM32\ntdll.dll
0x74b20000 - 0x74c60000 C:\Windows\SYSTEM32\KERNEL32.DLL
0x751e0000 - 0x752af000 C:\Windows\SYSTEM32\KERNELBASE.dll
0x69530000 - 0x695ca000 C:\Windows\system32\apphelp.dll
0x64c10000 - 0x64e62000 C:\Windows\AppPatch\AcGenral.DLL
0x74f90000 - 0x7504e000 C:\Windows\SYSTEM32\msvcrt.dll
0x74ae0000 - 0x74b1e000 C:\Windows\SYSTEM32\sechost.dll
0x74900000 - 0x7491d000 C:\Windows\SYSTEM32\SspiCli.dll
0x76bd0000 - 0x76c11000 C:\Windows\SYSTEM32\SHLWAPI.dll
0x73df0000 - 0x73ecc000 C:\Windows\SYSTEM32\UxTheme.dll
0x74ca0000 - 0x74def000 C:\Windows\SYSTEM32\USER32.dll
0x76a10000 - 0x76b18000 C:\Windows\SYSTEM32\GDI32.dll
0x73a30000 - 0x73a50000 C:\Windows\SYSTEM32\WINMM.dll
0x73c70000 - 0x73c82000 C:\Windows\SYSTEM32\samcli.dll
0x76c70000 - 0x76d7b000 C:\Windows\SYSTEM32\ole32.dll
0x74a40000 - 0x74ac7000 C:\Windows\SYSTEM32\OLEAUT32.dll
0x731a0000 - 0x731b5000 C:\Windows\SYSTEM32\MSACM32.dll
0x74880000 - 0x74888000 C:\Windows\SYSTEM32\VERSION.dll
0x75860000 - 0x76a03000 C:\Windows\SYSTEM32\SHELL32.dll
0x739c0000 - 0x739d9000 C:\Windows\SYSTEM32\USERENV.dll
0x739f0000 - 0x73a09000 C:\Windows\SYSTEM32\dwmapi.dll
0x73210000 - 0x73334000 C:\Windows\SYSTEM32\urlmon.dll
0x75060000 - 0x750d7000 C:\Windows\SYSTEM32\ADVAPI32.dll
0x74820000 - 0x7487e000 C:\Windows\SYSTEM32\WINSPOOL.DRV
0x67500000 - 0x67514000 C:\Windows\SYSTEM32\MPR.dll
0x752b0000 - 0x75361000 C:\Windows\SYSTEM32\RPCRT4.dll
0x748f0000 - 0x748f9000 C:\Windows\SYSTEM32\CRYPTBASE.dll
0x75380000 - 0x754ce000 C:\Windows\SYSTEM32\combase.dll
0x73a10000 - 0x73a30000 C:\Windows\SYSTEM32\WINMMBASE.dll
0x74050000 - 0x7405e000 C:\Windows\SYSTEM32\profapi.dll
0x72e30000 - 0x73047000 C:\Windows\SYSTEM32\iertutil.dll
0x72c60000 - 0x72e24000 C:\Windows\SYSTEM32\WININET.dll
0x74890000 - 0x748e1000 C:\Windows\SYSTEM32\bcryptPrimitives.dll
0x74f40000 - 0x74f7a000 C:\Windows\SYSTEM32\cfgmgr32.dll
0x74800000 - 0x7481f000 C:\Windows\SYSTEM32\DEVOBJ.dll
0x74060000 - 0x740d7000 C:\Windows\SYSTEM32\SHCORE.DLL
0x74920000 - 0x74945000 C:\Windows\system32\IMM32.DLL
0x750e0000 - 0x751d7000 C:\Windows\SYSTEM32\MSCTF.dll
0x74450000 - 0x74635000 C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.16384_none_a9f4965301334e09\COMCTL32.dll
0x670d0000 - 0x6718f000 C:\Program Files (x86)\Java\jre7\bin\msvcr100.dll
0x64f80000 - 0x65300000 C:\Program Files (x86)\Java\jre7\bin\client\jvm.dll
0x74040000 - 0x74048000 C:\Windows\SYSTEM32\WSOCK32.dll
0x749a0000 - 0x749a6000 C:\Windows\SYSTEM32\PSAPI.DLL
0x76c20000 - 0x76c6d000 C:\Windows\SYSTEM32\WS2_32.dll
0x74f80000 - 0x74f87000 C:\Windows\SYSTEM32\NSI.dll
0x66ba0000 - 0x66bac000 C:\Program Files (x86)\Java\jre7\bin\verify.dll
0x66b80000 - 0x66ba0000 C:\Program Files (x86)\Java\jre7\bin\java.dll
0x66b60000 - 0x66b73000 C:\Program Files (x86)\Java\jre7\bin\zip.dll
0x66910000 - 0x66979000 C:\Windows\System32\msvcp100.dll
0x70fc0000 - 0x71ef6000 C:\opencv\build\x86\vc10\bin\opencv_ffmpeg248.dll
0x64a00000 - 0x64c06000 C:\opencv\build\x86\vc10\bin\opencv_core248.dll
0x64790000 - 0x649fb000 C:\opencv\build\x86\vc10\bin\opencv_imgproc248.dll
0x64580000 - 0x64787000 C:\opencv\build\x86\vc10\bin\opencv_highgui248.dll
0x66d80000 - 0x66d99000 C:\Windows\SYSTEM32\AVIFIL32.dll
0x67490000 - 0x674b2000 C:\Windows\SYSTEM32\MSVFW32.dll
0x66d60000 - 0x66d74000 C:\Windows\SYSTEM32\AVICAP32.dll
0x670c0000 - 0x670cf000 F:\tmp\javacpp367334687899361\jniopencv_highgui.dll
0x66810000 - 0x66885000 F:\tmp\javacpp367334687899361\jniopencv_core.dll
0x72260000 - 0x723a8000 C:\Windows\SYSTEM32\dbghelp.dll
VM Arguments:
jvm_args: -Dfile.encoding=Cp1252
java_command: DetectEllipse 2 PathToPicture
Launcher Type: SUN_STANDARD
Environment Variables:
PATH=C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\IVI Foundation\VISA\WinNT\Bin;F:\Programmieren\tools\eclipse 32bit;
USERNAME=Username
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 60 Stepping 3, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows 8 , 64 bit Build 9200
CPU:total 4 (4 cores per cpu, 1 threads per core) family 6 model 60 stepping 3, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, erms, tsc, tscinvbit
Memory: 4k page, physical 8325332k(5583064k free), swap 13445332k(10026960k free)
vm_info: Java HotSpot(TM) Client VM (24.51-b03) for windows-x86 JRE (1.7.0_51-b13), built on Dec 18 2013 19:09:58 by "java_re" with unknown MS VC++:1600
time: Sun Feb 23 01:12:58 2014
elapsed time: 0 seconds
Here is the converted Java-Code:
import static com.googlecode.javacv.cpp.opencv_core.CV_FILLED;
import static com.googlecode.javacv.cpp.opencv_core.CV_RGB;
import static com.googlecode.javacv.cpp.opencv_core.CV_WHOLE_SEQ;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateImage;
import static com.googlecode.javacv.cpp.opencv_core.cvCreateMemStorage;
import static com.googlecode.javacv.cpp.opencv_core.cvDrawContours;
import static com.googlecode.javacv.cpp.opencv_core.cvGetSize;
import static com.googlecode.javacv.cpp.opencv_core.cvPoint;
import static com.googlecode.javacv.cpp.opencv_core.cvScalar;
import static com.googlecode.javacv.cpp.opencv_core.cvXorS;
import static com.googlecode.javacv.cpp.opencv_core.cvZero;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import static com.googlecode.javacv.cpp.opencv_highgui.cvSaveImage;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_CHAIN_APPROX_SIMPLE;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_RETR_CCOMP;
import static com.googlecode.javacv.cpp.opencv_imgproc.CV_THRESH_BINARY;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvContourArea;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvDilate;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvFindContours;
import static com.googlecode.javacv.cpp.opencv_imgproc.cvThreshold;
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.cpp.opencv_core.CvContour;
import com.googlecode.javacv.cpp.opencv_core.CvMemStorage;
import com.googlecode.javacv.cpp.opencv_core.CvRect;
import com.googlecode.javacv.cpp.opencv_core.CvScalar;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class DetectEllipse{
public static final double M_PI = 3.14159265358979323846;
public static final double MIN_AREA = 100.00;
public static final double MAX_TOL = 100.00;
private static int[] array = { 0 };
//
// We need this to be high enough to get rid of things that are too small
// too
// have a definite shape. Otherwise, they will end up as ellipse false
// positives.
//
//
// One way to tell if an object is an ellipse is to look at the relationship
// of its area to its dimensions. If its actual occupied area can be
// estimated
// using the well-known area formula Area = PI*A*B, then it has a good
// chance of
// being an ellipse.
//
// This value is the maximum permissible error between actual and estimated
// area.
//
public static void main(String[] args) {
IplImage src = cvLoadImage(args[1], 0);
if (src == null) {
System.out.println("!!! Unable to load image: " + args[1]);
return;
}
// the first command line parameter must be file name of binary
// (black-n-white) image
if (Integer.parseInt(args[0]) == 2) {
IplImage dst = cvCreateImage(cvGetSize(src), 8, 3);
CvMemStorage storage = cvCreateMemStorage(0);
CvSeq contour = new CvContour();
// maybe: = new CvSeq(0)
cvThreshold(src, src, 1, 255, CV_THRESH_BINARY);
//
// Invert the image such that white is foreground, black is
// background.
// Dilate to get rid of noise.
//
cvXorS(src, cvScalar(255, 0, 0, 0), src, null);
cvDilate(src, src, null, 2);
cvFindContours(src, storage, contour,
Loader.sizeof(CvContour.class), CV_RETR_CCOMP,
CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
cvZero(dst);
for (; contour.flags() != 0; contour = contour.h_next()) {
// if not working: use contour.isNull()
double actual_area = Math.abs(cvContourArea(contour,
CV_WHOLE_SEQ, 0));
if (actual_area < MIN_AREA)
continue;
//
// FIXME:
// Assuming the axes of the ellipse are vertical/perpendicular.
//
CvRect rect = ((CvContour) contour).rect();
int A = rect.width() / 2;
int B = rect.height() / 2;
double estimated_area = Math.PI * A * B;
double error = Math.abs(actual_area - estimated_area);
if (error > MAX_TOL)
continue;
System.out.printf("center x: %d y: %d A: %d B: %d\n", rect.x()
+ A, rect.y() + B, A, B);
CvScalar color = CV_RGB(
tangible.RandomNumbers.nextNumber() % 255,
tangible.RandomNumbers.nextNumber() % 255,
tangible.RandomNumbers.nextNumber() % 255);
cvDrawContours(dst, contour, color, color, -1, CV_FILLED, 8,
cvPoint(0, 0));
}
cvSaveImage("coins.png", dst, array);
}
}
}
cvThreshold()
expects a single channel image, and you are telling it to store the result in a 3-channel image, hence the crash!
You can call cvCreateImage()
to create a single channel IplImage
.
Good luck!
User contributions licensed under CC BY-SA 3.0