openCV人脸检测-替换 源代码:

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "face_detector = cv2.CascadeClassifier('./haarcascade_frontalface_alt.xml')\n",
    "img = cv2.imread('./di.jpg')\n",
    "rose = cv2.imread('./rose.png')\n",
    "face_zones = face_detector.detectMultiScale(img)\n",
    "for x,y,w,h in face_zones:\n",
    "    rose = cv2.resize(rose,(w,h))\n",
    "    img[y:y+h,x:x+w] = rose\n",
    "cv2.imshow('hot',img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}

你可能感兴趣的:(openCV人脸检测-替换 源代码:)