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.
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 am using C920 Logitech Web camera for the object recognition project .
I want to use my own H264 decoder for decoding the compressed stream from camera (Not caring about the performance and timing as of now which will be affected by my H264 decoder).
I want to hack the bool VideoCapture::retrieve(Mat& image, int channel=0) and replace the decoder call of the opencv retrive() function by my H264 decoder .
I took care about the return type as well as parameter list of the both decoder function (BOTH ARE SIMILAR).
But I am facing below problem in integrating/modifying my sample code .
So my queries are below :
I am using OPENCV 3.0 VERSION .
Q.1) With below sample code, am getting errors-
#include "precomp.hpp"
#include "opencv2/opencv.hpp"
#include <strmif.h>
#include <iostream>
using namespace std ;
using namespace cv;
struct _AMMediaType;
typedef _AMMediaType AM_MEDIA_TYPE;
DEFINE_GUID(FORMAT_VideoInfo,0x05589f80,0xc356,0x11ce,0xbf,0x01,0x00,0xaa,0x00,0x55,0x59,0x5a);
DEFINE_GUID(MEDIATYPE_Video,0x73646976,0x0000,0x0010,0x80,0x00,0x00,0xaa,0x00,0x38,0x9b,0x71);
DEFINE_GUID(MEDIASUBTYPE_RGB24,0xe436eb7d,0x524f,0x11ce,0x9f,0x53,0x00,0x20,0xaf,0x0b,0xa7,0x70);
int main(int, char**)
{
int t1= 10;
int t2= 10;
VideoCapture cap(0); // open the default camera
cap.set(3,1280);
cap.set(4,800);
AM_MEDIA_TYPE mt;
ZeroMemory(&mt,sizeof(AM_MEDIA_TYPE));
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;
if(!cap.isOpened()) // check if we succeeded
return -1;
for(;;)
{
Mat frame;
if( !cap.grab() )
{
cout << "Can not grab images." << endl;
return -1;
}
cap.retrieve(frame);
imshow("cameracapture", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
I am getting below linker errors :
1>main.obj : error LNK2001: unresolved external symbol FORMAT_VideoInfo
1>main.obj : error LNK2001: unresolved external symbol MEDIATYPE_Video
1>main.obj : error LNK2001: unresolved external symbol MEDIASUBTYPE_RGB24
I linked all lib in my project properties (by using VS2012),But no luck :(
Q.2) In OpenCV3.0\modules\videoio\src\cap_dshow.cpp file :
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_RGB24;
mt.formattype = FORMAT_VideoInfo;
As my LOGITECH C920 camera is supporting H264 codec, so I tried to modify the the above variables and added below lines of code in my sample code-
mt.majortype = MEDIATYPE_Video;
mt.subtype = MEDIASUBTYPE_H264;
mt.formattype = FORMAT_VideoInfo;
I got below error :
main.obj :error C2065: 'MEDIASUBTYPE_H264' : undeclared identifier
What modifications required to get the H264 compressed video
Q-3) If I will modify the OpenCV code itself, then How I can build the complete OPENCV3.0 code(with my modification in windows with VS2012) and use it for my purpose ??
You need to define INITGUID to resolve mentioned linker errors (see Referencing GUIDs for details).
However I don't see how it is going to help you in the part of supplying your H.264 decoder (too far from there).
To reference H.264 subtype identifier you need
#include <wmcodecdsp.h>
#pragma comment(lib, "wmcodecdspuuid.lib")
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!!
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;
}
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?