This post is all about the red Blob Detection from a Video.This is the post you should be looking on if you are here for blob Detection.Here the method which I have used is the Color Space conversion and then the detection using some more functions.So if you are looking for Color recognition then youre at the right place… (more…)
December 20, 2008
June 14, 2009
Image Enhancement Using HSV Color Space
So, How to make sure that we detect Colors Correctly….? Suppose you have an image in which the Colors are not so Strong.So, it would be quite difficult for us to detect Colored objects.Adding some arbitrary value in the Image would not Help since it would increase the brightness but not the Contrast. So How to do it… (more…)
June 13, 2009
Pixel Operation based Edge Detection
Dear Friends,
One day a thought popped up in my mind.What is an edge really..? many times it is a sudden change of color or almost always.In the camera frame one object overlaying on another object which happens with a color change. Which Meant that if there was a sudden change in the Net pixel RGB values which meant there is an edge.
By a sudden change I mean a change of atleast 5 units(depends on the scene again).
SO i thought I should Implement It.
So I have Implemented a successful way in which we can detect an edge.
Let us take a variable called “diff”.If we assign a value to this “diff” variable then the next pixel should atleast differ by that value “diff” the either way…which means the current pixel should be either 10 more or 10 less than the next pixel then the pixel is selected to be white(diff=10 in this case).
In this way I have an algo in front of me which I have Implemented.
THe Image is

3d-09-5balls
/*ALL the necessary header files*/
#include"math.h"
#include"conio.h"
#include"cv.h"
#include"highgui.h"
#include"stdio.h"
int main()
{
int i,j,k;
int temp1,temp2,temp3;//Temp variables
int height,width,step,channels;
int stepr, channelsr;
int temp=0;
uchar *data,*datar;
i=j=k=0;
IplImage *frame=cvLoadImage("3d-09-5balls.jpg",1);
IplImage *result=cvCreateImage( cvGetSize(frame), 8, 1 );
if(frame==NULL ) {
puts("unable to load the frame");exit(0);}
int diff=0;
printf("What do you want the Difference in the pixels to be..? ");
scanf("%d",&diff);
height = frame->height;
width = frame->width;
step =frame->widthStep;
channels = frame->nChannels;
data = (uchar *)frame->imageData;
cvNamedWindow("original",CV_WINDOW_AUTOSIZE);
cvNamedWindow("Result",CV_WINDOW_AUTOSIZE);
/*Here I use the Suffix r to diffenrentiate the result data and the frame data
Example :stepr denotes widthStep of the result IplImage and step is for frame IplImage*/
stepr=result->widthStep;
channelsr=result->nChannels;
datar = (uchar *)result->imageData;
for(i=0;i< (height-1);i++)
{
for(j=0;j<(width-1);j++)
{/*width-1 and height-1 to ovoid memory overleak*/
temp1=data[i*step+j*channels];/*Blue pix assigned to temp and same below*/
temp2=data[i*step+j*channels+1];/**/
temp3=data[i*step+j*channels+2];
if((temp1>(data[(i+1)*step+(j+1)*channels]+diff) ||(temp1)< data[(i+1)*step+(j+1)*channels]-diff )
//temp1 compared with the next pixel "(i+1)" and "(j+1)" means next pixel
&&( temp2>data[(i+1)*step+(j+1)*channels+1]+diff || temp2< data[(i+1)*step+(j+1)*channels+1]-diff)
//same as above here.comparing with the second channel and third channel.
&& (temp3>data[(i+1)*step+(j+1)*channels+2]+diff || temp3<data [(i+1)*step+(j+1)*channels+2]-diff)){
datar[(i)*stepr+(j)*channelsr]=255;// "&&" above because There should be difference in
//individually in all the channels."||" because when we compare 2 values one might be
//more or less than the other but not both
}
else datar[(i)*stepr+(j)*channelsr]=0;}}
/*If loop explanation
First taking the first channel and checking
If you want to use cvErode you may...*/
/*Destroying all the Windows*/
cvShowImage("original",frame);
cvShowImage("Result",result);
cvSaveImage("resultedges.jpg",result);
cvWaitKey(0);
cvDestroyWindow("original");
cvDestroyWindow("Result");
return 0;
}
Result would be this Image.depending on the value of difference.

So , try to see the changes by using some large or small values of Difference and play in Computer Vision.
Detecting Colors using RGB Color Space
This is a post which is based on Color detection Using the RGB Basics and It would be really useful in certain situations.This method uses the RGB Color Space to detect the Colors…Read on..
May 25, 2009
Project Suggestions
Dear friends,
This is the post where you may get some project suggestions on whatever you wish..This blog is your’s and I want you to please be interactive..So feel free to ask your questions here and you may also help others…You may post links and suggestions..Its all yours…
April 26, 2009
Understanding Color Space Basics
This post once again concentrates on understanding “What is Color Space” and how can it be used for Different projects you do and how well can you use the basics to finish the same.I still see a lot of users asking questions about Color Spaces and how to use them and this post satisfies your Thirst…Look at this picture.

This picture (from Wikipedia) shows a man wearing a blue dress with a green background.Now lets split this image channels into the constituent channels and then see what are the constituents of the image with the help of this program.
/*Program to remove the components and show them apart..
.make the users realize the importance
of color space in OpenCV*/
/*All the includes*/
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
#include "conio.h"
int main() {
int i,j,k;
/*Load the image*/
IplImage* frame=cvLoadImage("Man Color Image.jpg",1);
cvNamedWindow("main", CV_WINDOW_AUTOSIZE);
cvNamedWindow("red", CV_WINDOW_AUTOSIZE);
cvNamedWindow("green", CV_WINDOW_AUTOSIZE);
cvNamedWindow("blue", CV_WINDOW_AUTOSIZE);
if(frame==NULL){ /*If image not found then exit.
This is the function of this loop */
printf("the file doesnot exist");
exit(0);
}/*creating 3 images all one channel*/
IplImage* blue=cvCreateImage( cvGetSize(frame), 8, 1 );
IplImage* green=cvCreateImage( cvGetSize(frame), 8, 1 );
IplImage* red=cvCreateImage( cvGetSize(frame), 8, 1 );
//-----------------------------------------
/*Setting the Image Channel of interest(COI)*/
cvSetImageCOI( frame, 1 );
/*Here CvCopy sees the COI and ROI and then copies the channels to be copied
Here we set the first channel as the channel of interest*/
cvCopy( frame, blue, NULL );/*Copy the first channel */
cvSetImageCOI( frame, 2 );/*Set the COI to second channel*/
cvCopy( frame, green, NULL );/*Copy the second channel*/
cvSetImageCOI( frame, 3 );/*Set the COI to third channel*/
cvCopy( frame, red, NULL );/*Copy the third channel*/
cvShowImage("main",frame);
cvShowImage("blue",blue);
cvShowImage("green",green);
cvShowImage("red",red);
cvSaveImage("main.jpg",frame);
cvSaveImage("blue.jpg",blue);
cvSaveImage("green.jpg",green);
cvSaveImage("red.jpg",red);
cvWaitKey();
cvDestroyWindow( "main" );
cvDestroyWindow( "red" );
cvDestroyWindow( "green" );
cvDestroyWindow( "blue" );
return 0;/*This statement is compiler specific and might change.
As i already said that I am using DEV C++ as my compiler*/
}

Blue Channel

Green Channel

Red Channel
Now why is the Dress in the Red Channel low in Intensity..? (Do not worry about the sizes of the Image I have changed them to suit the looks and spacing).Its because the Red color is less in the blue area “but it is not zero(for most of the pixels in real time imaging)”.
Just look at the upper left corner in the green Image behind the head of the man.Don’t you see the leaves of the tree clearly with more intensity.Its because the leaves are green and which means they have more green color and less of the other colors.Because they are green.A matter of Fact (the leaves are green because they do not absorb the green color they reflect the green color).
If you look in the blue channel, the background is very dark which means that there is less “blue” intensity….think for some points like this from the image.
So any area in an image no matter what color it is has RGB values .
Now 8*8*8=(2^8)*(2^8)*(2^8)=2^24 which roughly comes to 16 million colors.So its is very difficult to detect specific colors using RGB hence we do a color space conversion.I have already posted a topic describing the importance of the HSV color space.
Now if you observe the higher the ‘R’ ,’G', ‘B’ value higher is the intensity and when R=G=B=255 which means that its pure white light, which again means that the intensity is contained in a combination of the RGB values…similarly some more arithmetic done on the RGB gives the HUE nd the saturation values.
Now look at the upper left corner of the green image …? Dont you think its brighter.The plants are green Just look at the thick green leaves they are brighter.If a part in the image is brighter then it means that it has higher intensity and higher intensity means that the higher is the number.
Just try to satisfy yourself with what you think and what is present.Ponder over this post for sometime it would be a good time investment.
Remember->brighter Region signifies higher intensity which again means higher numbers
Darker regions means the vice versa…please give me some feedback about my explanation
I will try to Improve the same.
December 20, 2008
Making of the Youtube Video
December 19, 2008
Saving a part of a video in another video
Before you come and read this post i sincerely request you to first read the other post which speaks how to convert a collection of images into a video….if you already know the same read on….
This post speaks about how to save a part of a video in another video….
(more…)
Creating Your own Videos in OpenCV
Don’t you want to convert all the images which you have of your friends or a collection of good images ..the images which you like ..convert them into a video..?
Yes…You can do it some very small code…here it goes…So now let’s speak about making your own videos in OpenCV without a help of a camera. (more…)
September 28, 2008
Color Detection by using Color space basics
Ever wondered how can i detect the color ..rather one color from many colors and highlight the same..?
This post is all about it…a quick glimpse about the color detection thing is here and also the method which I have used here is Color space conversion..So If you are a color Enthusiast then you should study this post… (more…)
