Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": [
- "import numpy as np\n",
- "import cv2\n",
- "\n",
- "upbody_cascade=cv2.CascadeClassifier('./haarcascade_upperbody.xml')\n",
- "\n",
- "cap = cv2.VideoCapture(0) ## zero signifies default camera\n",
- "\n",
- "count=0\n",
- "\n",
- "while True:\n",
- " ret , img =cap.read()\n",
- " count=count+1\n",
- " filename='vid_with_face_%d.png'%(count,)\n",
- " #convert the captured img into GRAY Color\n",
- " gray = cv2.cvtColor(img , cv2.COLOR_BGR2GRAY)\n",
- " #Detect upper body of human if any in the frame\n",
- " upperbody=upbody_cascade.detectMultiScale(gray,1.3,5)\n",
- " #check if any upperbody of human is detected , if yes show it in an window and save it \n",
- " if len(upperbody)>0:\n",
- " cv2.imshow('img',gray)\n",
- " cv2.imwrite(filename,gray)\n",
- " \n",
- " k = cv2.waitKey(3) & 0xff #escape key\n",
- " if k==27:\n",
- " break\n",
- " \n",
- "cap.release()\n",
- "cv2.destroyAllWindows()\n",
- " "
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "outputs": [],
- "source": []
- }
- ],
- "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.6.3"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment