Howto Stream Video Over Network Using OpenCV

I am currently doing one project about Mobile Robot Teleoperation, so stream video over network is one of my part. Actually there are many different approaches, but I chose OpenCV as my main approach because of its advantages in term of Computer Vision. But the crazy thing I have to do is making 2 server and client programs which run in Windows and Linux, respectively. Ok, now let’s go together:
[smartads]

Install OpenCV

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision.

  • OpenCV is released under a BSD license, it is free for both academic and commercial use.
  • The library has >500 optimized algorithms (see figure below). It is used around the world, has >2M downloads and >40K people in the user group. Uses range from interactive art, to mine inspection, stitching maps on the web on through advanced robotics.

For more information, go to OpenCV Wiki. It is not difficult to build OpenCV in Linux, just base on Install Guide but make sure that install all Prerequisites: Python, Intel TBB, …

In Windows counterpart, I can easily build OpenCV using Microsoft Studio, but I am using program which has multi-thread (POSIX) feature, so I can’t use this library for that. So I prefer to build OpenCV using Cygwin, but I didn’t get success yet :d. So what I have done with that ?

And don’t forget to install Cygwin and needed packages like gcc, make, cmake, … before that :)

Program

This post describes very well about what do you have to do with OpenCV and socket programming. Thank Nashruddin for great effort. But I would like to contribute some things here: cmake list and delay function.

I really love Cmake so much, it is very handy and powerful tool for cross platform applications. If you don’t know what is Cmake, have a look at http://cmake.org/, you will love it for sure.

In the folder which has your source code, just create a file named CMakeLists.txt. For the server part it will be:

project(MobileApp)
cmake_minimum_required(VERSION 2.6)
# Find OpenCV package
FIND_PACKAGE(OpenCV REQUIRED)
# Vision program
add_executable(stream_server stream_server.c)
target_link_libraries(stream_server ${OpenCV_LIBS})

REQUIRED
For the client counterpart:

project(MobileApp)
cmake_minimum_required(VERSION 2.6)
# Find OpenCV package
FIND_PACKAGE(OpenCV REQUIRED)
# Vision program
add_executable(stream_client stream_client.c)
target_link_libraries(stream_client ${OpenCV_LIBS})

To build the application, follow these steps:

$ mkdir build
$ cd build
$ cmake ..
$ make

cmake will automatically generate your Makefile based on your system configuration, so whenever you move it to other computer or other platform it will check again.

Note: there is one issue that cmake couldn’t understand the parameter OpenCV_LIBS even thought it can detect OpenCV libs, so you need to add OpenCV libs by using other variable OpenCV_DIR.So you need to change ${OpenCV_LIBS} to ${OpenCV_DIR}/libs. Have a look at FindOpenCV.cmake

{ 3 comments… add one }

  • PHT August 6, 2010, 11:49 am

    Hi,
    Currently, I am also doing a project related to Mobile Robot, seem to be the same as yours.
    The hardware of robot is going to finish soon and i am programming for a wireless control. A laptop with a webcam is attached on Robot, transfer Image data (via Wifi) back to other laptop and i do some image processing on this laptop to control mobile robot. I’ve been programming just like your post above and followed Nashruddin’s code. But i have two problems and really want your help:
    – My program have some errors: Cannot open include file: ‘pthread.h’, , … I am using VC2008 and OpenCV2.1 on Window system >> How can I fix these errors?.. It seems that I have to install BSD and …multi-thread???
    – The second problem is about data of image. Because, at the cilent side, i use CAMSHIFT for processing Image to track object so i need color-image. >> Multi-chanel Image can be stream? How to do that?
    Any help will be greatly appreciate!!!
    Thanks in advance!

    Reply
  • PTH August 9, 2010, 10:57 am

    where’s my last post?

    Reply
  • subhendu August 18, 2013, 6:49 pm

    The site of Nashuruddin is not working. Can you please mail me the full source code. please

    Reply

Leave a Comment