How to install OpenCV 3.0.0 for Java Eclipse in OSX 10.10.1 and up
OpenCV in Java is good, and on OSX is even better. There are many tutorials online, most of them out of date. They will lead you astray down dark and complicated alleys that dead end where no one can hear you scream. I’m here today to tell you how to avoid these pitfalls. Take my experience for free, because I love you, friend I haven’t met yet.*
*my results as of 2015-10-06, your mileage may vary.
OpenCV is a library that helps computers understand what they’re looking at. It can be as simple as finding a colored shape or a checkerboard, and as a complex as recognizing a face.
I need OpenCV working for the Evil Overlord and Evil Minion. The EM needs to be able to understand what it seems in order to do more kinds of work. Stupid robots expect everything to be perfect all the time. Slightly less stupid robots can look in the world and correct their movements based on what they see.
As I do most of my development on my ancient 17″ Apple laptop in Java, I need OpenCV to play nice with Eclipse. If you follow my steps you should be able to install OpenCV and start experimenting with advanced robotic vision systems.
Homebrew
Homebrew is “the missing package manager for OSX.” I followed their instructions and copied this line:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
into an OSX terminal. I had to also supply my sudo password. After a few moments installing, I then typed
brew tap homebrew/science brew install opencv3
Note that several tutorials suggested “brew install opencv” without the ‘3’, which no longer works. Then I got myself a snack and made dinner while it downloaded and installed everything needed. Lots of dependencies! Slow computer.
…then I started wondering if it was stuck in a loop…
When it’s finally done (it’s done!) the Java files will be in /usr/local/Cellar/opencv3/3.0.0/share/OpenCV/java/opencv-300.jar
Next, we’re going to set up a User Library, which comes in two parts: a jar file and a native library location. Basically the jar file explains to Java how to use the native library. The native library does OSX-specific stuff way way down near the machine level in specific ways that only OSX demands.
Open Eclipse. Choose a project and open Properties > Java Build Path > Libraries > Add Library > User Library > User Libraries > New. Type “OpenCV 3.0.0” to return to the “User Libraries” window. Choose “Add External Jars”, then press command+shift+G to get a popup that says “Go to folder”. Type in “/usr/local/Cellar/opencv3/3.0.0/share/OpenCV/java/” and then choose opencv-300.jar and click “Open”. Now there should be a small arrow next to “OpenCV 3.0.0”. Click that and a few options should appear, including “Native library location”. Click it and then click “Edit”. Use the command+shift+G option again to surf to the same folder, then click “Open” (note that this time you’re not choosing a specific file, you’re picking the entire folder.)
Finally, click “Ok” to get back to the main Eclipse window. Run your test script, and enjoy!
For what it’s worth, this process is still incredibly painful. How do we get it set up in Maven so that the people of the Water Tribe and the Fire nation can play with the people of the Earth Kingdom?