Reputation: 1872
I am trying to take a picture with the camera and then detect the faces in it. But it doesn't work... The results
array returns a count of zero. I have tested this code with a picture of somebody from the internet and it returned 1 found face. Here is my code:
// MARK: - UIImagePickerControllerDelegate Methods
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
Idea.CurrentIdea.idea.mockups.append(PFFile(data: UIImageJPEGRepresentation(pickedImage, 0.5)!))
//Face Detection
let cid:CIDetector = CIDetector(ofType:CIDetectorTypeFace, context:nil, options:[CIDetectorAccuracy: CIDetectorAccuracyHigh]);
let cii = CIImage(CGImage: pickedImage.CGImage!)
let results:NSArray = cid.featuresInImage(cii)
print(results.count)
for r in results {
let face:CIFaceFeature = r as! CIFaceFeature;
NSLog("Face found at (%f,%f) of dimensions %fx%f", face.bounds.origin.x, face.bounds.origin.y, face.bounds.width, face.bounds.height);
}
}
dismissViewControllerAnimated(true, completion: nil)
}
Any ideas? Thanks! There isn't much on the web about it recently.
Upvotes: 1
Views: 1701
Reputation: 1624
Make sure that your image orientation and the expected image orientation for the detector are the same. See this answer for more detail: https://stackoverflow.com/a/17019107/919790
Upvotes: 1