This is a script to label the Scene in a Video based on the crowed density level. You can label the scene into 3 level, Empty, Half, and Full. In order to run this script we need to install OpenCV library on our system. Please follow the installation guide for your system.
We assume that you install OpenCV and are ready to run the script. In ordor to download click here. Unzip the file and navigate into SceneDensity directory.
Open the Terminal inside the SceneDensity directory, activate the virtual environment you by following command.
workon OpenCVUse the following command to run the annotation tool. You will see an instruction about how to use this tool.
python annotate.pyOpen command prompt and use the command below to run the tool.You will see an instruction about how to use this tool.
python annotate.pyOpen Terminal and use the following commands
cd ~ && mkdir OpenCV && cd OpenCV && wget https://raw.githubusercontent.com/ImOmid/SceneDensity/master/installDep.shNow, you should be inside OpenCv directory. Use the following command to install dependencies.
bash ./installDep.shPlease wait, it will take time. Afterwards, close the Terminal and open a new Terminal.
For Python 2.7 use:
mkvirtualenv OpenCV -p python2For Python 3.5 use:
mkvirtualenv OpenCV -p python3Use the following command to change your Python environment into the virtual environment you just created.
workon OpenCVpip install numpyUse the following command to change the directory to build directory.
cd ~/OpenCV/buildUse the following command to configure the build. Copy and paste it into the Terminal. Current working directory must be build.
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH=~/OpenCV/opencv_contrib-3.2.0/modules \
-D PYTHON_EXECUTABLE=~/.virtualenvs/OpenCV/bin/python \
-D BUILD_EXAMPLES=ON ../opencv-3.2.0Be sure to check the output of CMake before going to next step. You sould see an output in which cmake found the Interpreter, Libraries, numpy path for Python. The output is similar to YouTube Video on How to build and Install OpenCV 3.2 Python on Ubuntu 16.04.
makeIt can take up to 2 hours based on your Computer specifications. Be patient!
If the compile finished without any error go to next step. Otherwise, use the following command to clean and make again.
make clean && makeUse the below commands to install OpenCV
sudo make install
sudo ldconfigUse the folllowing commands to build a symbolic link for OpenCV cv2.so.
For Python 2.7:
cd ~/.virtualenvs/OpenCV/lib/python2.7/site-packages/
ln -s /usr/local/lib/python2.7/site-packages/cv2.so cv2.soFor Python 3.5:
cd /usr/local/lib/python3.5/site-packages/
sudo mv cv2.cpython-35m-x86_64-linux-gnu.so cv2.so # Rename the file
cd ~/.virtualenvs/cv/lib/python3.5/site-packages/
ln -s /usr/local/lib/python3.5/site-packages/cv2.so cv2.soIf all the previous steps are done successfully. You should be able to import OpenCV in your virtual environment. Use the following commands to verify it.
cd ~
workon OpenCV
pythonimport cv2
cv2.__version__The output should be '3.2.0'
- Download and install Visual Studio and CMake.
1.1. Visual Studio 2012
1.2. CMake
- Download and install necessary Python, and Numpy to their default locations.
2.1. Python 2.7.x
2.1. Numpy
Download OpenCV
Download OpenCV_contrib
Extract both zip files into:
C:\OpenCV\sources\and create a build directory in:
C:\OpenCV\Run CMake as administrator
Where is the source code:
C:\OOpenCV\sources\opencv-masterWhere to build the binaries
C:\OpenCV\buildC:\Program Files (x86)\Microsoft Visual Studio 11.0\Vc\bin\cl.exeLook for OPENCV_EXTRA_MODULES_PATH and set it as follows.
C:\OpenCV\sources\opencv_contrib-master\modulesThen click Configure and wait until it is done.
Click Generate and wait for it to finish. When it is done close CMake.
- Got to:
C:\OpenCV\build\directory and run "OpenCV.sln" with Visual Studio.
-
Change the Debug mode to Release mode (you'll find it the middle of toolbar). Wait for the projects to get ready. Check if it is written Ready in the bottom left corner of the Visual Studio window.
-
When the projects are ready, Right Click on All_BUILD and select Build (you'll find in the solution explorer on the right of Visual Studio). It will take a while, wait until it finishes.
-
Right Click on INSTALL (right under ALL_BUILD) and select Build. When it finishes close the Visual Studio.
C:\OpenCV\sources\build\Releaseinto:
C:\Python27\Lib\site-packages\If there is a file with the same name replace it.
Copy all the dll files from:
C:\OpenCV\sources\build\Releaseinto:
C:\Python27\-
Right Click on My Computer and select properties.
-
Go to Advanced system settings (on top left corner) and select Environment Variables (on Advanced tab and at the bottom), and click on Path from the System variables section and click Edit.
-
Add all the following pathes by each time clicking on New
C:\Python27
C:\Python27\Lib\site-packages
C:\Python\Scripts
C:\OpenCV\build\lib\Release
C:\OpenCV\build\install\x86\vc11\bin
C:\OpenCV\build\install\x86\vc11\lib- Click OK on all setting windows you have opened.
Open Command prompt and run the following commands.
- Run python
python- Python interpreter must be run. To check if you installed OpenCV successfully import cv2 and check its version by following commands in Python interpreter.
import cv2
cv2.__version__You should see '3.2.0'
You can watch the Video Tutorial on How to build and Install OpenCV 3.2 from source for Python on Windows 10