2

I am trying to write this simple image modifier program in c++ with opencv on netbeans. I am using ubuntu 10.04. Everytime I try to run or compile it, it returns the below errors. I have opencv configured in the linker and the additional tools. What is going wrong?

include stdlib.h  
include stdio.h  
include math.h  
include cv.h  
include highgui.h  
int main(int argc, char *argv[])  
{  
  IplImage* img = 0;  
  int height,width,step,channels;  
  uchar *data;  
  int i,j,k;  
  if(argc<2){  
    printf("Usage: main <image-file-name>\n\7");  
    exit(0);  
  }  
  // load an image  
  img=cvLoadImage(argv[1]);  
  if(!img){  
    printf("Could not load image file: %s\n",argv[1]);  
    exit(0);  
  }  
  // get the image data  
  height    = img->height;  
  width     = img->width;  
  step      = img->widthStep;  
  channels  = img->nChannels;  
  data      = (uchar *)img->imageData;  
  printf("Processing a %dx%d image with %d channels\n",height,width,channels);  
  // create a window  
  cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);  
  cvMoveWindow("mainWin", 100, 100);  
  // invert the image  
  for(i=0;i<height;i++) for(j=0;j<width;j++) for(k=0;k<channels;k++)  
    data[i*step+j*channels+k]=255-data[i*step+j*channels+k];  
  // show the image  
  cvShowImage("mainWin", img );  
  // wait for a key  
  cvWaitKey(0);  
  // release the image  
  cvReleaseImage(&img );  
  return 0;  
}  

"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf  
make[1]: Entering directory `/home/kevin/NetBeansProjects/CppApplication_4'  
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/cppapplication_4  
make[2]: Entering directory `/home/kevin/NetBeansProjects/CppApplication_4'  
mkdir -p build/Debug/GNU-Linux-x86  
rm -f build/Debug/GNU-Linux-x86/main.o.d  
g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/  main.o main.cpp  
main.cpp:4:16: warning: cv.h: No such file or directory  
main.cpp:5:21: warning: highgui.h: No such file or directory  
main.cpp: In function ‘int main(int, char**)’:  
main.cpp:10: error: ‘IplImage’ was not declared in this scope  
main.cpp:10: error: ‘img’ was not declared in this scope  
main.cpp:12: error: ‘uchar’ was not declared in this scope  
main.cpp:12: error: ‘data’ was not declared in this scope  
main.cpp:21: error: ‘cvLoadImage’ was not declared in this scope  
main.cpp:32: error: expected primary-expression before ‘)’ token  
main.cpp:32: error: expected ‘;’ before ‘img’  
main.cpp:36: error: ‘CV_WINDOW_AUTOSIZE’ was not declared in this scope  
main.cpp:36: error: ‘cvNamedWindow’ was not declared in this scope  
main.cpp:37: error: ‘cvMoveWindow’ was not declared in this scope  
main.cpp:44: error: ‘cvShowImage’ was not declared in this scope  
main.cpp:47: error: ‘cvWaitKey’ was not declared in this scope  
main.cpp:50: error: ‘cvReleaseImage’ was not declared in this scope  
make[2]: *** [build/Debug/GNU-Linux-x86/main.o] Error 1  
make[1]: *** [.build-conf] Error 2  
make: *** [.build-impl] Error 2  
make[2]: Leaving directory `/home/kevin/NetBeansProjects/CppApplication_4'  
make[1]: Leaving directory `/home/kevin/NetBeansProjects/CppApplication_4'  

BUILD FAILED (exit value 2, total time: 115ms)  

EDIT: Sorry for the massive jumble

karlphillip
  • 92,053
  • 36
  • 243
  • 426
a sandwhich
  • 4,352
  • 12
  • 41
  • 62

2 Answers2

2

Alright mister, this is your compilation line right here:

g++    -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/  main.o main.cpp

When you include headers using <>:

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

the compiler will search those files on the default include path, which is usually: /usr/include

So, knowing that opencv doesn't install its developments files on this directory, I must suggest you to find them. IF opencv is correctly installed on the system, the command pkg-config --cflags opencv is going to tell you where they are. Go ahead, try it. You could also execute pkg-config --libs opencv to find the libraries that you must add to the compilation.

To summarize everything, if you open up a terminal and cd to the directory where your source code is, the command below might compile your project IF you have opencv correctly installed.

g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/main.o.d -o build/Debug/GNU-Linux-x86/  main.o main.cpp `pkg-config --cflags opencv` `pkg-config --libs opencv`

EDIT:

You know what? I just paste some code (opencv/camera) here (let's call it funcam.cpp). You can use it to test if OpenCV is installed and compiles stuff on your system. You can compile it with:

g++ funcam.cpp -o funcam `pkg-config --cflags opencv` `pkg-config --libs opencv`

If it works, you must figure out how to configure Netbeans. If it doesn't, you need to properly install OpenCV.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • @a I don't use it, I enjoy cmd line stuff too much. But now that you know what's wrong you can find a tutorial on how to configure Netbeans and add those settings. – karlphillip Oct 12 '10 at 02:57
  • Ok thank you. I typically use the command line, but I have been making an effort to use an ide for once. – a sandwhich Oct 12 '10 at 03:19
  • Ok, I have gotten it to work. Somehow. Ohwell, I'll just copy and paste everything into any new project. Thank you. – a sandwhich Oct 12 '10 at 22:09
1

This link will be helpful regarding setting up Netbeans to use OpenCV. Directly jump to bottom of the page if opencv and Netbeans are already installed.
Note directory paths, one will have to change them based on the installation.

Niroshan
  • 2,064
  • 6
  • 35
  • 60