This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
OpenCV: link error, can’t resolve external symbol _cvResize and _cvCvtColor
What is an undefined reference/unresolved external symbol error and how do I fix it?
I have tried all of the tutorials available on their website, and the solutions on stackoverflow, but i still can't find a solution.
What I have already done:
1- added include folder with the headers.
2- added lib folder to the additional lib directories
3- added opencv_core243d.lib and opencv_highgui243d.lib to additional dependencies.
code i'm trying to compile:
#include <stdio.h>
#include <cv.h>
#include <highgui.h>
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: ./opencv_hello <file.png>\n");
return -1;
}
IplImage* img = cvLoadImage(argv[1], CV_LOAD_IMAGE_UNCHANGED);
if (!img)
{
return -1;
}
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
The linker gives errors concerning unresolved symbols such as cvLoadImage, cvWaitKey etc.
The only thing i can think of would be the libs, but i have included them already.
As I understand, you're using the OpenCV 2.4
In this case I would like to suggest using of the C++ interface.
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(int argc, char* argv[])
{
if (argc < 2)
{
printf("Usage: ./opencv_hello <file.png>\n");
return -1;
}
cv::Mat img = imread(argv[1]);
if (img.empty())
{
return -1;
}
imshow("display", img);
waitKey(0); <---- cvWaitKey() is a C interface functio, waitKey() - C++
return 0;
}
Related
I have been using openCv for a while, but have just moved to windows 10.
Now, existing applications will compile, but I cannot make a new one.
In a new project (visual studio 2015, release 64)
I am adding all the libs:
opencv_calib3d310.lib
opencv_core310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_photo310.lib
opencv_shape310.lib
opencv_stitching310.lib
opencv_superres310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
setting:
D:\opencv-master\build64\lib\Release;%(AdditionalLibraryDirectories)
and
D:\opencv-master\modules\highgui\include
D:\opencv-master\modules\imgcodecs\include
D:\opencv-master\modules\core\include
D:\opencv-master\modules\videoio\include
D:\opencv-master\modules\imgproc\include
%(AdditionalIncludeDirectories)
and adding the most basic:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include "stdafx.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
if (argc != 2)
{
cout << " Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], IMREAD_COLOR); // Read the file
if (image.empty()) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
namedWindow("Display window", WINDOW_AUTOSIZE); // Create a window for display.
imshow("Display window", image); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
In visual studio, Intellisense is fine, no red underlines, everything looks good. When I try to compile tho...
'cv': a namespace with this name does not exist
'Mat': undeclared identifier
'image': undeclared identifier
...and many more. It is like it cannot find the libs, but i am linking them correctly, I am sure of it.
Can anyone assist me here?
I have a problem : error LNK2019: unresolved external symbol [...] referenced in function main
#include <opencv2/highgui/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char * const argv[])
{
cvNamedWindow("P2", CV_WINDOW_AUTOSIZE);
//path to image ex : c:/Users/image.jpg
CvCapture* capture = cvCreateFileCapture("path to image");
IplImage* frame;
while (1) {
frame = cvQueryFrame(capture);
if (!frame) break; cvShowImage("P2", frame); char c = cvWaitKey(0); if (c == 27) break;
}
cvReleaseCapture(&capture); cvDestroyWindow("P2");
return 0;
}
enter image description here
I start my project by following tutorial, the same configuration to use OpenCV with visual Studio and Eclipse but I have the same error.
Probably you're missing to specify input library (project property/link/input).
You don't specify which version of opencv you are using. If you are using openCV 3.1 like me the lib is opencv_world310d.lib for debug and opencv_world310.lib for release. Please check also the bitness of your application. The prebuilt libraries are for 64 bit.
I am trying to use graph library using opencv.
This is the code that I have written , and am building this on Visual studio 2010.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include "GraphUtils.h"
using namespace cv;
using namespace std;
int main()
{
float floatArray[4]= {1,1,2,2};
showFloatGraph("Rotation Angle", floatArray, 4 );
return 0;
}
There is no compilation error.
However, I am getting following linking error:
Error 1 error LNK2019: unresolved external symbol _showFloatGraph
referenced in function _main C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\opencv1\helloworld.obj
Error 2 error LNK1120: 1 unresolved externals C:\Users\Yam\Documents\Visual Studio
2010\Projects\plot\Debug\opencv1.exe
I have put the two files (GraphUtils.h and GraphUtils.c) with my .cpp file.
Why I am getting these compilation errors whenever I am using third party libraries (.c and .h) files, since I get this linking error also when using other library. I asked the question here
In Properties=>Linker=>input=>Additional dependencies , I have added :
opencv_core231d.lib;opencv_highgui231d.lib;opencv_imgproc231d.lib;opencv_features2d231d.lib;opencv_calib3d231d.lib;%(AdditionalDependencies)
And in fact my basic opencv program for image display works fine.
Do I need to do something special when using these libraries. As of now I just copy paste the .c and .h files in the folder where my .cpp file is present. Do I need to do something more ?
Update:
I found that the the file GraphUtils.c has the following code:
// OpenCV
#include <cv.h>
#include <cxcore.h>
#ifdef USE_HIGHGUI
#include <highgui.h>
#endif
I found that the cv.h, cxcore.h and highgui.h are actually present in opencv 2.3.1/opencv folder and so I changed it like this:
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#ifdef USE_HIGHGUI
#include <opencv/highgui.h>
#endif
Unfortunately this gave rise to more linking errors.
Update
The following program works fine.
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include<conio.h>
using namespace cv;
using namespace std;
int main( int argc, const char** argv )
{
Mat img = imread("xyz.bmp", CV_LOAD_IMAGE_UNCHANGED); //read the image data in the file "MyPic.JPG" and store it in 'img'
if (img.empty()) //check whether the image is loaded or not
{
cout << "Error : Image cannot be loaded..!!" << endl;
//system("pause"); //wait for a key press
return -1;
}
namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window
waitKey(0); //wait infinite time for a keypress
destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"
getch();
return 0;
}
But this program always gives error; no header file recognized. so no function would work:
#include "cv.h" //main OpenCV header
#include "highgui.h" //GUI header
int main() {
// declare a new IplImage pointer
IplImage* myimage;
// load an image
myimage = cvLoadImage("sayyidsmile.jpg",1); //change the file name with your own image
//create a new window & display the image
cvNamedWindow("Smile", 1);
cvMoveWindow("Smile", 100, 100);
cvShowImage("Smile", myimage);
//wait for key to close the window
cvWaitKey(0);
cvDestroyWindow( "Smile" );
cvReleaseImage( &myimage );
return 0;
}
Details on Env. Variables
I followed this article to set EVs.
Currently my variables are like this:
Name Value
OpenCV: C:\Users\Yuvue\Desktop\OpenCV2.3.1
INCLUDE: %OPENCV%\build\include
LIB: %OPENCV%\build\x86\vc10\lib
Path: %OPENCV%\build\x86\vc10\bin
Under Properties => VC++ Directories=> Library Directories, I have added the following:
$(OPENCV)\build\x86\vc10\lib
The second program compiles when I explicitly gives path of cv.h in the include. But if I do so with any of the third party libraries when they have used #include, it starts giving linking error (my original question).
Please help me sort this!!
I am really new to Opencv. After downloading and installing Opencv 2.4 according to the instruction, I began writing my first Opencv program, which was basically a copy of the tutorial on the web.
#include <stdio.h>
#include <iostream>
#include <vector>
#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include <stdlib.h>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main( int argc, char** argv )
{
char* filename = "C:\\Research\abc.pgm";
IplImage *img0;
if( (img0 = cvLoadImage(filename,-1)) == 0 )
return 0;
cvNamedWindow( "image", 0 );
cvShowImage( "image", img0 );
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage(&img0);
return 0;
}
The codes work very well, but you may notice that in the above code invoking Opencv function is in a C code fashion. I therefore decide to proceed with C++ code fashion with the following codes:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( int argc, char** argv )
{
if( argc != 2)
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -1;
}
Mat image;
image = imread(argv[1], CV_LOAD_IMAGE_COLOR); // Read the file
if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it.
waitKey(0); // Wait for a keystroke in the window
return 0;
}
However, in this case the program has several link errors although compiling seems fine. The link errors I have received are as follows:
Error 2 error LNK2019: unresolved external symbol "void __cdecl cv::namedWindow(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,int)" (?namedWindow#cv##YAXABV?$basic_string#DV?$char_traits#D#stlp_std##V?$allocator#D#2##stlp_std##H#Z) referenced in function _main C:\Research\OpencvTest\OpencvTest.obj
Error 1 error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow#cv##YAXABV?$basic_string#DV?$char_traits#D#stlp_std##V?$allocator#D#2##stlp_std##ABV_InputArray#1##Z) referenced in function _main C:\Research\OpencvTest\OpencvTest.obj
I am quite sure that I have added necessary Opencv libraries in my program (I use VC10), and the additional libraries I have added are as follows:
stl_port.lib
opencv_highgui242d.lib
opencv_core242d.lib
I was wondering what's wrong with my setting. Why does it work for the first program but not the second one? Any ideas will be appreciated. Thanks!
It has something to do with mixing STLPort and MSVC STL. You probably didn't build OpenCV libraries yourself, so they're using VC10 STL. With C interface there's just char* but with C++ interface linker gets confused with std::string in methods. You should see the same result with imread if you cast it's input to string too.
Can I mix STL implementations in my project?
I was trying to save images from a video file but It couldn't save any image in my hard drive. I compiled following program without errors.
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char* argv[]) {
int c=1;
IplImage* img=0;
IplImage* small;
IplImage* small=new IplImage(inputArray);
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromFile("test.avi");
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
small = cvCreateImage(cvSize(img->width/2,img->height/2), 8, 3);
sprintf(buffer,"C:/image%u.jpg",c);
c++;
if (cvWaitKey(100)== 27) break;
}
cvDestroyWindow("Video");
return 0;
}
I am using a 2.3.1 openCV library and Visual Studio 2010.
How can I save the image from a video file?
I have also tried this code,above program code are something wrong.please see following program code.After i adding following code ,also there was a same problem.
cvSaveImage(buffer,img);
Corrected program is shown below.please see this and tell me what i did wrong.but there is not compile error.after i run the program it doesn't save any image.
#include"stdafx.h"
#include<cv.h>
#include<highgui.h>
#include<cxcore.h>
int main(int argc, char* argv[]) {
int c=1;
IplImage* img=0;
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromCAM(-1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
sprintf(buffer,"D:/image%u.jpg",c);
cvSaveImage(buffer,img);
c++;
if (cvWaitKey(100)== 27) break;
}
cvDestroyWindow("Video");
return 0;
}
can you tell me how to save a image .above program doesn't save any images.please give me your suggestions.thank you.
You forgot to actually save the image:
cvSaveImage(buffer ,img);
Also, the following is redundant:
IplImage* small; // <-- you don't need this
IplImage* small=new IplImage(inputArray);
Don't know if you solved the problem or not. if not you can use imwrite("test.jpg",img); to save an image,
here is an example-
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
imwrite("test.jpg",img);
}