{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"haar.ipynb","provenance":[],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"},"accelerator":"GPU"},"cells":[{"cell_type":"code","metadata":{"id":"P2dSl2N84_Az"},"source":["from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"TrT3gZ78ykJo"},"source":["!sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"HCoZk62XykX0"},"source":["!sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"PXr6BJeyykak"},"source":["!sudo apt-get install libopencv-dev"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"LCRM10Nyykdp"},"source":["cd /content/drive/My Drive/drive2"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"N1lYZB9Tykrw"},"source":["ls"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"XrKW5G4HzQ4B"},"source":["import os\n","import cv2\n","import numpy as np\n","\n","def create_negative_description_file(path,file_name):\n"," for image in os.listdir(path):\n"," line = path+image\n"," with open(file_name,'a') as f:\n"," f.write(line)\n"," f.write('\\n')\n","\n","def create_positive_description_file(path,file_name):\n"," #image_names = os.listdir(path)\n"," for image in os.listdir(path):\n"," line = path+image+' 1 0 0 64 64'\n"," with open(file_name,'a') as f:\n"," f.write(line)\n"," f.write('\\n')\n"," \n","\n","create_positive_description_file('./pos/','info.txt')\n"," \n","create_negative_description_file('./neg/','bg.txt')"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"a21JAn-0zijE"},"source":["!opencv_createsamples -info info.txt -num 1816 -w 24 -h 24 -vec cars.vec"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"FiaNt-q6zjAv","colab":{"base_uri":"https://localhost:8080/","height":590},"executionInfo":{"status":"ok","timestamp":1572550451510,"user_tz":-330,"elapsed":15206170,"user":{"displayName":"alphaeus dmonte","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mBDtiKl7nle2mR5kznBnErB8iv7KF-emisMAEb1=s64","userId":"12919286271022660885"}},"outputId":"72112268-b4c7-4bd0-ceb8-f0a4bc91cb41"},"source":["!opencv_traincascade -data data -vec cars.vec -bg bg.txt -numPos 1600 -numNeg 2001 -numStages 19 -w 24 -h 24 -precalcValBufSize 4096 -precalcIdxBufSize 4096"],"execution_count":null,"outputs":[{"output_type":"stream","text":["---------------------------------------------------------------------------------\n","Training parameters are pre-loaded from the parameter file in data folder!\n","Please empty this folder if you want to use a NEW set of training parameters.\n","---------------------------------------------------------------------------------\n","PARAMETERS:\n","cascadeDirName: data\n","vecFileName: cars.vec\n","bgFileName: bg.txt\n","numPos: 1600\n","numNeg: 2001\n","numStages: 19\n","precalcValBufSize[Mb] : 4096\n","precalcIdxBufSize[Mb] : 4096\n","acceptanceRatioBreakValue : -1\n","stageType: BOOST\n","featureType: HAAR\n","sampleWidth: 24\n","sampleHeight: 24\n","boostType: GAB\n","minHitRate: 0.995\n","maxFalseAlarmRate: 0.5\n","weightTrimRate: 0.95\n","maxDepth: 1\n","maxWeakCount: 100\n","mode: BASIC\n","Number of unique features given windowSize [24,24] : 162336\n","\n","Stages 0-17 are loaded\n","\n","===== TRAINING 18-stage =====\n","