CUDA and OpenCV how to put them working together?

hi everybody,

i’m trying to do a simple thing, runing some OpenCV code on my CUDA (using cublas) project.

i’m just trying to compile the folowing lines (they are in the midle of CUBLAS code):

IplImage* img;

img=cvLoadImage( "./org.jpg",CV_LOAD_IMAGE_COLOR );

cvNamedWindow("Capture",CV_WINDOW_AUTOSIZE);

cvShowImage("Capture",img);

i have all the necessary includes in the file and my makefile looks like:

# Add source files here

EXECUTABLE	:= gpgpu

# Cuda source files (compiled with cudacc)

CUFILES		:= #gpgpu.cu

# C/C++ source files (compiled with gcc / c++)

CCFILES		:= \

	main.cpp \

	auxfunctions.cpp \

	#gpgpu_gold.cpp \

# Additional libraries needed by the project

USECUBLAS	   := 1

############################################################

####################

# Rules and targets

# for OpenCV's includes and libs, create path

NVCCFLAGS+=`pkg-config opencv --cflags`

	LIB+=`pkg-config opencv --libs`

include ../../common/common.mk

when i try to compile it gives the following error:

obj/release/main.cpp.o: In function `main':

main.cpp:(.text+0xa9): undefined reference to `cvLoadImage'

main.cpp:(.text+0xbf): undefined reference to `cvNamedWindow'

main.cpp:(.text+0xcf): undefined reference to `cvShowImage'

collect2: ld returned 1 exit status

make: *** [../../bin/linux/release/gpgpu] Error 1

i supose this is because the Opencv library’s are not linked correctly. i’v looked everywhere and i was’s able to find any decent topic about putting opencv and CUDA/CUBLAS working together.

I’d really apreciate any help. I’m running Ubuntu 8.04 on a 8800 GT.

thanks

Found a solution. it’s certainly not the way to do it but it works,

just modified the lines of common.mk from/to:

# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc

to

# Includes
INCLUDES += -I. -I$(CUDA_INSTALL_PATH)/include -I$(COMMONDIR)/inc -I/usr/include/opencv

and

ifeq ((USECUBLAS),1) ifeq ((emu),1)
LIB += -lcublasemu
else
LIB += -lcublas
endif
endif

to

ifeq ((USECUBLAS),1) ifeq ((emu),1)
LIB += -lcublasemu -lcxcore -lcv -lhighgui -lcvaux -lml
else
LIB += -lcublas -lcxcore -lcv -lhighgui -lcvaux -lml
endif
endif

I am trying to run a simple open cv code using CUDA

The code is a sample program

#include<stdio.h>

#include<math.h>

#include <cv.h>

#include <highgui.h>

/This will pop up a small box with “Welcome to OpenCV” as the text.@author: Amir hossein khalili a_khalili@ce.sharif.eduimitated from Gavin Page, gsp8334@cs.rit.edu@date: 1 March 2007/

int main( int argc, char** argv )

{//declare for the height and width of the imageint

int height = 620;

int i=10;

int width = 440;//specify the point to place the text

CvPoint pt = cvPoint( height/4, width/2 );//Create an 8 bit, 3 plane image

IplImage* hw = cvCreateImage(cvSize(height, width), 8, 3);//Clearing the Image

cvSet(hw,cvScalar(0,0,0));//initialize the font

CvFont font;cvInitFont( &font, CV_FONT_HERSHEY_COMPLEX,1.0, 1.0, 0, 1, CV_AA);//place the text on the image using the font

cvPutText(hw, "Welcome To OpenCV", pt, &font, CV_RGB(150, 0, 150) );//create the window container

cvNamedWindow("Hello World", 0);//display the image in the container

cvShowImage("Hello World", hw);//hold the output windows

cvWaitKey(0);

return 0;

}

I have configured CUDA VS Wizard 2.2 (http://forums.nvidia.com/index.php?showtopic=155412&st=0) and it works perfectly to cmpile and run small cuda codes and also all the sample cuda codes. But when I build this code in a cpp file inside a cuda project created using the wizard installed in VS 2008, it says “unresolved external symbol” for all cv functions!! Another thing to wonder is when I only compile the cpp file containing this code in the cuda project it gets compiled successfully!

Another problem: If I make a cuda kernel (the file containing the kernel has definition to include cuda.h) and call it from within the cpp file, it says unable to open cuda.h!! But, when I only run a cuda code in this project it is able to find the cuda.h and gets executed.

Cuda file containing the cuda kernel:

#include"cuda.h"

int cuda_kernel(int i)

{

i=i+10;

return(i);

}

While including this file in project I add these lines in the cpp file to check whether it is able to call cuda kernel or not:

int i = cuda_kernel(i);

printf("%d",i);

Also, I am unable to find the file common.mk in which change is needed to be done.

Please give some direction!!

Thanks in anticipation!

:confused: