Skip to main content

Posts

Showing posts with the label opencv

Blob Detection, Connected Component (Pure Opencv)

Connected-component labeling (alternatively connected-component analysis, blob extraction, region labeling, blob discovery, or region extraction) is an algorithmic application of graph theory, where subsets of connected components are uniquely labeled based on a given heuristic. Connected-component labeling is not to be confused with segmentation. i got the initial code from this URL: http://nghiaho.com/?p=1102 However the code did not compile with my setup of OpenCV 2.2, im guessing it was an older version. so a refactored and corrected the errors to come up with this Class class atsBlobFinder     {     public:         atsBlobFinder()         {         }         ///Original Code by http://nghiaho.com/?p=1102         ///Changed and added commments. Removed Errors     ...

Computing Gini Index of an image (measure of Impurity)

Using my previous posts Class file and this reference: http://people.revoledu.com/kardi/tutorial/DecisionTree/how-to-measure-impurity.htm float computeGiniIndex(Mat r, Mat g, Mat b)     {         float giniIndex = 0.0;         float frequency = getFrequencyOfBin(r);         for( int i = 1; i < histSize; i++ )         {             float Hc = abs(getHistogramBinValue(r,i));             giniIndex += Hc*Hc;         }         frequency = getFrequencyOfBin(g);         for( int i = 1; i < histSize; i++ )         {             float Hc = abs(getHistogramBinValue(g,i));  ...

Computing Entropy of an image (CORRECTED)

entropy is a measure of the uncertainty associated with a random variable. basically i want to get a single value representing the entropy of an image. 1. Assign 255 bins for the range of values between 0-255 2. separate the image into its 3 channels 3. compute histogram for each channel 4. normalize all 3 channels unifirmely 5. for each channel get the bin value (Hc) and use its absolute value (negative log is infinity) 6. compute Hc*log10(Hc) 7. add to entropy and continue with 5 until a single value converges 5. get the frequency of each channel - add all the values of the bin 6. for each bin get a probability - if bin 1 = 20 bin 2 = 30 then frequency is 50 and probability is 20/50 and 30/50 then compute using shannon formula  REFERENCE: http://people.revoledu.com/kardi/tutorial/DecisionTree/how-to-measure-impurity.htm class atsHistogram { public:     cv::Mat DrawHistogram(Mat src)     {      ...

Blobs with opencv (internal function)

There are many open source opencv BLOB libraries that you can use. i have tried several of these, however because of the 64 bit machine that im using recompiling these are very troublesome. If you have heard of these libraries: "cvBlobsLib": http://opencv.willowgarage.com/wiki/cvBlobsLib   "cvBlob": http://code.google.com/p/cvblob/   "Bloblib" by Dave Grossman (also referred to as "Blob Analysis Package"): Go to http://tech.groups.yahoo.com/group/OpenCV/files/  You will know that opencv also has a built in function that can help you find blobs using cv::findContour and see some statistics using the cv::moments. eventually make these functions similar to regionprops Matlab function The BLOB FINDER CLASS: class atsBlobFinder { public:     atsBlobFinder(cv::Mat src)     {         numBlobs = 0;         cv::Mat img; //must create a temporary Matrix to hold...

finding the center of gravity in opencv

Alot of feature detectors such as the Haar classifier will return rectangular shapes presented as a detected feature. one of the things to do in order to track these, is to find the center of the rectangle.   int main( int argc, char** argv ) { atscameraCapture movie; char code = (char)-1; for(;;)         {             //get camera             cv::Mat imgs = movie.ats_getImage(); #define drawCross( center, color, d, img )                                 \             line( img, Point( center.x - d, center.y - d ),                \       ...

Opencv with OpenGL (installation and trials)

so i needed to install opengl for a 2D/3D test using opencv since Opengl libraries come preinstalled just needed to download GLUT from: http://www.xmission.com/~nate/glut.html since im running on a 64bit machine i need to place the GLUT32.dll in the C:\Windows\SysWOW64 instead of C:\Windows\System32 i then place the GLUT.h in the: C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include and the GLUT32.lib in the C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib in the visual studio dependencies i just add the following: opengl32.lib glut32.lib glu32.lib and im all set and good to go with the test program /**********************************   Simple.cpp   A simple GLUT program. ****************************************************************************/ #include <string.h> #include <glut.h> void mydisplay( void ) {     glClearColor (0.0, 0.0, 0.0, 0.0);     glClear(GL_COLOR_BUFFER...

Histogram computation on a video

Histograms are collected counts of data organized into a set of predefined bins   refracted class for histogram: given an input image, output the histogram image class atsHistogram { public:     cv::Mat DrawHistogram(Mat src)     {         /// Separate the image in 3 places ( R, G and B )          vector<Mat> rgb_planes;          split( src, rgb_planes );          /// Establish the number of bins          int histSize = 255;          /// Set the ranges ( for R,G,B) )          float range[] = { 0, 255 } ;          const float* histRange = { range };          bool uniform = true; bool accumulate = false;   ...

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...