undefined reference to `cvLoadImage'

asked 2013-10-21 08:45:23 -0600

MohsenHk gravatar image

updated 2013-10-21 09:16:39 -0600

I installed "libopencv-dev version: 2.3.1-7" with "synaptic". when I(my os is ubuntu 12.04 32bit)

.pro:

QT       += core gui
TARGET = opencv_test1
TEMPLATE = app
SOURCES += main.cpp\
        widget.cpp
HEADERS  += widget.h
FORMS    += widget.ui

main.cpp:

#include <QtGui/QApplication>
#include "widget.h"
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Widget w;
    w.show();
    //---------------------------------------------------------------
    IplImage* img= cvLoadImage("/home/mrl-x200/Desktop/IR_0007.jpg");
    //cvNamedWindow("hi",CV_WINDOW_AUTOSIZE);
    //cvShowImage("hi",img);
    //---------------------------------------------------------------
    return a.exec();
}

when i ran it gave me this error:

error: undefined reference to `cvLoadImage'
error: collect2: ld returned 1 exit status

what am I should to do? thank you

edit retag flag offensive close merge delete

Comments

1

either use the c++ api ( preferred ) , cv::Mat, cv::imread(), etc.

or include "opencv/cv.h" and "opencv/highgui.h"

honestly, don't use the old c-api, it has restricted functionality (can't access anything invented after 2010) and support for it will go away fast.

btw, which opencv version did you get via synaptic ? (current is 2.4.6)

berak gravatar imageberak ( 2013-10-21 08:52:17 -0600 )edit

thank you... libopencv-dev version: 2.3.1-7 . then I can't use any opencv2 functions?

MohsenHk gravatar imageMohsenHk ( 2013-10-21 09:22:58 -0600 )edit
1

oh, sure you can use opencv2 with 2.3.1.

cvLoadImage amd IplImage are from the old c-api, avoid those.

use cv::Mat img=cv::imread("my.png"), i.e, the c++ api

2.3.1 is a bit old, no face-recognition, stitching, hdr stuff. maybe update the one or other day

oh, and i did not read properly:

you need to link opencv_highgui231

berak gravatar imageberak ( 2013-10-21 09:32:58 -0600 )edit

thank you my friend :)

MohsenHk gravatar imageMohsenHk ( 2013-10-21 09:45:05 -0600 )edit
1

cvLoadImage should be fine as soon as you include library references in the .pro file, for example:

INCLUDEPATH += "C:/OpenCV245/mybuild2/install/include" LIBS += -L"C:/OpenCV245/mybuild2/install/lib" \ -lopencv_core245d \ -lopencv_imgproc245d \ -lopencv_highgui245d

DONT forget the 'l' letter just in front of each lib name.

antonio gravatar imageantonio ( 2013-10-21 10:09:25 -0600 )edit