@RodMckay said in Error: undefined reference to `cvReleaseImage' (opencv + Qt):
I try to write a simple image viewer program by using opencv int Qt5.1
the problem is that Qt5.1 shows me the error in runtime , where am I wrong ?
.pro
@
#-------------------------------------------------
Project created by QtCreator 2013-09-11T03:55:37
#-------------------------------------------------
QT += core
QT -= gui
TARGET = camera_onConsole
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += D:\opencv\build\include
LIBS += -lopencv_highgui246
-lopencv_imgproc246
-lopencv_objdetect246
SOURCES += main.cpp
@
.cpp
@
#include <QCoreApplication>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <opencv/cxcore.h>
int main(int argc, char argv[])
{
QCoreApplication a(argc, argv);
IplImage img = cvLoadImage("D:/image.jpg");
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow( "Example1" );
return a.exec();
}
@
is there anyone who knows solution of this ? thanks for replies
The error in the runtime could be due to various reasons, and it would be helpful if you could provide more information about the specific error message or behavior that you are encountering.
However, based on the code that you have provided, there are a few issues that might be causing the problem:
The Qt project file (.pro) is missing the inclusion of the "widgets" module, which is required for creating GUI applications. You can add it by modifying the "QT" line in your .pro file to:
QT += core widgets
The OpenCV library that you are linking to is version 2.4.6, which might not be compatible with the version of Qt that you are using (Qt 5.1). You could try linking to a more recent version of OpenCV (e.g., 4.x), or using an older version of Qt that is compatible with OpenCV 2.4.6.
The use of the "IplImage" data type is deprecated in newer versions of OpenCV, and you might encounter compatibility issues when using it with Qt. You could try using the newer "cv::Mat" data type instead, which is recommended for working with images in OpenCV.
Here is a modified version of your code that addresses these issues:
.pro
@
#-------------------------------------------------
Project created by QtCreator 2013-09-11T03:55:37
#-------------------------------------------------
QT += core widgets
TARGET = camera_onConsole
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += D:\opencv\build\include
LIBS += -lopencv_highgui
-lopencv_imgproc
-lopencv_objdetect
SOURCES += main.cpp
@
.cpp
@
#include <QCoreApplication>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
cv::Mat img = cv::imread("D:/image.jpg");
cv::namedWindow("Example1", cv::WINDOW_AUTOSIZE);
cv::imshow("Example1", img);
cv::waitKey(0);
cv::destroyWindow("Example1");
return a.exec();
}
@
Note that this code uses the newer "cv::Mat" data type instead of "IplImage", and also uses the updated function names for creating and destroying windows in OpenCV.