How to use the mtcnn.MTCNN function in mtcnn

To help you get started, we’ve selected a few mtcnn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipazc / mtcnn / tests / test_mtcnn.py View on Github external
def test_mtcnn_multiple_instances(self):
        """
        Multiple instances of MTCNN can be created in the same thread.
        :return:
        """
        detector_1 = MTCNN(steps_threshold=[.2, .7, .7])
        detector_2 = MTCNN(steps_threshold=[.1, .1, .1])

        ivan = cv2.imread("ivan.jpg")

        faces_1 = detector_1.detect_faces(ivan)
        faces_2 = detector_2.detect_faces(ivan)

        self.assertEqual(len(faces_1), 1)
        self.assertGreater(len(faces_2), 1)
github ipazc / mtcnn / tests / test_mtcnn.py View on Github external
def setUpClass(cls):
        global mtcnn
        mtcnn = MTCNN()
github ipazc / mtcnn / tests / test_mtcnn.py View on Github external
def test_mtcnn_multiple_instances(self):
        """
        Multiple instances of MTCNN can be created in the same thread.
        :return:
        """
        detector_1 = MTCNN(steps_threshold=[.2, .7, .7])
        detector_2 = MTCNN(steps_threshold=[.1, .1, .1])

        ivan = cv2.imread("ivan.jpg")

        faces_1 = detector_1.detect_faces(ivan)
        faces_2 = detector_2.detect_faces(ivan)

        self.assertEqual(len(faces_1), 1)
        self.assertGreater(len(faces_2), 1)
github ipazc / mtcnn / example.py View on Github external
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import cv2
from mtcnn import MTCNN

detector = MTCNN()

image = cv2.cvtColor(cv2.imread("ivan.jpg"), cv2.COLOR_BGR2RGB)
result = detector.detect_faces(image)

# Result is an array with all the bounding boxes detected. We know that for 'ivan.jpg' there is only one.
bounding_box = result[0]['box']
keypoints = result[0]['keypoints']

cv2.rectangle(image,
              (bounding_box[0], bounding_box[1]),
              (bounding_box[0]+bounding_box[2], bounding_box[1] + bounding_box[3]),
              (0,155,255),
              2)

cv2.circle(image,(keypoints['left_eye']), 2, (0,155,255), 2)
cv2.circle(image,(keypoints['right_eye']), 2, (0,155,255), 2)