All posts by alex

cv workbench

what is it?

Its main purpose is to help with the computer vision software design, developement and testing. By using a graphical diagram editor that defines analysis flow, different algorithm combinations can be tried, with different parameters, very quickly and with no coding.

Software is not in production state, although it is functional. Hopefully, I will continue developing it as I get time to do it.

Application is divided in two parts, the diagram editor and the diagram runner. Use diagram editor to edit diagrams, and runner to execute them.
The diagram editor, by now, is only available for windows (as it is written using c# and wcf), but hopefully, in near future, a javascript version would be available.
The runner is developed using c++ multi-platform libraries and should run in linux, windows and mac.

See an example:

how to run

The diagram editor is like others editors. You can drop boxes that enclose algorithms from toolbox to diagram canvas, and then connect their outputs (at the right) from one box to another box inputs (at the left). When finished, a file can be saved. This file is an XML representation of the diagram wwhich can be run with runner. At the bottom left corner a property window is displayed with the parameters of each box. Remember that any diagram must contain one box of type DummyBox which must be called “start_box”, which is where runner will send frames from input.

The runner is a command line application that can be run from a terminal application. It has three kind of inputs (vnc, camera and pictures) which will be connected to diagram startup box. For each type of input different parameters could be necessary (for example, ip and port for vnc, or device index for camera). Command line syntax is as follows:

1
2
3
4
./chain run vnc <diagram_file> <vnc parameters>
./chain run camera <diagram_file> <camera_device_number> (where 0 is default)
./chain run pics <diagram_file>  <directory_with_images> <secs_between_images>
./chain save_box_config <boxes_configuration_file>

When a diagram is run, a monitor window could be presented showing input frames. Several intermediate or output windows could be also showed depending on the diagram, one for each WindowBox. To stop it, you can press Esc over any window (or simply Ctrl-c in the command line terminal).

Some basic boxes are:

BoxConvertColorSpace converts an image from one color type to another. for example BGR to GRAY. Parameter is an integer for the type of conversion (see cvtColor)
BoxMask makes a copy of input on output but masking it using the mask
BoxTee connects the input to 4 outputs
DummyBox it’s the starting box. Must be called “start_box”
DummyBox Displays input in a window
BoxThread Runs all the tree conected to its output in a different thread. (be careful!)
BoxDrawContours Makes a copy of input image to output and draws contours onto it.

Some algorithms are:

BoxWatershedSegmenter Watershed segmentation algorithm
BoxMedianBlur Median blur
ksize – aperture linear size; it must be odd and greater than 1, for example: 3, 5, 7
BoxGraphSegmentation Graph segmentation algorithm
sigma – see http://cs.brown.edu/~pff/papers/seg-ijcv.pdf
min_area – min pixels for a segment to be detected
threshold – see http://cs.brown.edu/~pff/papers/seg-ijcv.pdf
BoxCanny Canny segmentation algorithm
BoxBackgroudSegm Background segmentation algorithms

how to compile

Cmake files are available to compile on linux and windows.

Prerequisites are:
boost (http://www.boost.org/)
opencv (http://opencv.org/)
bgslibrary for background segmentation (https://github.com/andrewssobral/bgslibrary)
graph segmentation code from Pedro F. Felzenszwalb and Daniel P. Huttenlocher (http://cs.brown.edu/~pff/segment/)
pugixml (http://pugixml.org/)
(most of them are included in source tree)

compile in linux

1
2
3
4
$ mkdir -p build/debug
$ cd build/debug/
$ cmake ../.. -DCMAKE_BUILD_TYPE=Debug
$ make

other examples

download

Download code from here.

httptunnel

What is it

It creates tunnels using http protocol. It is useful to bypass restrictive firewalls or proxies. It uses two techniques, the well known CONNECT technique as well as a BOSH-like implementation. It bypass most firewalls (as requests are valid HTTP requests)  and proxies in their most secure configurations.

How to run

To create a tunnel a user can run httptunnel_server at server where tunnelized service is started and httptunnel_client where the client of the service is used. The client must connect to port where httptunnel_client is started in order to use a tunnelized connection.

1
httptunnel_client -port <local_port> -http_host <http_host> -http_port <http_port> [-proxy_host <proxy_host> -proxy_port <proxy_port>] [-proxy_user  <proxy_user> -proxy_pass <proxy_pass>]

port: where the httptunnel client will listen for tunnelled connections
http_host: the hostname or ip where httptunnel_tunnel is running
http_port: the port where httptunnel_tunnel is running
proxy_host: the proxy host in case of necessary
proxy_port: the proxy port in case of necessary
proxy_user:  the proxy username in case of proxy authentication
proxy_pass: the proxy password in case of proxy authentication

1
httptunnel_server -http_port <http_port> -client_port <client_port> -client_host <client_host>

http_port: the port where httptunnel_server listens
client_port: the port where destination service is bound
client_host: the hostname or ip where destination service is running

Example: Tunnel a ssh connection

Configuration at host (server.com):

1
httptunnel_server -http_port 80 -client_port 22 -client_host 127.0.0.1

Configuration at client:

1
httptunnel_client -port 22 -http_host server.com -http_port 80 -proxy_host proxy.mynet.com -proxy_port 3128

– to start a ssh connection will run at client:

1
ssh 127.0.0.1

which will start a tunneled ssh connection at server.com

Build

At this moment only windows compile system is provided (VS2008) but linux/unix
compile system will be available soon.

Windows

A solution ‘httptunnel.sln’ is provided.
Portable Components C++ library is a prerequisite.
It must be installed at same directory where httptunel is located in and it must be named as ‘poco’.
|
+ – httptunnel
+ – poco

Download

http://diggertunnel.sourceforge.net/

bashttp mini web server

 

What is it

It’s a micro web server that features php and web service extension

Build

Dependencies: Poco c++ libraries

For linux:

1
2
3
4
5
~/bashttp $ rm -rf build/
~/bashttp $ mkdir -p build/debug
~/bashttp $ cd build/debug/
~/bashttp $ cmake ../.. -DCMAKE_BUILD_TYPE=Debug
~/bashttp $ make

For windows use cmake-gui from http://www.cmake.org/.

How to run

To run it

1
2
~/bashttp $ bashttp 8888 doc_root
bashttp listening on 127.0.0.1:8888

Where 8888 is the port and ‘doc_root’ is the document root directory

To stop it simply press ctr+c

Configuration and test files

miniwebserver-files

doc_root: document root directory

doc_root/index.html: html test page

doc_root/index.php: php test page

mime.conf: mime configuration. Must be in execution directory.

/etc/alternatives/php-cgi: php binary for linux

php.cgi.exe: php binary for windows. Must be in execution directory.

😈 Execute shell from browser 😈

Screenshot from 2014-04-19 07:08:56

Write a new web service

Example of service that would be called as ‘http://server/newservice’:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class NewService : public MiniWebService
{
public:
    virtual void exec(const Poco::Net::HTTPServerRequest& request,
                        std::map<std::string, std::string> &query,
                        Poco::Net::HTTPServerResponse& response,
                        Poco::Net::StreamSocket& sock,
                        Poco::Net::HTTPServerSession& session)
    {
        std::ostream& ostr = response.send();
        ostr << "it works.";
        ostr.flush();
    }

    static std::string name() { return "newservice"; }
};

Where:

  • name() method returns the web service identifier as seen in url
  • exec(…) implements the web service.

Add it to server before start it

1
2
std::shared_ptr svc(new NewService());
server.addService(NewService::name(), svc);

Download

download here.

Cmake sample

Minimum cmake sample. It will create an executable for sample.cpp.

Windows

Download cmake-gui from http://www.cmake.org/. Execute using path as follows

cmake-win2

Configure and Generate.Choose build chain (compiler, linker …). Remeber that Visual Studio 11 means Visual Studio 2012. It will create solution and project files in build directory. Open and use it.

Linux

cd to the directory and

1
2
3
$ cd build/
$ cmake ..
$ make

Also ccmake can be used to configure options and debug and release configurations (remember to use first char with upper case e.g. Debug)

The CMake files

The one at main dir

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
cmake_minimum_required(VERSION 2.8)

set(BINARY_NAME "sample")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

#link static
set(BUILD_SHARED_LIBS OFF)


set(CMAKE_CXX_FLAGS_DEBUG "-D_DEBUG ${CMAKE_CXX_FLAGS_DEBUG}")
if(WIN32)
    #windows linker settings
else(WIN32)
    #linux linker settings
    set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ ${CMAKE_EXE_LINKER_FLAGS}")
endif(WIN32)

if(CMAKE_COMPILER_IS_GNUCC)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --std=c++0x -funsigned-char -frounding-math -fsignaling-nans -ffloat-store -mfpmath=sse -msse2 -fmessage-length=0 -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter -Wno-comment")
endif(CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++0x -funsigned-char -frounding-math -fsignaling-nans -ffloat-store -mfpmath=sse -msse2 -fmessage-length=0 -Wall -Wextra -Wno-unknown-pragmas -Wno-unused-variable -Wno-unused-parameter -Wno-comment")
endif(CMAKE_COMPILER_IS_GNUCXX)

if(WIN32)
    #windows include dirs
else(WIN32)
    #linux include dirs
    include_directories(SYSTEM /usr/local/include)
endif(WIN32)

add_subdirectory(src)

The other at src

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
set(PART_NAME ${BINARY_NAME})

set(${PART_NAME}_SRC
    #sources here
    sample.cpp
)

include_directories(${PROJECT_SOURCE_DIR})
add_executable(${PART_NAME} ${${PART_NAME}_SRC})

if(WIN32)
    target_link_libraries(${PART_NAME}
    #   windows libraries
    )
else(WIN32)
    target_link_libraries(${PART_NAME}
    #   linux libraries
    )
endif(WIN32)


install(TARGETS ${PART_NAME} RUNTIME DESTINATION usr/bin)

The files

cmake-sample-files-ls
download here cmake-template.zip