Welcome to Chris Johnsons' Portfolio

G'day. My name is Christopher Johnson and you've reached my humble portfolio which contains bits and pieces that I've created over the years. I've decided to post as much as I can in order to show where I've come from and in what ways I've improved. Thanks for stopping by. I hope you enjoy what you see. If you have any questions then feel free to contact me. Chris.

Twitter Update

Follow me on Twitter

Navigation

My Websites

Most Recent Additions

Browse by Month

Content Syndication

Meta

TimeLapse Code Snippets

main function

int main(int argc, char **argv) {
	// parse the passed in parameters
	int currentArgc;
	for(currentArgc = 1; currentArgc < (argc-1); currentArgc++) {
		if(strncmp(argv[currentArgc], "-t", 2) == 0) {
			timeWait = atoi(argv[currentArgc + 1]);
		} else if(strncmp(argv[currentArgc], "-i", 2) == 0) {
			picturesToTake = atoi(argv[currentArgc + 1]);
		} 
	}
 
	if(timeWait <= 0) {
		fprintf(stderr,"Time between shots is too small\n");
		exit(EXIT_FAILURE);
	}
 
	// Create the directory to store the frames
	DIR *dir = opendir(directory);
	if(dir == NULL) {
		if(mkdir(directory, 493) == -1) {
			fprintf(stderr, "Couldn't create directory %s", directory);
		}
	} else {
		closedir(dir);
	}
 
	// Try to open capture device that is available
	capture = cvCaptureFromCAM(CV_CAP_ANY);
	if(!capture) {
		fprintf( stderr, "Cannot Open Capture Device \n" );
		exit(EXIT_FAILURE);
	}
 
	// Create a window in which the captured images will be presented
	cvNamedWindow("Time Lapse", CV_WINDOW_AUTOSIZE);
	frameW = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
	frameH = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
 
	// Setup captured font
	CvFont font;
	cvInitFont(&font, CV_FONT_HERSHEY_DUPLEX, 1.0, 1.0, 0, 1, CV_AA);
	CvPoint pt = cvPoint(10, frameH - 10);
 
	// Set an alarm for taking pictures
	alarm(timeWait);
	signal(SIGALRM, takePicture);
 
	// Display current frame
	while(finished == 0) {
		IplImage* frame = cvQueryFrame( capture );
		if(!frame) {
		    fprintf( stderr, "Frame Capture Error\n" );
			break;
		}
 
		// If a picture has been taken display text
		if(snap == 1) {
			snap = 0;
			cvPutText(frame, "Snap", pt, &font, CV_RGB(255, 255, 255) );
		}
 
		cvShowImage("Time Lapse", frame );
 
		// Check to see if escape was pushed
		if((cvWaitKey(10) & 255) == 27) {
			finished = -1;
		}
	}
 
	// Clean up
	cvReleaseCapture(&capture);
	cvDestroyWindow("Time Lapse");
 
	// Check for a clean exit
	if(finished != -1) {
		convertPicsToAVI();
	}
 
	exit(EXIT_SUCCESS);
}