Convert between color spaces:
cvCvtColor(src,dst,code); // src -> dst
code = CV_
e.g.: CV_BGR2GRAY, CV_BGR2HSV, CV_BGR2Lab
Convert between color spaces:
cvCvtColor(src,dst,code); // src -> dst
code = CV_
e.g.: CV_BGR2GRAY, CV_BGR2HSV, CV_BGR2Lab
To threshold one channel in RGB image or any other type it looks like this: This peace of code is inspired from a post in the OpenCV mailing.
In case you want to threshold the blue channel for example, so follow this steps
You would first split the BGR image in the three channels:
cvSplit(BGRimg, Bimg, Gimg, Rimg)
Then, use thresholding to theshold the blue plane to a binary image according to whatever criteria you need (i.e. a 1 is a pixel to keep a 0 is a pixel to discard):
cvThreshold(Bimg, Bimgthresh, ….criteria…)
the use this thresholded image as a “mask” to filter the channels by simple multiplication:
cvMul(Bimg, Bimgthresh, Bimg) cvMul(Gimg, Bimgthresh, Gimg) cvMul(Rimg, Bimgthresh, Rimg)
then recombine the planes into the image
cvMerge(Outimg, Bimg, Gimg, Rimg)
I found this good steps to train Haar classifier from OpenCV mailing list. So I am listing it in case it would help somebody or I need it in my research.
1- For positive set, it’s recommended to have ~2000 samples. The same is applied for the negative ones.
2- If you have different form of the object or gesture; try to make these images have the same conditions. Examples: – All hands are in the same range of degree of rotation. – If you are interested in hands; make your decision either to put wrist or not for ALL images.
3- When you define the ROI ‘Region of interest’ for the positive ones, try to mark an area that have some sort of rough marks. ‘Viola-Jones’ method is using HAAR features to detect candidates, and these features are simple and rough in some how.
4- Don’t include a lot of positions for the same detector; Instead, find the common area ‘if exist’ between all positions ‘forms’ of the object which has rough ‘clear’ marks in it.
Advice: Although machine-learning methods may give good results, but you have to understand their requirements and conditions well to utilize them. Also, they require a lot of GOOD !!! SAMPLES !!! to run the classification well.
At the end I’d like to thank everyone who get involved in this post.
This is an example showing how to crop an image which is loaded from a capture device using matrix as a data storage:
cvNamedWindow("nocrop", CV_WINDOW_AUTOSIZE);
cvNamedWindow("crop", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCaptureFromCAM(0);
if( !capture ){ printf("invalid camera\n"); return; }
IplImage* nocrop = cvQueryFrame(capture);
CvMat* crop = cvCreateMat(nocrop->width/2,nocrop->height/2,CV_8UC3);
for(;;) {
nocrop=cvQueryFrame(capture);
if(!nocrop) return;
cvGetSubRect( nocrop, crop, cvRect( nocrop->width/4, nocrop->height/4, nocrop->height/2, nocrop->width/2 ) );
cvShowImage("nocrop",nocrop);
cvShowImage("crop",crop);
int c=cvWaitKey(33);
if(c==27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("nocrop");
cvDestroyWindow("crop");
return;
[ad#AdBrite inline]
I found a good article where Image allignment Algorithms are discussed with source code.
In this article we see:
Check it here