1: <?php
2: /**
3: * Face_detect implementation
4: *
5: * @author Duck <duck@obala.net>
6: * @package Ansel
7: */
8: class Ansel_Faces_Facedetect extends Ansel_Faces_Base
9: {
10: /**
11: * Where the face defintions are stored
12: */
13: private $_defs = '';
14:
15: /**
16: * Create instance
17: */
18: public function __construct($params)
19: {
20: $this->_defs = $params['defs'];
21: }
22:
23: /**
24: *
25: */
26: public function canAutogenerate()
27: {
28: return true;
29: }
30:
31: /**
32: * Get faces
33: *
34: * @param string $file Picture filename
35: * @throws Horde_Exception
36: */
37: protected function _getFaces($file)
38: {
39: if (!Horde_Util::loadExtension('facedetect')) {
40: throw new Horde_Exception('You do not have the facedetect extension enabled in PHP');
41: }
42:
43: return face_detect($file, $this->_defs);
44: }
45:
46: /**
47: * Check if a face in is inside anoter face
48: *
49: * @param array $face Face we are cheking
50: * @param array $faces Existing faces
51: *
52: * @param int Face ID containg passed face
53: */
54: protected function _isInFace($face, $faces)
55: {
56: foreach ($faces as $id => $rect) {
57: if ($face['x'] > $rect['x'] && $face['x'] + $face['w'] < $face['x'] + $rect['w']
58: && $face['y'] > $rect['y'] && $face['y'] + $face['h'] < $face['y'] + $rect['h']) {
59: return $id;
60: }
61: }
62:
63: return false;
64: }
65:
66: protected function _createView($face_id, $image, $rect)
67: {
68: return $this->createView(
69: $face_id,
70: $image,
71: $rect['x'],
72: $rect['y'],
73: $rect['x'] + $rect['w'],
74: $rect['y'] + $rect['h']);
75: }
76:
77: }
78: