Opencv Setup

Post Reply
Javier
Posts: 11
Joined: Tue Sep 21, 2010 6:01 pm

Opencv Setup

Post by Javier » Wed Oct 27, 2010 4:09 pm

Hi all,
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; 
} 

Using gcc and assuming the source file to be sourcefile.c :

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

mhetrick
Posts: 15
Joined: Sat Sep 25, 2010 7:08 pm

Re: Opencv Setup

Post by mhetrick » Thu Oct 28, 2010 2:26 am

If you end up getting Error 1 like I did, you need to install the Java OSX Developers Package (You need to have a developer account at Apple).

http://developer.apple.com/java/download/

Post Reply