Dear myrobotlab,

I seem to have problems enabling my iSight webcam on my Macbook Pro through the myrobotlab Java application. 

Is anyone familiar with this problem and how i am able to solve it?

Thanks in advance.

GroG

12 years 10 months ago

And Welcome !

I have not run the opencv service with myrobotlab on a Mac yet, but I'm sure we can figure it out.

A quick look on the web revealed the following (see below) - taken from http://opencv.willowgarage.com/wiki/Mac_OS_X_OpenCV_Port

If you do get OpenCV installed, quite likely you might need to copy the files the installation steps put in the /opt/local/lib....
I'm guessing they might be cv.dmg highgui.dmg cxcore.dmg cvaux.dmg cxcore.dmg.  They might be mangled with version too (2.1)

At some point I will be trying this on a Mac as soon as I can get my hands on one.   Do you think this is something you can try yourself?  
 

GroG.

 

 

1. Easy build via MacPorts

For Snow Leopard users, you can build OpenCV 2.1.0 and above via MacPorts as a 64-bit library with support of QTKit video I/O and Cocoa GUI.

Assuming MacPorts installed, first use:

 

sudo port selfupdate

to update the MacPorts base and the port tree. Then, simply:

 

sudo port install opencv

to build OpenCV 2.1.0 in 64-bit.

If you encounter errors, try installing its dependents with +universal whenever possible.

 

sudo port -v install opencv +python26

to use with Python 2.6 bindings or

 

sudo port -v install opencv +python27

to use with Python 2.7 bindings

By default OpenCV is installed to /opt/local/ according to MacPorts conventions. The opencv_xxxx utilities are located in /opt/local/bin/, the dynamic libraries in /opt/local/lib/ and the header files in /opt/local/include/opencv/.

To use the libraries, include the required files with standard includes. For example:

 

#include <cv.h>
#include <highgui.h>

If you use Xcode, the instructions are similar to the ones in method 3. It only differs that /usr/local becomes /opt/local.

Dear Grog,

Thank you for your reply. 

I already have OpenCV installed by using Mac Ports and it is working quite well. 

Theres lots of opencv *.dylib files in the /opt/local/lib so i assume thats alright.

The *.dmg files you are mentioning are disk manage files, somewhat like a ISO file.

You can tell how Mac-ignorant I am.  Thanks for the distinction.  

If you've downloaded and unzipped the latest version of myrobolab you should have a directory structure like this:

/myrobotlab-0002
/myrobotlab-0002/bin
/myrobotlab-0002/lib

the myrobotlab.sh file calls b.sh
it has the following shell script line

java -d32 -Djava.library.path=./bin org.myrobotlab.service.Invoker -service Invoker services GUIService gui > log.txt

which starts myrobotlab with 2 running services an Invoker Service and a GUIService
the -Djava.library.path=./bin  is a directive to tell mrl where native libraries are located

I'm guessing you should be able to copy the opencv dynamic library files into the /myrobotlab-0002/bin directory.

On my Linux/PC system the files are named like this

 

libcvaux.so.2.1.0   libcxts.so.2.1.0     libml.so.2.1.0  libcv.so.2.1.0      libhighgui.so.2.1.0  libcxcore.so.2.1.0  
 
and are currently in the /myrobotlab-0002/bin directory.
 
Would the Mac Port install have libcvaux.dylib ... etc?

 
 



 

I forgot something.. The terminal outputs following when i try to connect cam:

java.lang.reflect.InvocationTargetException
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at com.myrobotlab.framework.Service.invoke(Service.java:690)
       at com.myrobotlab.framework.Service.invoke(Service.java:639)
       at com.myrobotlab.framework.Service.invoke(Service.java:569)
       at com.myrobotlab.framework.Service.process(Service.java:233)
       at com.myrobotlab.framework.Service.run(Service.java:215)
       at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.googlecode.javacv.jna.highgui
       at com.myrobotlab.service.OpenCV.capture(OpenCV.java:454)
       ... 10 more

It just looks like the application can't find the binaries...

Can you give me the list of names of the binaries now in the bin folder which came from the MacPort install?

Also, what "is" working with OpenCV - where there executables in the MacPort install?

Currently i have these files (links) in the myrobot*/bin library:

 

libopencv_calib3d.dylib
libopencv_contrib.dylib
libopencv_core.dylib
libopencv_features2d.dylib
libopencv_flann.dylib
libopencv_gpu.dylib
libopencv_highgui.dylib
libopencv_imgproc.dylib
libopencv_legacy.dylib
libopencv_ml.dylib
libopencv_objdetect.dylib
libopencv_ts.dylib
libopencv_video.dylib
libopenjpeg.dylib
 
my opencv2.2/lib directory looks like this, the files with version 2.2 and WITHOUT version are dynamic links:
 
lib
libopencv_calib3d_pch_dephelp.a
libopencv_calib3d.2.2.0.dylib
libopencv_calib3d.2.2.dylib
libopencv_calib3d.dylib
libopencv_contrib_pch_dephelp.a
libopencv_contrib.2.2.0.dylib
libopencv_contrib.2.2.dylib
libopencv_contrib.dylib
libopencv_core_pch_dephelp.a
libopencv_core.2.2.0.dylib
libopencv_core.2.2.dylib
libopencv_core.dylib
libopencv_features2d_pch_dephelp.a
libopencv_features2d.2.2.0.dylib
libopencv_features2d.2.2.dylib
libopencv_features2d.dylib
libopencv_flann_pch_dephelp.a
libopencv_flann.2.2.0.dylib
libopencv_flann.2.2.dylib
libopencv_flann.dylib
libopencv_gpu_pch_dephelp.a
libopencv_gpu.2.2.0.dylib
libopencv_gpu.2.2.dylib
libopencv_gpu.dylib
libopencv_highgui_pch_dephelp.a
libopencv_highgui.2.2.0.dylib
libopencv_highgui.2.2.dylib
libopencv_highgui.dylib
libopencv_haartraining_engine.a
libopencv_imgproc_pch_dephelp.a
libopencv_imgproc.2.2.0.dylib
libopencv_imgproc.2.2.dylib
libopencv_imgproc.dylib
libopencv_legacy_pch_dephelp.a
libopencv_legacy.2.2.0.dylib
libopencv_legacy.2.2.dylib
libopencv_legacy.dylib
libopencv_ml_pch_dephelp.a
libopencv_ml.2.2.0.dylib
libopencv_ml.2.2.dylib
libopencv_ml.dylib
libopencv_objdetect_pch_dephelp.a
libopencv_objdetect.2.2.0.dylib
libopencv_objdetect.2.2.dylib
libopencv_objdetect.dylib
libopencv_test_core_pch_dephelp.a
libopencv_test_pch_dephelp.a
libopencv_ts.2.2.0.dylib
libopencv_ts.2.2.dylib
libopencv_ts.dylib
libopencv_video_pch_dephelp.a
libopencv_video.2.2.0.dylib
libopencv_video.2.2.dylib
libopencv_video.dylib

I'm not sure... I don't believe there is direct references anywhere to a 2.1.0 but I'll need to check...

What about changing the  -Djava.library.path=./bin in myrobotlab-0002/b.sh file

to 

-Djava.library.path=<absolute path>/opencv2.2/lib ?

 

visionHead

12 years 10 months ago

In reply to by admin

I changed it to following

java -Djava.library.path=/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_graphics_opencv/work/OpenCV-2.2.0/lib  -cp "myrobotlab.jar;lib/*" com.myrobotlab.service.Invoker -service Invoker invoker GUIService gui > log.txt

I still seem to get the errors:

 

 

at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.googlecode.javacv.jna.cxcore
at com.myrobotlab.image.OpenCVFilterHSV.<init>(OpenCVFilterHSV.java:76)
... 16 more
 
and
 
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': dlopen(libcxcore.dylib, 9): image not found
 

this error makes good sense, theres no such file!

something must be totally wrong, i cannot seem to find any the libcxcore.dylib anywhere?

That is strange, it exists on my system !?!?    Most of the OpenCV samples use it too....?

I tried to do a manual install of opencv 2.0 which succeeded and my missing dylibs files appeared, but the application is still looking in the wrong directory

 

 

Caused by: java.lang.UnsatisfiedLinkError: Unable to load library 'cxcore': dlopen(/usr/lib/libcxcore.dylib, 9): no suitable image found.  Did find:
/usr/lib/libcxcore.dylib: mach-o, but wrong architecture
 
I get a bad feeling when i read the error above, but its pointing in the wrong directory (/usr/lib/*) should be 
 
java -Djava.library.path=./bin com.myrobotlab.service.Invoker -service Invoker invoker GUIService gui > log.txt
 
Why is it not looking in the bin as stated?

I have changed the path, its still looking in /usr/lib

I saw this link:

http://code.google.com/p/javacv/issues/detail?id=3

 

Someone replied:

 

Hi samuel,  
I want to suggest you to add the path "/opt/local/lib" in the cxcore class for those who installed opencv via 
Macports (that's the default installation directory) to avoid the first error discussed in this thread.
ps. thanks for the great work

I dont exactly understand how to change that path?

It looks as if Samuel has fixed it, I assume in his latest release...

I'm guessing that if you download and replace the myrobotlab-0002/lib/javacv.jar  it might work now?

If it does, I'm not sure why/how the path is hardcoded in javacv ?   Samuel is an excellent developer, I would be very surprised if he has hardcoded paths... :P

I'm going to get the latest release from JavaCV and check to make sure it works on my system.  So for you the OpenCV service will load in version 0001 but not 0002?  Any error info?

This is odd. I tried to reinstall the macport for opencv, now i can suddenly use 0002 with OpenCV.. But no webcam view.

 

Oh and this time theres no error in the terminal!

I think we are getting closer visionHead..
previously I had builds/binaries for Linux & windows from opencv 2.1
I see a considerable amount of change between 2.1 and 2.2

Some of the differences besides actual code changes is the binary names...
previously opencv would produce shared libraries like libcv.so,

now they have shared objects like libopencv_core.so.2.2

Also, JavaCV has changed considerably -  Samuel is now release many jars - some look like they distinguish between 32 and 64 bit...

I am now in the process of syncing up... starting with opencv builds - I have just successfully built the Linux versions of opencv 2.2 ..  after that I will build the windows version... and after that I'll get the latest JavaCV verify that it works and bundle it all up...

I'm sure that this was some of the root cause of the problem as the MacPort installs 2.2 and MRL came with 2.1..

After I synch up Linux, windows & JavaCV, I'll notify you...

My preference is to have MRL run with a local copy of the binaries... this guarantees compatibility.. and if the command line is done correctly - the user can install any version of OpenCV on their system, which MRL will NOT be dependent on...  So, when we get it working on your system can you send me the shared libraries you have from the MacPort so I can bundle those?

Regards,
GroG

I just downloaded it, but what bothers me is that there is no reaction in the terminal anymore.. I get no error or anything.. But sadly, still no webcam view! 

Hello visionHead,

I believe we need to start with very small steps to see where the issue is.

I have compiled one of JavaCV's samples "MotionDetector" -  Strangely, the other two samples "HoughLines and OpticalFlowTracker"  do not work on my system..  I'll be investigating the details and possibly submitting bugs to Samuel Audet @ JavaCV

Please download the class file MotionDetector.class   from http://code.google.com/p/myrobotlab/downloads/list

put it in the myrobotlab-0003/lib directory

You should be able to launch the MotionDetector through a terminal...

cd to the myrobotlab-0003/lib directory and run the following command:

java -classpath $CLASSPATH:javacpp.jar:javacv.jar:javacv-macosx-x86_64.jar -Djava.library.path=/<absolute location of the libopencv_*2.2.0.dylibs>  MotionDetector

A Canvas Frame with hardware acceleration should come up, and your camera should turn on - 
It will be black but when you move it should detect it.  It "should" look like this when you move

If it does work YAY - 1 small step

If it does not work:
I will need any error information which comes back.

visionHead

12 years 10 months ago

In reply to by admin

I downloaded the 0003 and the MotionDetector.class file as described..

Unfortunately no positive result:

 

java -classpath $CLASSPATH:javacpp.jar:javacv.jar:javacv-macosx-x86_64.jar -Djava.library.path=/opt/local/lib  MotionDetector
Exception in thread "main" java.lang.NoClassDefFoundError: MotionDetector
Caused by: java.lang.ClassNotFoundException: MotionDetector
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

I tried following:

java -classpath ":./javacv.jar" -Djava.library.path=/opt/local/lib MotionDetector

It gives med only:

 

Camera dropped frame!
 
And its starts java, but the application has crashed, so i need to kill it from terminal.
 
Oh god, you really need to change this forum, its very unfriendly for replies :o)

Sadly im running out of time in my project. So im curious about the possibilities with importing an image into OpenCV in myrobotlab and just ignoring the camera function for  while.

If image importing is not possible, then AVI-file import. If you have a guide i would appreciate it highly!

 

Thanks in advance.

I did a opencv 2.2 build and loaded Samuel's javacv libs...
My Eclipse editor has lit up like a Christmas Tree with all the errors ... this will take a little time to correct..
Most of it looks pretty easy like, import path changes from jna to cpp and from .core to .opencv_core

binaries in opencv/bin:

 

bin
3calibration
adaptiveskindetector
bagofwords_classification
bgfg_codebook
bgfg_segm
blobtrack_sample
brief_match_test
build3dmodel
calibration
calibration_artificial
camshiftdemo
chamfer
connected_components
contours
contours2
convert_cascade
convexhull
cout_mat
delaunay
demhist
descriptor_extractor_matcher
dft
distrans
drawing
edge
facedetect
fback
fback_c
ffilldemo
filestorage
find_obj
find_obj_calonder
find_obj_ferns
fitellipse
generic_descriptor_match
grabcut
hog_gpu
houghlines
image
imagelist_creator
inpaint
kalman
kmeans
laplace
latentsvmdetect
letter_recog
lkdemo
matcher_simple
matching_to_many_images
meanshift_segmentation
minarea
morphology
morphology2
motempl
mser_sample
mushroom
one_way_sample
opencv_createsamples
opencv_haartraining
opencv_performance
opencv_test
opencv_test_core
opencv_test_gpu
opencv_test_ml
opencv_traincascade
peopledetect
polar_transforms
pyramid_segmentation
segment_objects
select3dobj
squares
starter_imagelist
starter_video
stereo_calib
stereo_match
tree_engine
video_homography
watershed

myrobotlab uses JavaCV to interface with the OpenCV binaries -

 

http://code.google.com/p/javacv/

Samuel states Java 6 SE is needed - the link he posted is here :

 

Java SE 6 for Mac OS X http://developer.apple.com/java/ etc.

Can you confirm you have Java SE 6 ?

Are you getting any output?  Any errors?

When you say you have opencv working, in what context do you have it working?  The sample .c examples which ship with OpenCV?

Regards,

GroG

 

java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07-334-10M3326)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02-334, mixed mode)
 
I have my projects running in OpenCV right now.. I use a OpenCV framework from vislab for XCode. Samples work aswell as my own project!

 

 

If you do get OpenCV installed, quite likely you might need to copy the files the installation steps put in the /opt/local/lib....
I'm guessing they might be cv.dmg highgui.dmg cxcore.dmg cvaux.dmg cxcore.dmg.  They might be mangled with version too (2.1)

Im not quite sure if i got this wrong, but did you mean that i should copy the files else where? If so, where should i place them?

Thanks in advance.

 

That reply thread was getting squished, so I started another one....

The error you reported

 

java -classpath $CLASSPATH:javacpp.jar:javacv.jar:javacv-macosx-x86_64.jar -Djava.library.path=/opt/local/lib  MotionDetector Exception in thread "main" java.lang.NoClassDefFoundError: MotionDetector Caused by: java.lang.ClassNotFoundException: MotionDetector at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

 

It looks as if it can't find the MotionDetector class - which can be caused by not getting the -classpath correct...
Event on a Linux machine I find the weird and slightly different notation of the -classpath directive frustrating..
For example 

 

 

java -classpath ":./javacv.jar" -Djava.library.path=/usr/local/lib MotionDetector

works for me on Fedora 13  

But,
 
 java -classpath "./javacv.jar" -Djava.library.path=/usr/local/lib MotionDetector
 
Does not !
Why?  I don't know, but a single semi-colon makes a difference ! :P
 
The second one generates an error very similar to the one you reported
 
Exception in thread "main" java.lang.NoClassDefFoundError: MotionDetector
Caused by: java.lang.ClassNotFoundException: MotionDetector
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334)
 
 
Without accessibility to a mac I am at a loss of what to try next...
 
My wife has a mac, but she will not be back until Wed...
 
Yarrggg :P


 

 

 

admin

12 years 10 months ago

I've started to install MacPorts, OpenCV and all the dependencies on my borrowed mac...

 

Have you tried downloading and installing JavaCV's samples?  MotionDetector was one of them.

visionHead

12 years 10 months ago

I dont really use that, i use basic functions to track a object. My project is up running, but its a pain in the ass adjusting the HSV and testing filters, which is a great benefit using your application. Is there no way to import af AVI or IMAGE to the application instead of camera streaming?

admin

12 years 10 months ago

I downloaded myrobotlab-0005.zip

I loaded OpenCV 2.2 from MacPorts

Ba-bing ! - http://myrobotlab.org/node/93

See if you get lucky with the latest (myrobotlab-0005.zip) - if not send me the log.txt 

Good Luck.

visionHead

12 years 10 months ago

It works now! But the frames are EXTREMELY slow, i get this output in terminal.

Great progress!!

 

Camera dropped frame!
Camera dropped frame!
Camera dropped frame!
Exception in thread "OpenCV_videoProcessor" java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(DataBufferByte.java:42)
at java.awt.image.Raster.createInterleavedRaster(Raster.java:253)
at java.awt.image.BufferedImage.<init>(BufferedImage.java:368)
at com.googlecode.javacv.cpp.opencv_core$IplImage.getBufferedImage(opencv_core.java:828)
at com.googlecode.javacv.cpp.opencv_core$IplImage.getBufferedImage(opencv_core.java:822)
at com.googlecode.javacv.cpp.opencv_core$IplImage.getBufferedImage(opencv_core.java:819)
at org.myrobotlab.service.OpenCV$VideoProcess.run(Unknown Source)
at java.lang.Thread.run(Thread.java:680)
Camera dropped frame!

visionHead

12 years 10 months ago

I just realised its impossible using the gui on a 13" screen :o) Damn.

admin

12 years 10 months ago

You can load the pyramid down filter which will reduce the size of the frames.
When you load a filter it must be a unique name.  But, you can load as meaning filters as you want.  Meaning you can load PyramidDown twice with 2 unique names, and your image size will be 1/4 the original.

visionHead

12 years 10 months ago

That helped alot. Now i have a mysterious question! Why does the InRange act different in the myrobotlab gui compared to InRange directly in my OpenCV project? I cant seem to take the HSV values directly from the simulation in my myrobotlab and use them in the project?! :-/

admin

12 years 10 months ago

I have not seen you project, So its hard for me to say...

This is a link to the inRange filter I created for mrl.

You can quickly find who/which is reporting correctly by taking some samples of colors and plot what values they should have.