Skip to content

Instantly share code, notes, and snippets.

@nikhil9
Created November 1, 2012 18:48
Show Gist options
  • Save nikhil9/3995679 to your computer and use it in GitHub Desktop.
Save nikhil9/3995679 to your computer and use it in GitHub Desktop.
Sample code to load GrayScale image using Opencv
#include <iostream>
#include <cv.h>
#include <highgui.h>
using namespace std;
char key;
int main()
{
IplImage* frame=cvLoadImage("img1.png",CV_LOAD_IMAGE_GRAYSCALE); //Load image in IplImage frame.
cvNamedWindow("window1", CV_WINDOW_AUTOSIZE); //Create window of name 'Window1'
if(frame == NULL){ //if image file not found then print this message
printf("the file doesnot exist");
exit(0);
}
cvShowImage("window1",frame); //Display image in Window1
cvWaitKey(); //Wait for keyboard input
cvDestroyWindow( "window1" ); //destroy window
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment