I am using OpenCV 2.4.6 in Visual Studio 2012 and I have testing one of the sample programs , name matcher_simple.cpp -- which matches two sample images , image1 and image2.
#include <stdio.h>
#include "opencv2/core/core.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/opencv.hpp"
using namespace cv;
static void help()
{
printf("\nThis program demonstrates using features2d detector, descriptor extractor and simple matcher\n"
"Using the SURF desriptor:\n"
"\n"
"Usage:\n matcher_simple <image1> <image2>\n");
}
int main(int argc, char** argv)
{
if(argc != 3)
{
help();
return -1;
}
//cv::initModule_nonfree();
Mat img1 = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE);
Mat img2 = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE);
if(img1.empty() || img2.empty())
{
printf("Can't read one of the images\n");
return -1;
}
// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
return 0;
}
On compiling I get this error :
1>------ Build started: Project: opencvreinstated, Configuration: Release x64 ------
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(void)" (??0SURF#cv##QEAA#XZ)
1>matcher_simple.obj : error LNK2001: unresolved external symbol "public: __cdecl cv::SURF::SURF(double,int,int,bool,bool)" (??0SURF#cv##QEAA#NHH_N0#Z)
1>C:\Users\motiur\documents\visual studio 2012\Projects\opencvreinstated\x64\Release\opencvreinstated.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have testing this in release mode 64 bit , I also have successfully ran simple other opencv samples , for example streaming live video . I did not have these sort of issues there . Help is appreciated . Thanks.
You have to link in the nonfree module, since this is where the Surf features are implemented.
Go to project Properties -> Linker -> Input, and add smth like opencv_nonfree246d.dll to Additional Dependencies field.
For details, please, see http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html#the-local-method
Related
This question already has answers here:
Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
(20 answers)
Closed 6 months ago.
I am using SDL2 and vcpkg.
I install sdl2 by vcpkg and build project in Visual Studio 2022 Debug x86
LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main##YAHXZ)
code:
#include "SDL2/SDL.h"
const int WINDOW_WIDTH = 640;
const int WINDOW_HEIGHT = 480;
int main(int argc, char* argv[]) {
SDL_Window* window = NULL;
SDL_Surface* surface = NULL;
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("%s\n", SDL_GetError());
}
return 0;
}
(More of a comment than a solution, but I cannot comment yet)
Have you tried the solutions proposed in this thread?
According to an answer there, the most probable solution would be that your Linker's SubSystem setting is not set to Windows:
Apart from that, there are some other potential solutions in that thread, if none of them work, please report back.
I am new to Tesseract API. Currently I am running the sample program from the Wiki on Visual Studio 2013, and the program is as follows.
#include "leptonica\allheaders.h"
#include "iostream"
#include "api\baseapi.h"
#include "stdio.h"
using namespace std;
using namespace tesseract;
int main(int argc, char** argv)
{
char* outText;
TessBaseAPI *api = new TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng"))
{
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead("/usr/src/tesseract-3.02/phototest.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image);
return 0;
}
When I compile this with VS2013, I get the following errors.
1>------ Build started: Project: OCRTest, Configuration: Debug Win32 ------
1> main.cpp
1>c:\tesseract-build\include\leptonica\pix.h(209): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\include\leptonica\pix.h(211): warning C4305: 'initializing' : truncation from 'double' to 'const l_float32'
1>c:\tesseract-build\tesseract-ocr\api\baseapi.h(32): fatal error C1083: Cannot open include file: 'platform.h': No such file or directory
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I believe I have not built the tesseract source properly, but I cannot be sure. Also, declaring
TessBaseAPI * api = new TessBaseAPI()
throws up errors such as 'type specifier expected' when cursor is moved over TessBaseAPI(). Help would be greatly appreciated, and thank you in advance!
Assuming that you are using Tesseract 3.02.02 & leptonica 1.68 library.
Follow these steps.
Remember to check Tesseract Development files option when installing Tesseract
Add below Include folders in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\include
C:\Program Files\Tesseract-OCR\include\tesseract
C:\Program Files\Tesseract-OCR\include\leptonica
Add below lib folder in Project solutions -> VC++ Directories
C:\Program Files\Tesseract-OCR\lib
Add additional dependencies in Configuration Properties -> Linker->Input ->Additional Dependencies
libtesseract302.lib
libtesseract302d.lib
liblept168.lib
liblept168d.lib
General program structure
>
> #include <baseapi.h>
> #include <allheaders.h>
> #include <iostream>
>
> using namespace std;
>
> int main(void)
> {
> tesseract::TessBaseAPI api;
> //...
> }
>
>
Actually the coding below is what I tried to execute. When I tried to execute this using Microsoft Visual Studio 2012, there is an error.
Error error LNK2019: unresolved external symbol _cvPyrSegmentation referenced in function "void __cdecl START_SEGMENT(int)" (?START_SEGMENT##YAXH#Z)
Error error LNK1120: 1 unresolved externals
But I asked my friend to execute this code using his laptop, it works just fine.No error. But he is using Microsoft Visual Studio 2010 instead of me using Visual Studio 2012..I wonder why there is an error when I execute this code but when my friend execute it, no error.
So I removed some header and the coding looks like the one that I ask from the beginning( from this Question.The one with ""Error error C3861: 'cvPyrSegmentation': identifier not found ""..
After I removed some header, there is no more Error LNK1120. But there is ""Error error C3861: 'cvPyrSegmentation': identifier not found""...
Blank ...Too many error for a newbie.Learning process never be easy .yeahhh!
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/legacy/legacy.hpp>
#include <stdio.h>
static void help(void)
{
printf("\nThis program present the function of pyramid segmentation which is
cvcvPyrSegmentation()\n""we can controlled the value of threshold by creating
the taskbar\n""Usage :\n");
}
IplImage* image[2] = { 0, 0 }, *image0 = 0, *image1 = 0;
CvSize size;
int w0, h0,i;
int threshold1, threshold2;
int l,level = 4;
int sthreshold1, sthreshold2;
int l_comp;
int block_size = 1000;
float parameter;
double threshold;
double rezult, min_rezult;
int filter = CV_GAUSSIAN_5x5;
CvConnectedComp *cur_comp, min_comp;
CvSeq *comp;
CvMemStorage *storage;
CvPoint pt1, pt2;
static void START_SEGMENT(int a)
{
(void) a;
cvPyrSegmentation(image0, image1, storage, &comp, level, threshold1+1,
threshold2+1);
cvShowImage("Segmentation", image1);
}
int main( int argc, char** argv )
{
char* filename;
help();
filename = argc == 2 ? argv[1] : (char*)"C:/Users/acer/Documents/Visual Studio
2012/Projects/me2.jpg";
if( (image[0] = cvLoadImage( filename, 1)) == 0 )
{
help();
printf("Cannot load fileimage - %s\n", filename);
return -1;
}
cvNamedWindow("Source", 0);
cvShowImage("Source", image[0]);
cvNamedWindow("Segmentation", 0);
storage = cvCreateMemStorage ( block_size );
image[0]->width &= -(1<<level);
image[0]->height &= -(1<<level);
image0 = cvCloneImage( image[0] );
image1 = cvCloneImage( image[0] );
// segmentation of the color image
l = 1;
threshold1 =255;
threshold2 =30;
START_SEGMENT(1);
sthreshold1 = cvCreateTrackbar("Threshold1", "Segmentation", &threshold1, 255,
START_SEGMENT);
sthreshold2 = cvCreateTrackbar("Threshold2", "Segmentation", &threshold2, 255,
START_SEGMENT);
cvShowImage("Segmentation", image1);
cvWaitKey(0);
cvDestroyWindow("Segmentation");
cvDestroyWindow("Source");
cvReleaseMemStorage(&storage );
cvReleaseImage(&image[0]);
cvReleaseImage(&image0);
cvReleaseImage(&image1);
return 0;
}
#ifdef _EiC
main(1,"pyramid_segmentation.c");
#endif
Having fixed your compilation problem, you now have a linker problem.
You need to follow the instructions in the OpenCV documentation to find out how to link their libraries to your binary.
You'll start with -lcv and potentially have to add some additional libraries.
I work on Windows7 x64 in c++ language.
I created a project that open firefox browser when I show a marker to my web cam, using ShellExecuteEx function. My project works well with visual studio 2010.
But, when I try to run my project with Qt Creator, I get this error:
main_cam.obj:-1: error: LNK2019: riferimento al simbolo esterno __imp__ShellExecuteExW#4 non risolto nella funzione _main
debug\cam.exe:-1: error: LNK1120: 1 esterni non risolti
The code is:
#include <iostream>
#include <stdio.h>
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <windows.h>
#include <ShellAPI.h>
include [...]
int main () {
[...]
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = "firefox.exe";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
[...]
if (condition_is_verified) {
ShExecInfo.lpParameters = (LPCWSTR)"www.google.it";
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
}
[...]
}//end main
I think problem is shell32.lib . If it is, I haven't this library in my pc. how can I fix it?
Can you help me?
Thanks in advance!
It is very simple. Just right click the the project pro file and add external library. Choose system library, static and give the path of shell32.lib which is
C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
This is my solution to this problem :
in the .pro file : INCLUDEPATH += "C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib"
( the path to the file shellAPI.lib )
in my mainwindow.h :
#define NOMINMAX // You have to do this for windows.h to work, else u'll get mistakes with datetime.h
#include <windows.h> // (without the space)
#pragma comment(lib, "Shell32.lib")
#include <ShellAPI.h> // without space also
I have installed opencv with macports following the directions here: Compile OpenCV (2.3.1+) for OS X Lion / Mountain Lion with Xcode
I have also search and tried every other variation of this on stackexchange and google, but this seems to get me closest.
It seems to work for some things, but not for sample code that ships with 2.4.2. Note that I have added ALL opencv 2.4.2 dylibs Link Binary with Libraries.
For example, the following will compile and run:
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
int main ( int argc, char **argv )
{
cvNamedWindow( "My Window", 1 );
IplImage *img = cvCreateImage( cvSize( 640, 480 ), IPL_DEPTH_8U, 1 );
CvFont font;
double hScale = 1.0;
double vScale = 1.0;
int lineWidth = 1;
cvInitFont( &font, CV_FONT_HERSHEY_SIMPLEX | CV_FONT_ITALIC,
hScale, vScale, 0, lineWidth );
cvPutText( img, "Hello World!", cvPoint( 200, 400 ), &font,
cvScalar( 255, 255, 0 ) );
cvShowImage( "My Window", img );
cvWaitKey();
return 0;
}
However, when I try to build any of the samples, such as the display_image.cpp, example, as follows, I get link errors.
-DOES NOT WORK-
#include <stdio.h>
#include <iostream>
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/flann/miniflann.hpp"
using namespace cv; // all the new API is put into "cv" namespace. Export its content
using namespace std;
using namespace cv::flann;
static void help()
{
cout <<
"\nThis program shows how to use cv::Mat and IplImages converting back and forth.\n"
"It shows reading of images, converting to planes and merging back, color conversion\n"
"and also iterating through pixels.\n"
"Call:\n"
"./image [image-name Default: lena.jpg]\n" << endl;
}
int main(int argc, char *argv[])
{
help();
const char* imagename = argc > 1 ? argv[1] : "lena.jpg";
Mat img = imread(imagename); // the newer cvLoadImage alternative, MATLAB-style function
if(img.empty())
{
fprintf(stderr, "Can not load image %s\n", imagename);
return -1;
}
if( !img.data ) // check if the image has been loaded properly
return -1;
Mat img_yuv;
cvtColor(img, img_yuv, CV_BGR2YCrCb); // convert image to YUV color space. The output image will be created automatically
vector<Mat> planes; // Vector is template vector class, similar to STL's vector. It can store matrices too.
split(img_yuv, planes); // split the image into separate color planes
imshow("image with grain", img);
waitKey();
return 0;
}
I get the following errors:
Undefined symbols for architecture x86_64:
"cv::split(cv::Mat const&, std::__1::vector<cv::Mat, std::__1::allocator<cv::Mat> >&)", referenced from:
_main in main1.o
"cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
_main in main1.o
"cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
_main in main1.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea how to resolve this?
I had the same problem. A build setting default seems to be different in Xcode 4.5.
Under "Build Settings"--> Apple LLVM compiler 4.1 - Language >
C++ Standard Library:=
Change from libc++ (LLVM ...) to libstdc++ (GNU C++ ...).
It's very likely that OpenCV has not been compiled with C++11 settings, while the program is.
Set the build of your tool without C++11 switches (i.e. -std=c++11 -stdlib=libc++).
Try to manually add the directory where port puts all the dylibs (/opt/local/lib if I'm not getting wrong) in Build Settings->Library search path. This should fix the linking problem.