Skip to main content

Posts

Showing posts from 2011

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         ///works with VS2010 and OpenCV 2.2+         void FindBlobs(const cv::Mat &binary, vector < vector<cv::Point>  > &blobs)         {             blobs.clear();             // Fill the la

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));             giniIndex += Hc*Hc;         }         frequency = getFrequencyOfBin(b);         for( int i = 1; i < histSize; i++ )         {             float Hc = abs(getHistogramBinValue(b,i));             giniIndex += Hc*Hc;         }         giniIndex = 1 - (giniIndex);         //cout << giniIndex <<endl;         return giniIndex;     }

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)     {         /// Separate the image in 3 places ( R, G and B )    

Opencv 2.3.1 Installation

alright it took me a while before posting this. for OPENCV 2.3.1 and Visual studio 2010 Professional on a windows 7 64 bit environment Download The "super pack" and unzip to "C:\OPENCV" it seems you can only get the source of opencv and need to compile it with CMAKE. very straight forward. download CMAKE and use the command prompt to enter CMAKE CMAKELIST.txt at the opencv directory Open  "ALL_BUILD" by double clicking - opens up visual studio Compile it and wait. (took a minute) go to properties and select the release version and compile again (took another minute) your all set with the opencv installation "c:\opencv\build" create an empty visual studio "win32 console application" Click on Configuration Properties->VC++ Directories, and edit the Include Directories. Add: C:\opencv\build\common\tbb30_20110427oss\include (UPDATE) C:\opencv\build\include Click on Configuration Properties->VC++ Directories, and

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 the gray scale or wont work         cv::cvtColor(src,img,CV_BGR

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 ),                \             Point( center.x + d, center.y + d ), color, 2, CV_AA, 0); \             line( img, Point( center.x + d, center.y - d ),                \             Point( center.x - d, center.y + d ), color, 2, CV_AA, 0 )             cv::Point center;             //given 2 points representing the rectangle             cv::Point topLeft(100,100);             cv::Point bottomRight(200,200);             cv::rectangle(imgs,topLeft,bottom

2D/3D estimation using solvePnP in opencv (NOT SOLVED)

In opencv "solvePnP" is used to find known points on a known 3D object. doing so the objects orientation relative to the camera coordinate system can be found. the function is equivalent to finding the extrinsic camera parameters. which makes me believe its more for planar objects. need to do a few more experiments to find out why. im using code from: http://www.morethantechnical.com/2010/03/19/quick-and-easy-head-pose-estimation-with-opencv-w-code/    #include <opencv2/core/core.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/calib3d/calib3d.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> #include <string> using namespace cv; #include <vector> using namespace std; #include <GL/gl.h> #include <GL/glu.h> #include <glut.h> void loadNext(); void loadWithPoints(Mat& ip, Mat& img); const GLfloat light_ambient[]  = { 0.0f, 0.0f, 0.0f, 1.0f }; const GLfloat light_diffuse[]  =