after beautiful weekend all done
This commit is contained in:
parent
97bef3fb5c
commit
d1c7a3aaa6
83
wko-02.ipynb
83
wko-02.ipynb
File diff suppressed because one or more lines are too long
99
wko-03.ipynb
99
wko-03.ipynb
@ -1080,6 +1080,105 @@
|
||||
"\n",
|
||||
"![HighGUI Canny](img/highgui-canny.png)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "b68fdade",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import cv2 as cv\n",
|
||||
"import numpy as np\n",
|
||||
"import matplotlib.pyplot as plt\n",
|
||||
"%matplotlib inline"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "305441e2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"ename": "error",
|
||||
"evalue": "OpenCV(4.5.5) /io/opencv/modules/imgproc/src/smooth.dispatch.cpp:293: error: (-215:Assertion failed) ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1 in function 'createGaussianKernels'\n",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31merror\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_17561/1543211412.py\u001b[0m in \u001b[0;36mfuncCan\u001b[0;34m(thresh1, thresh2, apertureSize, blur)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0maperture_size\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Aperture size'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mblur\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Blur'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mimage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mimage2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0medge\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCanny\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mapertureSize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maperture_size\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31merror\u001b[0m: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/smooth.dispatch.cpp:293: error: (-215:Assertion failed) ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1 in function 'createGaussianKernels'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "error",
|
||||
"evalue": "OpenCV(4.5.5) /io/opencv/modules/imgproc/src/smooth.dispatch.cpp:293: error: (-215:Assertion failed) ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1 in function 'createGaussianKernels'\n",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31merror\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_17561/1543211412.py\u001b[0m in \u001b[0;36mfuncCan\u001b[0;34m(thresh1, thresh2, apertureSize, blur)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0maperture_size\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Aperture size'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mblur\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Blur'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mimage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mimage2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0medge\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCanny\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mapertureSize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maperture_size\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31merror\u001b[0m: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/smooth.dispatch.cpp:293: error: (-215:Assertion failed) ksize.width > 0 && ksize.width % 2 == 1 && ksize.height > 0 && ksize.height % 2 == 1 in function 'createGaussianKernels'\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"ename": "KeyboardInterrupt",
|
||||
"evalue": "",
|
||||
"output_type": "error",
|
||||
"traceback": [
|
||||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
||||
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
|
||||
"\u001b[0;32m/tmp/ipykernel_17561/1543211412.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 40\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0m__name__\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m\"__main__\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 41\u001b[0;31m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
|
||||
"\u001b[0;32m/tmp/ipykernel_17561/1543211412.py\u001b[0m in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m 28\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 29\u001b[0m \u001b[0;32mwhile\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 30\u001b[0;31m \u001b[0mfuncCan\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 32\u001b[0m \u001b[0mk\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitKey\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m&\u001b[0m \u001b[0;36m0xFF\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;32m/tmp/ipykernel_17561/1543211412.py\u001b[0m in \u001b[0;36mfuncCan\u001b[0;34m(thresh1, thresh2, apertureSize, blur)\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0maperture_size\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Aperture size'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m3\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[0mblur\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m2\u001b[0m \u001b[0;34m*\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetTrackbarPos\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Blur'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'Canny'\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 8\u001b[0;31m \u001b[0mimage\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 9\u001b[0m \u001b[0mimage2\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGaussianBlur\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimg\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mblur\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 10\u001b[0m \u001b[0medge\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcv\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mCanny\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mimage\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthresh2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mapertureSize\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maperture_size\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
|
||||
"\u001b[0;31mKeyboardInterrupt\u001b[0m: "
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"def funcCan(thresh1=0, thresh2=0, apertureSize=0, blur=0):\n",
|
||||
" original=cv.imread(\"img/lena.png\",1)\n",
|
||||
" img=original.copy()\n",
|
||||
" thresh1 = cv.getTrackbarPos('Threshold 1', 'Canny')\n",
|
||||
" thresh2 = cv.getTrackbarPos('Threshold 2', 'Canny')\n",
|
||||
" aperture_size = 2 * cv.getTrackbarPos('Aperture size', 'Canny') + 3\n",
|
||||
" blur = 2 * cv.getTrackbarPos('Blur', 'Canny') + 1\n",
|
||||
" image=cv.GaussianBlur(img,(blur,blur),0)\n",
|
||||
" image2=cv.GaussianBlur(img,(blur,blur),0)\n",
|
||||
" edge = cv.Canny(image, thresh1, thresh2, apertureSize=aperture_size)\n",
|
||||
" cv.imshow('Canny', edge)\n",
|
||||
" cv.imshow('Original with blur',image2)\n",
|
||||
" \n",
|
||||
"def main():\n",
|
||||
" original=cv.imread(\"img/lena.png\",1)\n",
|
||||
" cv.namedWindow('Canny')\n",
|
||||
" cv.imshow('Original',original)\n",
|
||||
"\n",
|
||||
" thresh1=100\n",
|
||||
" thresh2=1\n",
|
||||
" aperture_size = 0\n",
|
||||
" blur = 2\n",
|
||||
"\n",
|
||||
" cv.createTrackbar('Threshold 1','Canny',thresh1,255,funcCan)\n",
|
||||
" cv.createTrackbar('Threshold 2','Canny',thresh2,255,funcCan)\n",
|
||||
" cv.createTrackbar('Aperture size','Canny',aperture_size,2,funcCan)\n",
|
||||
" cv.createTrackbar('Blur','Canny',blur,20,funcCan)\n",
|
||||
"\n",
|
||||
" while(True):\n",
|
||||
" funcCan(0,0,0,0)\n",
|
||||
"\n",
|
||||
" k = cv.waitKey(1) & 0xFF\n",
|
||||
" if k == 27:\n",
|
||||
" break\n",
|
||||
"\n",
|
||||
" # Close the window\n",
|
||||
" cv.destroyAllWindows()\n",
|
||||
" cv.waitKey(1)\n",
|
||||
" \n",
|
||||
"if __name__ == \"__main__\":\n",
|
||||
" main()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
201
wko-05.ipynb
201
wko-05.ipynb
File diff suppressed because one or more lines are too long
1539
wko-06.ipynb
1539
wko-06.ipynb
File diff suppressed because one or more lines are too long
1583
wko-07.ipynb
1583
wko-07.ipynb
File diff suppressed because one or more lines are too long
1234
wko-08.ipynb
1234
wko-08.ipynb
File diff suppressed because one or more lines are too long
1332
wko-09.ipynb
1332
wko-09.ipynb
File diff suppressed because it is too large
Load Diff
1884
wko-10.ipynb
1884
wko-10.ipynb
File diff suppressed because one or more lines are too long
132
zag_9.py
Normal file
132
zag_9.py
Normal file
@ -0,0 +1,132 @@
|
||||
import argparse
|
||||
import time
|
||||
|
||||
import cv2
|
||||
import dlib
|
||||
import imutils
|
||||
import numpy as np
|
||||
from imutils import face_utils
|
||||
from imutils.video import FileVideoStream, VideoStream
|
||||
from scipy.spatial import distance as dist
|
||||
|
||||
def eye_aspect_ratio(eye):
|
||||
A = dist.euclidean(eye[1], eye[5])
|
||||
B = dist.euclidean(eye[2], eye[4])
|
||||
C = dist.euclidean(eye[0], eye[3])
|
||||
ear = (A + B) / (2.0 * C)
|
||||
return ear
|
||||
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument(
|
||||
"-p", "--shape-predictor", required=True, help="path to facial landmark predictor"
|
||||
)
|
||||
ap.add_argument("-v", "--video", type=str, default="", help="path to input video file")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
|
||||
EYE_AR_THRESH = 0.3
|
||||
EYE_AR_CONSEC_FRAMES = 3
|
||||
|
||||
|
||||
COUNTER = 0
|
||||
TOTAL = 0
|
||||
|
||||
|
||||
print("[INFO] loading facial landmark predictor...")
|
||||
detector = dlib.get_frontal_face_detector()
|
||||
predictor = dlib.shape_predictor(args["shape_predictor"])
|
||||
|
||||
|
||||
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
|
||||
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
|
||||
|
||||
|
||||
print("[INFO] starting video stream thread...")
|
||||
vs = FileVideoStream(args["video"]).start()
|
||||
fileStream = True
|
||||
vs = VideoStream(src=0).start()
|
||||
fileStream = False
|
||||
time.sleep(1.0)
|
||||
|
||||
# uncomment to our video
|
||||
# video = cv2.VideoCapture("vid/blinking-woman1.mp4")
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
if fileStream and not vs.more():
|
||||
break
|
||||
|
||||
frame = vs.read()
|
||||
|
||||
# uncomment to our video
|
||||
# _, frame = video.read()
|
||||
|
||||
# comment to our video
|
||||
frame = imutils.resize(frame, width=800)
|
||||
|
||||
# comment to our video
|
||||
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
|
||||
|
||||
rects = detector(gray, 0)
|
||||
|
||||
# uncomment to our video
|
||||
# rects = detector(frame, 0)
|
||||
|
||||
for rect in rects:
|
||||
|
||||
# shape = predictor(gray, rect)
|
||||
shape = predictor(frame, rect)
|
||||
shape = face_utils.shape_to_np(shape)
|
||||
|
||||
leftEye = shape[lStart:lEnd]
|
||||
rightEye = shape[rStart:rEnd]
|
||||
leftEAR = eye_aspect_ratio(leftEye)
|
||||
rightEAR = eye_aspect_ratio(rightEye)
|
||||
|
||||
ear = (leftEAR + rightEAR) / 2.0
|
||||
|
||||
leftEyeHull = cv2.convexHull(leftEye)
|
||||
rightEyeHull = cv2.convexHull(rightEye)
|
||||
cv2.drawContours(frame, [leftEyeHull], -1, (0, 255, 0), 1)
|
||||
cv2.drawContours(frame, [rightEyeHull], -1, (0, 255, 0), 1)
|
||||
|
||||
if ear < EYE_AR_THRESH:
|
||||
COUNTER += 1
|
||||
|
||||
else:
|
||||
|
||||
if COUNTER >= EYE_AR_CONSEC_FRAMES:
|
||||
TOTAL += 1
|
||||
|
||||
COUNTER = 0
|
||||
|
||||
cv2.putText(
|
||||
frame,
|
||||
"Blinks: {}".format(TOTAL),
|
||||
(10, 30),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.7,
|
||||
(0, 0, 255),
|
||||
2,
|
||||
)
|
||||
cv2.putText(
|
||||
frame,
|
||||
"EAR: {:.2f}".format(ear),
|
||||
(300, 30),
|
||||
cv2.FONT_HERSHEY_SIMPLEX,
|
||||
0.7,
|
||||
(0, 0, 255),
|
||||
2,
|
||||
)
|
||||
|
||||
|
||||
cv2.imshow("Frame", frame)
|
||||
key = cv2.waitKey(1) & 0xFF
|
||||
|
||||
if key == ord("q"):
|
||||
break
|
||||
|
||||
|
||||
cv2.destroyAllWindows()
|
||||
# vs.stop()
|
Loading…
Reference in New Issue
Block a user