Guest User

Untitled

a guest
May 27th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "code",
  5. "execution_count": null,
  6. "metadata": {
  7. "collapsed": true
  8. },
  9. "outputs": [],
  10. "source": [
  11. "import numpy as np\n",
  12. "import cv2\n",
  13. "\n",
  14. "upbody_cascade=cv2.CascadeClassifier('./haarcascade_upperbody.xml')\n",
  15. "\n",
  16. "cap = cv2.VideoCapture(0) ## zero signifies default camera\n",
  17. "\n",
  18. "count=0\n",
  19. "\n",
  20. "while True:\n",
  21. " ret , img =cap.read()\n",
  22. " count=count+1\n",
  23. " filename='vid_with_face_%d.png'%(count,)\n",
  24. " #convert the captured img into GRAY Color\n",
  25. " gray = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)\n",
  26. " #Detect upper body of human if any in the frame\n",
  27. " upperbody=upbody_cascade.detectMultiScale(gray,1.3,5)\n",
  28. " #check if any upperbody of human is detected , if yes show it in an window and save it \n",
  29. " if len(upperbody)>0:\n",
  30. " cv2.imshow('img',gray)\n",
  31. " cv2.imwrite(filename,gray)\n",
  32. " \n",
  33. " k = cv2.waitKey(3) & 0xff #escape key\n",
  34. " if k==27:\n",
  35. " break\n",
  36. " \n",
  37. "cap.release()\n",
  38. "cv2.destroyAllWindows()\n",
  39. " "
  40. ]
  41. },
  42. {
  43. "cell_type": "code",
  44. "execution_count": null,
  45. "metadata": {
  46. "collapsed": true
  47. },
  48. "outputs": [],
  49. "source": []
  50. }
  51. ],
  52. "metadata": {
  53. "kernelspec": {
  54. "display_name": "Python 3",
  55. "language": "python",
  56. "name": "python3"
  57. },
  58. "language_info": {
  59. "codemirror_mode": {
  60. "name": "ipython",
  61. "version": 3
  62. },
  63. "file_extension": ".py",
  64. "mimetype": "text/x-python",
  65. "name": "python",
  66. "nbconvert_exporter": "python",
  67. "pygments_lexer": "ipython3",
  68. "version": "3.6.3"
  69. }
  70. },
  71. "nbformat": 4,
  72. "nbformat_minor": 2
  73. }
Add Comment
Please, Sign In to add comment