This is the first part of the People Counter tutorial. We´ll look into setting up our environment so we can start coding.
First of all, I’ll be using Windows. I’m doing it this way since I don’t have Linux installed right now on my personal computer but if you wan´t to use other OS it’s fine. You just need to make sure the required tools are installed. The code we write will work in many OS’s with minor modifications. I’ve run this code on my Windows computer, on a Ubuntu Virtual Machine and on my Raspberry Pi B, so don’t worry.
Let’s start! You’ll need to download the following programs:
- Python 2.7 (lastest version, as of writing, is 2.7.11). Install the 64bit version.
- OpenCV 3.xx (latest version as of writing is 3.1).
- Pip (get-pip.py)
- numpy. Be sure to download the 64bit version.
Now let’s install the software:
- Install Python 2.7 (64bit version) on the default location “C:\Python27”. Make sure to check the “Add python.exe to Path” option.
- Run the openCV executable and extract to “C:\”, where a folder named “opencv” will be created.
- Navigate to “C:\opencv\build\python\2.7\x64” and copy the “cv2.pyd” file.
- Navigate to “C:\Python27\Lib\site-packages” and paste the file.
- Using CMD navigate to where you downloaded pip and run the following command “python get-pip.py“.
- The install numpy with the following command “pip install “numpy-1.10.4+mkl-cp27-cp27m-win_amd64.whl”“. The name of your numpy WHL file may vary. You may also need to disable your antivirus software in order for pip to install the package.
And that’s it! We’re set up to start coding the people counter but before that, let’s run an example code to see if everything’s running smooth.
- Download the following image to a directory of your choice.
- Open IDLE, the python editor installed by default.
- Open a New file (CTRL+N), and save it in the same directory as the image with the name “helloWorld.py”.
- Add the following code:
- The run it with F5 in IDLE or with “python helloWorld.py” in CMD.
- Three windows are show (exit pressing ‘Q’ or ESC key). Also look at the directory in which you ran the code, two new images are created.
This is the end of the first chapter. In the next one we’ll look into opening a video stream, from a video file or a webcam, and do some operations on it.
If you have any questions, suggestions, complaints, etc. , be sure to leave them on the comment section. 🙂