A simple command line tool to detect faces in photographs using Apple’s Core Image Library.
The app runs in the terminal and returns the coordinates of the faces found by Core Image in files defined by their paths. The processing of one image takes milliseconds. The tool can be easily integrated with apps written in PHP, Java, Ruby, etc.
After the launch of the app the user is asked to enter the absolute path of a photograph followed by \n. The tool returns the coordinates of all faces that have been found:
[[face1_left, face1_top, face1_width, face1_height], [face2_left, ...], ...]. An error message is shown instead in case of a problem (also in stdout). The user is asked to enter another image path after that. To exit the tool an empty string or EOF should be entered.
The app accepts
--low-accuracy as a parameter to use a faster version of the Core Image face detection algorithm.
The tool has been developed and tested on Mac OS 10.8 Mountain Lion, but will probably work on the earlier versions of it. You can clone the repository and build the app in xCode yourself or simply try to run the compiled executable file.
$ ./CICommandLineFaceDetector Enter image path> /path/to/image.jpg [[206,71,56,56],[130,101,40,40]] Enter image path> /path/to/image2.jpg  Enter image path> /wrong/path/to/image.jpg Error: file does not exist Enter image path> /path/to/broken/image.jpg Error: wrong image Enter image path> /path/to/image3.jpg [[235,241,44,44]] Enter image path> $
$./CICommandLineFaceDetector --low-accuracy # Faster but less accurate Enter image path> /path/to/image.jpg [[206,71,56,56],[130,101,40,40]] # The result is a bit different Enter image path> /path/to/image3.jpg  # Some faces can not be found when --low-accuracy is on Enter image path> $
The tool does not look into the EXIF data and therefore does not consider the orientation of the images. Thus, the photographs having [0,0] not in the top-left corner will not be handled correctly. It is important to make sure that the faces are in the upright position because CoreImage mostly detects only them.