Getting MacBook Pro built in iSight camera to work with OpenCV in MRL

Anyone had any success?

 

I started MRL, started an OpenCV service, when I clicked the capture button in the input section of the GUI I get the following error on the command line.

createServices service count 2
Exception in thread "OpenCV_videoProcessor" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:448)
    at com.googlecode.javacpp.Loader.load(Loader.java:372)
    at com.googlecode.javacpp.Loader.load(Loader.java:319)
    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.googlecode.javacpp.Loader.load(Loader.java:338)
    at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:97)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.googlecode.javacpp.Loader.load(Loader.java:338)
    at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:85)
    at com.googlecode.javacv.OpenCVFrameGrabber.start(OpenCVFrameGrabber.java:174)
    at org.myrobotlab.opencv.VideoProcessor.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:724)
 

Here's a listing of my native libraries folder.

 

$ ls libraries/native/x86.64.mac/
cv2.so                libopencv_features2d.2.4.dylib    libopencv_highgui.2.4.dylib    libopencv_nonfree.2.4.dylib    libopencv_ts.2.4.dylib
libopencv_calib3d.2.4.dylib    libopencv_flann.2.4.dylib    libopencv_imgproc.2.4.dylib    libopencv_objdetect.2.4.dylib    libopencv_video.2.4.dylib
libopencv_contrib.2.4.dylib    libopencv_gpu.2.4.dylib        libopencv_legacy.2.4.dylib    libopencv_photo.2.4.dylib    libopencv_videostab.2.4.dylib
libopencv_core.2.4.dylib    libopencv_haartraining_engine.a    libopencv_ml.2.4.dylib        libopencv_stitching.2.4.dylib    librxtxSerial64.jnilib
 

Sending a No-Worky.

 

GroG's picture

What you see is the most

What you see is the most delicate bridge ....

Java -> JavaCV -> JNI -> OpenCV native code  -> OS/Camera Driver

I usually try to start at the bottom, and test just the OpenCV code - On the other platforms I''ve got LKDemo applications which comes with OpenCV when you build it - it will take a camera feed.  It's a good one to test the

OpenCV native code  -> OS/Camera Driver 

part.  Regrettably, I do not have this executable for x86.64.mac :(  

Have you build OpenCV on your mac before ?  Would this be a possibility?

kmcgerald's picture

I'll see what I can do

I built OpenCV on an old G5 Power Mac running 10.4 a few years ago but haven't done any real development on this MacBook though.  I'll poke around and see if I can get something OpenCV related working.  Maybe I'll luck out and find something precompiled.

GroG's picture

The minor version is

The minor version is important too.. 

at the moment it's OpenCV 2.4.3

kmcgerald's picture

Poking at this again

ok so on my 64bit 10.7.5 machine I've downloaded the opencv-2.4.3 tarball, installed Xcode, installed the Command Line Tools from within Xcode, installed cmake, unpacked the tarball, made a build directory, cmake'd, make'd, make installed.  Now what?

GroG's picture

Steps # 1 What I like to do

Steps # 1

What I like to do is check the build works without any other complexities. This requires that "build examples" = true in the CMake config file.  

When the examples are build there should be a lkdemo program somewhere - this tests Lucas Kanade tracking points and by default will try to capture the first camera available, unless specified differently on the command line. 

If you dont have examples set to true (its false by default) you have to re-set it and build / install again 

The lkdemo should look something like this :

 

Or, you could by-pass evrything and just dump all the new .dylibs into <mrl install point>/libraries/native/x86.64.mac - fire up MRL and see if you can get a capture going...

:)

kmcgerald's picture

Gah! No Camera

sucks not having a camera for this box.  I nuked the OpenCV directory, untarred, changed config for examples and rebuilt/installed.  Now I have a ton of examples but no camera to test with.

I'll try copying the dylibs in and see if I can use the IPCamera source.

 

Links that helped me get this far... (for posterity and myself since I'll have to do this again on my other system)

2. Build from source using the CMake build system (new)

http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port 

After installing Xcode 4.3, the Command Line Tools must be installed. This is done from the Downloads section of Xcode's preferences.

http://guide.macports.org/chunked/installing.xcode.html

kmcgerald's picture

No-worky with IPCamera

copied /usr/local/lib/libopencv*2.4.dylib and ~/OpenCV-2.4.3/build/lib/cv2.so into the native/x86.64.mac directory.

$ file libraries/native/x86.64.mac/*
libraries/native/x86.64.mac/cv2.so:                         Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_calib3d.2.4.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_contrib.2.4.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_core.2.4.dylib:       Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_features2d.2.4.dylib: Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_flann.2.4.dylib:      Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_gpu.2.4.dylib:        Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_highgui.2.4.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_imgproc.2.4.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_legacy.2.4.dylib:     Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_ml.2.4.dylib:         Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_nonfree.2.4.dylib:    Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_objdetect.2.4.dylib:  Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_photo.2.4.dylib:      Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_stitching.2.4.dylib:  Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_ts.2.4.dylib:         Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_video.2.4.dylib:      Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/libopencv_videostab.2.4.dylib:  Mach-O 64-bit dynamically linked shared library x86_64
libraries/native/x86.64.mac/librxtxSerial64.jnilib:         Mach-O universal binary with 3 architectures
libraries/native/x86.64.mac/librxtxSerial64.jnilib (for architecture i386):    Mach-O bundle i386
libraries/native/x86.64.mac/librxtxSerial64.jnilib (for architecture x86_64):    Mach-O 64-bit bundle x86_64
libraries/native/x86.64.mac/librxtxSerial64.jnilib (for architecture ppc7400):    Mach-O bundle ppc

$ ./myrobotlab.sh
createServices service count 2
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextGetCTM: invalid context 0x0
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextSetBaseCTM: invalid context 0x0
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextGetCTM: invalid context 0x0
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextSetBaseCTM: invalid context 0x0
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextGetCTM: invalid context 0x0
Jul 16 15:37:35 sourapple java[59404] <Error>: CGContextSetBaseCTM: invalid context 0x0
Exception in thread "ocv_videoProcessor" java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
    at java.lang.Runtime.loadLibrary0(Runtime.java:849)
    at java.lang.System.loadLibrary(System.java:1087)
    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:448)
    at com.googlecode.javacpp.Loader.load(Loader.java:372)
    at com.googlecode.javacpp.Loader.load(Loader.java:319)
    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:136)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:270)
    at com.googlecode.javacpp.Loader.load(Loader.java:338)
    at com.googlecode.javacpp.Loader.load(Loader.java:319)
    at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(opencv_core.java:163)
    at org.myrobotlab.opencv.IPCameraFrameGrabber.grab(Unknown Source)
    at org.myrobotlab.opencv.VideoProcessor.run(Unknown Source)
    at java.lang.Thread.run(Thread.java:724)
 

 

Looking at that error output again it occurs to me ... when I build OpenCV do I have to tell it to specifically build for JNI support?

GroG's picture

  I think lkemo will take a

 

I think lkemo will take a command line argument of a file name .e.g lkdemo sample.avi

kmcgerald's picture

lkdemo works

I pointed lkdemo at a video file and it worked. I clicked points and they were tracked and if I hit 'r' a bunch were added and tracked.