Here this post demonstrates the sobel operator..the double differentiation on the picture do you remember …? since this is double differentiation on the input the output is very dull you need to observe the output very closely. Have fun differentiating the input Image.
This post just describes how to copy a channel from the color image and then put it in a single channel image.
Here an important point is that If the Image is a three channel image then OpenCV knows that it should be a color image.When we declare a variable(whenever I refer to a variable I mean IplImage Variable from now on) with only one channel then its naturally a MonoChrome Image.
So if we copy a color channel into a monochrome channel we get a monochrome image.Its simple.
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
int main() {
/*If you do to find Explanations for some functions i'd suggest you
that you check out the older posts of this blog*/
int height,width,step,channels;
uchar *data,*data1;
int i,j,k;
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
IplImage* frame = cvQueryFrame( capture );
IplImage* src1 = cvCreateImage( cvGetSize(frame), 8, 1 );/*This is the image
where a mono image is stored*/
if( !capture ) {
fprintf( stderr, "ERROR: capture is NULL n" );
getchar();
exit(0);
}
// Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
// Show the image captured from the camera in the window and repeat
while( 1 ) {
// Get one frame
IplImage* frame = cvQueryFrame( capture );
if( !frame ) {
fprintf( stderr, "ERROR: frame is null...n" );
getchar();
break;
}
height = frame -> height;
width = frame -> width;
step = frame -> widthStep;
channels = frame->nChannels;
data = (uchar *)frame->imageData;
data1 = (uchar *)src1->imageData;
/*Just try to figure out why i did not use the third for Loop..?
Well this is not a perfect way to get a monochrome Image of a color Image but this is a ver good Example of how to
play with Images */
for(i=0;i< (height);i++)
for(j=0;j< width; j++)
data1[i*(src1->widthStep)+j*(src1->nChannels)]=data[(height-i)*step+j*channels];
/*Here i used height-i because the image is fliped vertically.reflipping it removes the Error
We can use a flipping function from OpenCV but since a small manipulation is working why do it any other way..*/
cvShowImage( "mywindow", src1 );
/* Do not release the frame!
//If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
//remove higher bits using AND operator*/
if( (cvWaitKey(10) && 255) == 27 ) break;
}
/* Release the capture device housekeeping*/
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}
/*End of program*/
Well then If you have studied all the posts of the blog and practiced them,
then by this time you are fairly acquainted with OpenCV Basics.
Try to pick up tasks and then try to accomplish them by yourself…

hey hi ,
im extremely happy the way u r explaining the working of opencv.its really impressive.do continue the gud work which is helping beginers like me..thanks once again..
Comment by D_E_A_R — September 17, 2008 @ 9:34 am |
This post has been updated Today..
Comment by colouredpages — June 23, 2009 @ 7:16 pm |
hai, ur materials are very good.
Comment by JOHN — May 3, 2010 @ 12:37 pm |