For Mac people, some of the steps of the opencv compilation can take a while, please try to follow this instructions prior to the class.
If you do not have macports, install it
http://www.macports.org/install.php
On a new shell, install cmake
sudo port install cmake
Check out the openCV sourceCode
svn co https://code.ros.org/svn/opencv/trunk/opencv
From the opencv directory run Cmake
sudo cmake -G "Unix Makefiles"
sudo make -j8
sudo make install
If you get no errors you should be ready to compile an opencv application.
This code shows a simple capture from webcam:
Code: Select all
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
// A Simple Camera Capture Framework
int main() {
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if( !capture ) {
fprintf( stderr, "ERROR: capture is NULL \n" );
getchar(); return -1; }
// 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;
}
cvShowImage( "mywindow", frame );
// 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;
}
gcc -o TheOut sourcefile.c -I/usr/local/include/opencv
-L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_ml
-lopencv_video -lopencv_imgproc -lopencv_calib3d