Showing posts with label Open CV. Show all posts
Showing posts with label Open CV. Show all posts

Wednesday, October 7, 2009

Reading and Displaying Image in Open CV

// Reading and Displaying Image

#include "stdafx.h"

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])

{

int apertureSize = 3;

int dx=1;

int dy=0;

int r,g,b;

IplImage *img = cvLoadImage("C:\\lena.png");

IplImage *img1 = cvCreateImageHeader(cvSize(img->width,img->height),img->depth,img->nChannels);

printf("Number of channels %d",img->nChannels);


//cvLaplace(img,img1,apertureSize);

//CV_RGB(r,g,b)(int)((uchar)(b)+((uchar)(g)<<8)+((uchar)(r)<<16));

//cvCanny(img,img1,

cvNamedWindow("Image",1);

cvShowImage("Image",img);

cvWaitKey();

return 0;

}

// Reading and Displaying Image

#include "stdafx.h"

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])

{

int apertureSize = 3;

int dx=1;

int dy=0;

int r,g,b;

IplImage *img = cvLoadImage("C:\\lena.png");

IplImage *img1 = cvCreateImageHeader(cvSize(img->width,img->height),img->depth,img->nChannels);

printf("Number of channels %d",img->nChannels);



//cvLaplace(img,img1,apertureSize);

//CV_RGB(r,g,b)(int)((uchar)(b)+((uchar)(g)<<8)+((uchar)(r)<<16));

//cvCanny(img,img1,

cvNamedWindow("Image",1);

cvShowImage("Image",img);

cvWaitKey();

return 0;

}

Sobel edge detection in Images using Open CV

// Sobel Edge

#include "stdafx.h"

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])

{

int dx,dy,apertureSize;

IplImage *img = cvLoadImage("c:\\lena.png");

IplImage *img1 = cvCloneImage(img);

dx=1; dy=0; apertureSize=3;

cvSobel(img,img1,dx,dy,apertureSize);

cvNamedWindow("SobelEdge",1);

cvShowImage("SobelEdge",img1);

cvWaitKey();

return 0;

}

// Sobel Edge

#include "stdafx.h"

#include <cv.h>

#include <cxcore.h>

#include <highgui.h>

int _tmain(int argc, _TCHAR* argv[])

{

int dx,dy,apertureSize;

IplImage *img = cvLoadImage("c:\\lena.png");

IplImage *img1 = cvCloneImage(img);

dx=1; dy=0; apertureSize=3;

cvSobel(img,img1,dx,dy,apertureSize);

cvNamedWindow("SobelEdge",1);

cvShowImage("SobelEdge",img1);

cvWaitKey();

return 0;

}

Reading and Displaying image in Open CV

#include "stdafx.h"

#include <stdlib.h>

#include <stdio.h>

#include <math.h>

#include <cv.h>

#include <highgui.h>

int main(int argc, char *argv[])

{

IplImage* img = 0;

IplImage* img1 = 0;

int height,width,step,channels;

uchar *data;

int i,j,k;

// load an image

img=cvLoadImage("C:\\boat.png");

if(!img){

printf("Could not load image file: %s\n","C:\\House24.bmp");

exit(0);

}

// get the image data

height    = img->height;

width     = img->width;

step      = img->widthStep;

channels  = img->nChannels;

int dataOrder = img->dataOrder;

int imageSize = img->imageSize;

printf("Processing a %dx%d image with %d channels\n",height,width,channels);

printf("Step size = %d\n",step);

printf("Data Order = %d\n",dataOrder);

printf("Image Size = %d\n",imageSize);

printf("Number of Channels = %d\n",channels);

img1 = cvCloneImage(img);

IplImage* img2 = cvCloneImage(img);

// create a window

//cvNamedWindow("Image Negative", CV_WINDOW_AUTOSIZE);

//cvMoveWindow("Image Negative", 100, 100);

cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);

cvMoveWindow("Original Image", 200,200);

cvNamedWindow("Smooth Image", CV_WINDOW_AUTOSIZE);

cvMoveWindow("Smooth Image", 300,300);

// invert the image

//  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)

// data[i*step+j*channels+k]=255-data[i*step+j*channels+k];

//void cvSmooth( const CvArr* img, CvArr* img2, int smoothtype=CV_MEDIAN, int param1=15);

//void cvSobel(const CvArr* img, CvArr* img2, int xorder=2, int yorder=2, int aperture_size=3);

// show the image

//cvCanny(img,img2,10,100,3);

cvShowImage("Original Image", img1);

//cvShowImage("Image Negative", img );

cvShowImage("Smooth Image", img2);

// wait for a key

cvWaitKey(0);

// release the image

cvReleaseImage(&img1 );

cvReleaseImage(&img2);

return 0;

}

#include "stdafx.h"

#include <stdlib.h>

#include <stdio.h>

#include <math.h>

#include <cv.h>

#include <highgui.h>

int main(int argc, char *argv[])

{

IplImage* img = 0;

int height,width,step,channels;

uchar *data;

int i,j,k;

// load an image

img=cvLoadImage("C:\\boat.png");

if(!img){

printf("Could not load image file: %s\n","C:\\House24.bmp");

exit(0);

}

// get the image data

height    = img->height;

width     = img->width;

step      = img->widthStep;

channels  = img->nChannels;

int dataOrder = img->dataOrder;

int imageSize = img->imageSize;

printf("Processing a %dx%d image with %d channels\n",height,width,channels);

printf("Step size = %d\n",step);

printf("Data Order = %d\n",dataOrder);

printf("Image Size = %d\n",imageSize);

printf("Number of Channels = %d\n",channels);

// create a window

cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);

cvMoveWindow("Original Image", 200,200);

// show the image

cvShowImage("Original Image", img);

// wait for a key

cvWaitKey(0);

// release the image

cvReleaseImage(&img );

return 0;

}