# Category Archives: Computer Vision

## Configure OpenCV-Python development environment in Windows

In older days, it is relative complex to configure a OpenCV development environment. You have to install an IDE, e.g. Mircosoft Visual Studio, and have to set many configurations of the project, such as the include folder, the header folder and where the IDE can find the third-party OpenCV library. But after Python becomes one of the main streams, things has changed. Python has proven to be a better and easier way to program and test computer vision programs, compared with C++. In this article, I will show you the simple steps that could help you to configure an OpenCV-Python ready environment in Windows.

1. First, you have to download and install Python 2.7 and Numpy. Install them to their default locations, in order to avoid any further issues. The reason to use Python 2.7 instead of Python 3.x is that Python 2.7 is best supported by most third-party libraries, while Python 3 is too new for all the scientific libraries to be fully supported.

2. Download the latest OpenCV release from Sourceforge and extract it into a system folder, e.g., C:\Program Files\opencv.

3. Goto $(opencv folder)\build\python\2.7\x86 or \x64 based on your machine type. Copy cv2.pyd to$(python folder)\lib\site-packages.

That’s all you have to do. Really easy and will only cost you 10 minutes. Now let’s open the Python IDLE and test if the environment is working:

import numpy
import cv2

print cv2.__version__


Run the code and if you got the version printed and no error message, then congratulations: you have succeed. But if you did get error message, then you should check the version of both the Python and the OpenCV is correct. If you have multiple versions of Python, then check if you have run the right version of IDLE.

Before we try more complicated vision algorithms, let’s simply connect a USB camera first and try to get the video stream from the camera and display it on the screen:

import cv2

cap = cv2.VideoCapture(0)

while(True):
cv2.imshow('camera', frameInput)

if cv2.waitKey(33) == 27:
break

cv2.destroyAllWindows()
cap.release()


What you should got is a pop-up window displaying the current image captured from the camera. You don’t have to understand this code at the moment, but the thing is once you got the live video stream from the USB camera, further steps can be done to process, modify and save it. More details and examples will be discussed later in my further blogs.

References
[1] OpenCV-Python Tutorials, Install OpenCV-Python in Windows, available at: http://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_setup/py_setup_in_windows/py_setup_in_windows.html

## AR.Drone Position Servoing and Visual Tracking

A demonstration of my Master’s Thesis: Visual-Based Localization and Tracking of a UGV with a Quadcopter. In this project, a visual tracking framework is designed to track the UGV with an AR.Drone quadcopter from Parrot. The system utilizes a centralized control by a ground station which is running ROS and Ubuntu 12.04 LTS.

The first two experiments were taken with the support of a global vision system which was designed using a low cost web camera. While in the last experiment, the quadcopter simply uses IMU data for navigation. The image was captured from the bottom camera of the AR.Drone and processed with OpenCV. Four PID controllers were designed to control the motion of the quadcopter to make it hold at a position or track a trajectory.

The next step is to use such a robot system for factory and infrastructure inspection. But since I have to return my quadcopter to the department, it is really problematic for me to imply this idea. Hope I can find the chance to get another AR.Drone soon.

（国内用户请访问优酷：http://v.youku.com/v_show/id_XNzczOTg0MDY0.html