2014/04/03

Face detection : OpenCV vs CIDetector

I found sample code to detect face in one OpenCV tutorial webpage. I knew there was a similar method in iOS, later I found it was called CIDetector in CoreImage framework. I didn’t know it was released since iOS 5.

I tried to measure time to detect face in both ways. I made a png image file which size is 1280 x 720 px, but this size seems to be too big. The sample code of OpenCV makes it gray and small. So both method receives the gray and small image, and time was measured after that. The measured part is here in OpenCV :
{
    cascade.detectMultiScale(image, faces,
                             1.1, 2,
                             CV_HAAR_SCALE_IMAGE,
                             cv::Size(30, 30));
}
CIDetector is here :
{
    NSDictionary *detectorOptions = [[[NSDictionary alloc] initWithObjectsAndKeys:CIDetectorAccuracyLow, CIDetectorAccuracy, nil] autorelease];
    CIDetector *faceDetector = [CIDetector detectorOfType:CIDetectorTypeFace context:nil options:detectorOptions];
    NSDictionary *imageOptions = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:1]                                                          forKey:CIDetectorImageOrientation];
    NSArray *array = [faceDetector featuresInImage:ciimage options:imageOptions];
}
result of face detection

↑The result image is here. OpenCV made the circle and the white square was made by the result of CIDetector.

The result of comparison, there are results that OpenCV is faster, and also there are results that CIDetector is faster. Finally it is up to our app setting, I suppose.
I wonder the time of CIDetector change dramatically at the second time. This is because Cocoa touch framework keeps something in itself? I experienced the same thing when I measured the time to implement sort (or something) in CoreData.

Here is the actual time data.
———————————————————
original image size is 1280x720px and make this gray and resize(1/4 or 1/2)
unit : [msec]

(1) iPod touch (5thG), iOS 7.1

1/4 resize
OpenCV : 217.10 → 212.25
CIDetector : 1115.63 → 281.25

1/2 resize
OpenCV : 862.41 → 857.82
CIDetector : 741.23 → 273.15

(2) iPhone 5s 32bit, iOS 7.1
1/4 resize
OpenCV : 45.03 → 43.77
CIDetector : 517.68 → 85.04

1/2 resize
OpenCV : 184.37 → 178.71
CIDetector : 416.24 → 85.36

———————————————————
You see the second time is faster in CIDetector, right?

By the way, this project is built as 32bit (even in iPhone 5s), because OpenCV is not available at 64bit, at least I don’t know the way to build as 64bit with OpenCV.
Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示