teaching machines

Canny Algorithm edge detection

November 1, 2011 by . Filed under fish vision.

Last week I started reading sections of the OpenCV book given to me by Professor Johnson and Stevenson. The sections I read with had to deal with edge detection and gray scaling (required for the Canny Algorithm). I expanded upon my previous code for loading in an image to do this.

 

// OpenCVConfiguration.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cv.h>
#include <highgui.h>


int main(int argc, char *argv[])
{
	//image loading and allocation to memory
	//IplImage* img = cvLoadImage( "S:\\Photos\\Television\\Pokemon\\pokemon.jpg" );

	//window creation
	//cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );

	//load image to window
	//cvShowImage( "Example1", img );

	//wait key causes a pause for a keystroke determined by the parameter
	//0 = indefinite wait
	//cvWaitKey( 0 );
	//without this the window seems to close instantly

	//release the memory of the image
	//cvReleaseImage( &img );

	//deallocate the window memory
	//cvDestroyWindow( "Example1" );

	//image loading and allocation to memory
	IplImage* img = cvLoadImage( "S:\\Photos\\Fish Vision\\FCM060-2FL.jpeg" );
	//IplImage* img = cvLoadImage( "S:\\Photos\\Television\\Pokemon\\pokemon.jpg" );

	//window creation
	cvNamedWindow( "Original", CV_WINDOW_AUTOSIZE );

	//load image to window
	cvShowImage( "Original", img );

	//without this the window seems to close instantly

	//Try to grayscale image
	
	//was going to copy image did not work as planned, just going to create a new image
	//IplImage* img2 = cvCopy( img );
	//does not work requires array does not take iplimage
	//cvCvtColor() 

	//instead create new image to convert to grayscale
	//IplImage* img2 = cvCreateImage( cvSize( img->width, img->height ), img->depth, img->nChannels );
	IplImage* img2 = cvLoadImage("S:\\Photos\\Fish Vision\\FCM060-2FL.jpeg",CV_LOAD_IMAGE_GRAYSCALE);
	//IplImage* img2 = cvLoadImage("S:\\Photos\\Television\\Pokemon\\pokemon.jpg",CV_LOAD_IMAGE_GRAYSCALE);

	//cvCvtColor( img, img2, CV_RGB2GRAY );

	//window creation
	cvNamedWindow( "Grayscale", CV_WINDOW_AUTOSIZE );

	//load image to window
	cvShowImage( "Grayscale", img2 );

	// expects (img, output img, low threshold, high threshold, aperture?) //images must be grayscale
	cvCanny( img2, img2, 10, 100, 3  );

	//window creation
	cvNamedWindow( "Canny Edge Detection", CV_WINDOW_AUTOSIZE );

	//load image to window
	cvShowImage( "Canny Edge Detection", img2 );

	//wait key causes a pause for a keystroke determined by the parameter
	//0 = indefinite wait
	cvWaitKey( 0 );

	//release the memory of the image
	cvReleaseImage( &img );
	cvReleaseImage( &img2 );

	//deallocate the window memory
	cvDestroyWindow( "Original" );
	cvDestroyWindow( "Grayscale" );
	cvDestroyWindow( "Canny Edge Detection" );

	return 0;
}

I have left the comments in to show some of my thought process. The next step is to get tortoise svn up and running. I have installed and will be learning how to use it with Cmake.