Posts

Showing posts from October, 2015

Finding permutations in strings

Image
In C++ the Standard Template Library provides us with std::next_permutation to easily implement this. [code language="cpp"] #include <iostream> #include <algorithm> #include <iterator> #include <string.h> int main() { char str[] = "abcd"; const size_t len = strlen( str ); do { std::copy( str, str + len, std::ostream_iterator<char>( std::cout ) ); std::cout << std::endl; } while ( std::next_permutation( str, str + len ) ); return 0; } [/code]

Using OpenCV to find and draw contours in video

Image
This is a very similar post to that posted previously, which used a OpenCV and cvBlobsLib to identify contours in video footage and display them on the screen. Please refer to this for detail on how to convert the Red, Green, Blue (RGB) format into Hue, Saturation, Value (HSV) format, and threshold the HSV into the black and white format needed for finding contours in OpenCV: https://www.technical-recipes.com/2011/track-colored-objects-in-video-using-opencv-and-cvblobslib/ This example achieves the same but without using the cvBlobsLib to identify contours / strongly connected components, just 100% OpenCV calls.

Configuring NetBeans to use OpenCV in Linux Environments

Image
A quick guide to setting up and installing OpenCV for using in the Netbeans integrated development environment in Linux. Step 1: Download and extract OpenCV for Linux Versions of OpenCV can be downloaded from here: http://opencv.org/downloads.html Save it to the location of your choice. Open a command prompt, navigate to the download location and unzip:

Graph Traversals in C++ and C#

Image
Breadth First Search From WikiPedia : "Breadth-first search (BFS) is an algorithm for traversing or searching tree or graph data structures. It starts at the tree root (or some arbitrary node of a graph, sometimes referred to as a 'search key') and explores the neighbor nodes first, before moving to the next level neighbors" I have borrowed heavily the C++ code listing used at the 'Geeks for geeks' website and made a few modifications of my own, such as using smart pointers. I have also produced C# equivalents of the code. For reference the website is here: http://www.geeksforgeeks.org/breadth-first-traversal-for-a-graph/ Full C++/C# code listings: [tabs] [tab title="C++"] [code language="cpp"] #include <iostream> #include <list> #include <memory> class Graph { int _V; bool _directed; std::unique_ptr< std::list<int> > adj; public: Graph(int V, bool directed); ...

Implementation of the Simplex algorithm in Visual C++

Image
An excellent implementation of the Simplex algorithm exists over at Google Code, written by Tommaso Urli: https://code.google.com/p/cpplex/ Implemented as class library, it relies on no other dependencies other than the C++ Standard Library. I've taken this implementation and compiled it as a Visual Studio application. The only slight modification I needed was to insert: [code language="cpp"]#include <algorithm>[/code] into matrix.cpp then it compiled std::max just fine.

How to configure FLTK in NetBeans in Linux

Image
Some instructions and screenshots to help you get up and running using the Fast Light Toolkit (FLTK) within the NetBeans development environment in Linux. For configuring FLTK in Visual Studio environments please refer to this post . Go to the FLTK website and download the latest source: http://www.fltk.org

Fixing compiler problems when using smart pointers in NetBeans

Image
I like using NetBeans for C++ development within Linux environments. Sometimes a gotcha can occur when trying to use the following declaration: [code language="cpp"]#include <memory>[/code] You may wish use this in order to utilize smart pointers such as std::unique_ptr , leaving the user with a compilation error such as this: error: ‘unique_ptr’ in namespace ‘std’ does not name a template type It's easy enough to overcome. Just make sure the appropriate compiler flag is set in NetBeans. In NetBeans right-click your project and select Properties. Then select Additional Options field in Build > C++ Compiler:

Determining if paths are Hamiltonian in C++

Image
A Hamiltonian path in a graph is a path whereby each node is visited exactly once. A number of graph-related problems require determining if the interconnections between its edges and vertices form a proper Hamiltonian tour, such as traveling salesperson type problems. Such a problem is NP-Complete, that is, the effort required to solve the problem increases dramatically as the size of the problem grows. This C++ implementation borrows heavily from the ideas and algorithms used in the following article: http://www.geeksforgeeks.org/backtracking-set-7-hamiltonian-cycle/