Skip to main content

Posts

Showing posts from July, 2011

Artificial Intelligence (K Nearest Neighbor) in OPENCV

In pattern recognition , the k -nearest neighbor algorithm ( k -NN) is a method for classifying objects based on closest training examples in the feature space . k -NN is a type of instance-based learning , or lazy learning where the function is only approximated locally and all computation is deferred until classification. The k -nearest neighbor algorithm is amongst the simplest of all machine learning algorithms: an object is classified by a majority vote of its neighbors, with the object being assigned to the class most common amongst its k nearest neighbors ( k is a positive integer , typically small). If k = 1, then the object is simply assigned to the class of its nearest neighbor. The k -NN algorithm can also be adapted for use in estimating continuous variables. One such implementation uses an inverse distance weighted average of the k -nearest multivariate neighbors. This algorithm functions as follows: Compute Euclidean or Mahalanobis distance from target plo...

Artificial Intelligence (support vector machine (SVM)) in OPENCV

A support vector machine ( SVM ) is a concept in computer science for a set of related supervised learning methods that analyze data and recognize patterns, used for classification and regression analysis . The standard SVM takes a set of input data and predicts, for each given input, which of two possible classes the input is a member of, which makes the SVM a non- probabilistic binary linear classifier . Given a set of training examples, each marked as belonging to one of two categories, an SVM training algorithm builds a model that assigns new examples into one category or the other. An SVM model is a representation of the examples as points in space, mapped so that the examples of the separate categories are divided by a clear gap that is as wide as possible. New examples are then mapped into that same space and predicted to belong to a category based on which side of the gap they fall on. A Support Vector Machine (SVM) performs classification by constructing a...

Artificial Intelligence (Multilayered perceptrons) in OPENCV

Neural networks are models of biological neural structures. The starting point for most neural networks is a model neuron. Each input is modified by a weight , which multiplies with the input value. The neuron will combine these weighted inputs and, with reference to a threshold value and activation function, use these to determine its output. This behavior follows closely our understanding of how real neurons work.  Neural neworks are typically organized in layers. Layers are made up of a number of interconnected 'nodes' which contain an 'activation function'. Patterns are presented to the network via the 'input layer', which communicates to one or more 'hidden layers' where the actual processing is done via a system of weighted 'connections'. The hidden layers then link to an 'output layer' where the answer is output as shown in the graphic below.   Backpropagation is a common method of teaching artificial neural networks ...

OPENCV2 C++ basics (OOP) old style vs new style

Version 2.2 of the opencv library has divided its library into modules. These library modules have their own associated header files which is required therefore any code you see on the internet that looks like this: #include "cv.h" #include <cv.h> and so on is done using the old style, C or C++. However after the restructuring of the opencv library into modules, not all functionality was ported to the new style: #include <opencv2/core/core.hpp> one example of such method is the LOGPOLAR transform. Another thing to take note here is, the old deprecated IplImage is changed to the matrix cv::Mat. therefore you should avoid using such unless your using the old style. For the Log-Polar Transform i will be using this header file: #include <opencv2/imgproc/imgproc_c.h> Also to make things easy, ive created a class to convert between cv::Mat and IplImage class atsoldtonew { public:     IplImage convertOld(cv::Mat MatImage)     { ...

OPENCV2 C++ basics (OOP) edge detection using CANNY

if you have an OK background on C++ you can follow easily: ive seperated the camera capturing and the edge detection to separate classes. the main entry point remains the same. you can use the code to add a new class to process images using the atscameraCapture class. #include <iostream> #include <iomanip> #include <sstream> #include <string> #include <vector> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> //for atsEdges #include <opencv2/imgproc/imgproc.hpp> class atscameraCapture { public:     cv::Mat ats_getImage()     {         //check if Camera is still open         if (!cap.isOpened())         {             std::cout< "Cant Capture";             exit(0);     ...

build a cascade of boosted classifiers based on Haar-like features

Step 1 - Tools Needed: You can find these executables as part of the opencv default installation. they are located in the BIN folder Samples: you should have alot of positive and negative images. Take note that compressed images such as jpeg have certain issues therefore selecting a BMP image is recommended. Create folders for the Negative and Positive images and include an info file aswell Basically there should be four sets of images that you work on: - a positive sample set representing your object that you want to train - another positive sample set for testing purpose - a negative sample set (or so-called backgrounds) for training - and another negative sample set for testing, too so your 2 folders containing the images are: /opencv/project/negative /opencv/project/positive as well as the info file: -train.txt -test.txt To work with these images in the utilities, a list of the files is needed. Using Win32 as host OS, you can get the list via command promt...