I’m working with python 2.7 and opencv 3.1 I want to run a code for tracking objects by this:
import cv2
import sys
if __name__ == \'__main__\' :
# Set
Once Installation is over. All files are installed in
/usr/local/ folder.
But to use it, your Python should be able to find
OpenCV module.
You have two options for that.
Move the module to any folder in Python Path: Python path can be found out by entering import sys;print sys.path in Python terminal. It will print out many locations. Move /usr/local/lib/python2.7/site-packages/cv2.so to any of this folder. For example, su mv /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/ → site-packages. But you will have to do this every time you install OpenCV.
Add /usr/local/lib/python2.7/site-packages to the PYTHON_PATH: It is to be done only once. Just open ~/.bashrc and add following line to it, then log out and come back. export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages. Thus OpenCV installation is finished. Open a terminal and try
import cv2.