Recognizing The iPhone
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
<?xml version="1.0"?> <opencv_storage> <cascade> <stageType>BOOST</stageType> <featureType>HAAR</featureType> <height>32</height> <width>32</width> <stageParams> <boostType>GAB</boostType> <minHitRate>9.9500000476837158e-01</minHitRate> <maxFalseAlarm>5.0000000000000000e-01</maxFalseAlarm> <weightTrimRate>9.4999999999999996e-01</weightTrimRate> <maxDepth>1</maxDepth> <maxWeakCount>100</maxWeakCount></stageParams> <featureParams> <maxCatCount>0</maxCatCount> <featSize>1</featSize> <mode>BASIC</mode></featureParams> <stageNum>3</stageNum> <stages> <!-- stage 0 --> <_> <maxWeakCount>1</maxWeakCount> <stageThreshold>1.</stageThreshold> <weakClassifiers> <_> <internalNodes> 0 -1 0 6.3478387892246246e-03</internalNodes> <leafValues> -1. 1.</leafValues></_></weakClassifiers></_> <!-- stage 1 --> <_> <maxWeakCount>1</maxWeakCount> <stageThreshold>1.</stageThreshold> <weakClassifiers> <_> <internalNodes> 0 -1 2 -6.0746502876281738e-01</internalNodes> <leafValues> 1. -1.</leafValues></_></weakClassifiers></_> <!-- stage 2 --> <_> <maxWeakCount>1</maxWeakCount> <stageThreshold>1.</stageThreshold> <weakClassifiers> <_> <internalNodes> 0 -1 1 -2.4005537852644920e-02</internalNodes> <leafValues> 1. -1.</leafValues></_></weakClassifiers></_></stages> <features> <_> <rects> <_> 0 0 12 3 -1.</_> <_> 4 0 4 3 3.</_></rects> <tilted>0</tilted></_> <_> <rects> <_> 0 0 16 4 -1.</_> <_> 0 0 8 2 2.</_> <_> 8 2 8 2 2.</_></rects> <tilted>0</tilted></_> <_> <rects> <_> 0 0 30 19 -1.</_> <_> 10 0 10 19 3.</_></rects> <tilted>0</tilted></_></features></cascade> </opencv_storage> |
I’m spending the month of July in Utrecht, Netherlands as artist-in-residence at Impakt, working on a project to let computers recognize other computers. For early testing, I’ve trained a computer vision “cascade file” (above) for recognizing front-facing iPhones.
The resulting cascade files, like above, will be released as a printed book, as well as on GitHub.
Automating OpenCV Training Tests
Automating the process of testing OpenCV training settings using a little Python script.
Collection File App – Updated UI
Collection File App
A screenshot of a little Processing app for marking objects in photographs. The app saves a “cascade file” for use in training OpenCV. In-progress version is on GitHub.
Installing OpenCV on Mac
UPDATE: Mavericks users were likely frustrated for the last few weeks trying to install OpenCV. It appears the problem has been fixed, and these instructions should work without issue.
My previous post on installing OpenCV for Mac users is one of the most popular on this site (which is simultaneously surprising and fantastic). However, I recently switched from using MacPorts to Homebrew – users that need to migrate existing installs can check out this guide.
Still complicated but thoroughly do-able, here is how to install OpenCV on a Mac running Mountain Lion:
- Open Applications > Utilities > Terminal…
- Install Homebrew by typing the following into Terminal
1ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install) - Run the command brew doctor to check for any errors
- While normal installations using Homebrew are very straightforward, for some reason OpenCV requires an extra step – you need to install an add-on called
science:
1brew tap homebrew/science - Then you can run the usual Homebrew command to install OpenCV:
1brew install opencv
If this fails, it may be that you have ffmpeg installed – if so, try this instead:
1brew install opencv --env=std - This may take several minutes, so be patient!
- Homebrew may tell you that you have to update PYTHONPATH – if so, open your favorite text editor, click File > Open… and hit command+shift+. to see hidden files
- Navigate up to your home folder and open the .bash_profile file – if it doesn’t exist, create it yourself
- Add the line suggested by Homebrew, probably something like:
1export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH - Save the file and close it – you may also have to exit Terminal and open it again
- Test by opening Python:
1python
Then try to import OpenCV:
1import cv - If you don’t get any errors, you’re all set! Now go enjoy a real beer!
Hope this helps! Problems, suggestions – leave them in the comments.
Installing OpenCV for Python on Mac Lion
Like previous installs of other command-line tools like FFMPEG, the frustration often does not seem worth the trouble. Esoteric errors are near impossible to parse and files are installed in odd places (odd to me, at least). Below are the steps I used to install the OpenCV library (blob detection, facial tracking, etc etc) for use with Python on my Mac, running 10.7.4 (Lion).
Much of this was pulled from a StackOverflow post (http://stackoverflow.com/a/6087778/1167783) but the suggestions would have been less helpful had they not be corroborated by several other posts with similar suggestions. That said, this was the only guide I could find that worked well for me (thanks!).
- Install MacPorts (download here)
If you haven’t already – this makes installation mucheasier; test the install by typing the following into the Terminal:
1port
If you don’t get an error, it installed correctly - Check your Python version
If you have Lion, you are likely running Python 2.7 – to double-check, type:
1Python
And see what version comes up. The problem installing OpenCV for Python seems to be a conflict between what version of Python MacPorts assumes and what you’re really running. To be sure you are using 2.7, type this into the Terminal:
1sudo port select --set python python27 - Install NumPy
Not sure why this is necessary, but appears to be (NumPydoes 2d array processing, so that’s likely the reason); type the following:
1sudo port install py27-numpy - Install OpenCV
We’re ready! Type the following and be prepared to wait – OpenCV is quite large and takes a while to download and get set up. If you’ve already installed it in another location (I had) it appears that MacPorts just links it – nice! Type:
1sudo port install opencv +python27 - Test
In the Terminal, type the following to enter Python:
1python
Then, to test OpenCV, type:
1import cv
If you don’t get an error, you’re good! To exit Python, type:
1exit()
Some of the suggestions I found say that you need to do some further profile editing and other (weird) stuff – I didn’t need to, but if you have problems it might be worth a try.
To further test the library, try this simple example that converts an image from one file format to another. I wrote this in TextWrangler, saved the file, and ran it using the #! > Run in Terminal… command (requires the command-line tools to be installed.
1 2 3 |
import cv im = cv.LoadImageM("test.jpg") cv.SaveImage("test-converted.png", im) |
The new file should be generated and you’re good to go!
Thoughts, suggestions, or problems? Please send me an email: mail [at] jeffreythompson [dot] org
Further Blobs > Drawing
Further version of the blob-tracking drawing software for my Digital Drawing class – goes into use tomorrow!
Image Tracking/Drawing
A few (not quite working) screenshots of a image tracking/drawing software I’m writing in Processing today for my Digital Drawing class.
No Longer A Face
Using facial-recognition algorithms (Processing’s OpenCV library) while slowly degrading an image until the algorithm no longer sees a face.