I am trying to compile a very simple OpenCV (2.4.9) program in Visual Studio 2010 just to check whether opencv libraries have been linked properly. Here is the program code I am trying to run.
#include "stdafx.h"
#include <stdio.h>
#include <opencv2/opencv.hpp>
using namespace cv;
int main(int argc, char** argv )
{
Mat image;
image = imread( "MyPic.jpg", 1 );
if ( !image.data )
{
printf("No image data \n");
return -1;
}
namedWindow("Display Image", CV_WINDOW_AUTOSIZE );
imshow("Display Image", image);
waitKey(0);
return 0;
}
But when I press the build button, the compilation fails and shows the following error.
1>LINK : fatal error LNK1104: cannot open file 'opencv_gpu249.lib'
What the problem could be? How to solve it?
You need to add the OpenCV library path to the Visual Studio's Library Directories:
OpenCV-2.4.9-Path\build\x86\vc10\lib
or for 64bits
OpenCV-2.4.9-Path\build\x64\vc10\lib
Related
I have recently been trying to properly configure eclipse to be able to use OpenCV. After installing it to my computer, (Ubuntu, using cmake) I attempted to build some sample code from the OpenCV tutorials.
This is the sample code.
#include <cv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <highgui.h>
using namespace cv;
int main( int argc, char** argv )
{
Mat image;
image = imread( argv[1], 1 );
if( argc != 2 || !image.data )
{
printf( "No image data \n" );
return -1;
}
namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
imshow( "Display Image", image );
waitKey(0);
return 0;
}
Some additions to includes to make it work.
Everything is found properly, but when build, gives these 3 errors. (the file I am compiling is named test.cpp)
./test.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
make: *** [libOpenCV] Error 1
recipe for target 'libOpenCV' failed
I dont know why these errors are happening, or how to fix it. Anyone have any clue?
I think you need to check the link obj, opencv requires number of libraries to work properly. Pls check the detail manual on opencv website.
I installed OpenCV 2.4.10 and configured it to my Visual Studio 2010. And even I run below code in opencv(c)
My code in opencv:
#include "opencv\highgui.h"
int main(int argc, char** argv)
{
IplImage* img =cvLoadImage("d:\\1.jpg",CV_WINDOW_AUTOSIZE);
cvNamedWindow("example1", CV_WINDOW_AUTOSIZE);
cvShowImage("Example1", img);
cvWaitKey(0);
cvReleaseImage(&img);
cvDestroyWindow("Exame1");
}
and it works but when I try to use the code given here,with opencv2(c++) but it gives an error (break)
My code in opencv2:
#include "opencv2\opencv.hpp"
using namespace cv;
int main()
{
Mat image = imread("d:\\1.jpg", CV_LOAD_IMAGE_COLOR);
namedWindow("test", WINDOW_AUTOSIZE);
imshow("test", image);
waitKey(0);
return 0;
}
Error(break):
Unhandled exception at 0x7624c41f (KernelBase.dll) in o.exe: Microsoft C++ exception: cv::Exception at memory location 0x0035f63c..
Why is this error just in opencv2?!
I want to work with opencv2
You will have to verify that you are building in debug/release mode based on the build information of the opencv .dll files you are using.
I'm trying to run an Visual Studio 2013 program with OpenCV library but it doesn't work because I have an Access violation executing location. I've read other posts but it still doesn't work.
Here is full code of program:
#include "opencv2\highgui\highgui.hpp"
using namespace cv;
int main(int argc, char **argv)
{
Mat image = imread(argv[1], -1);
if (img.empty())
return -1;
namedWindow("Example", WINDOW_AUTOSIZE);
imshow("Example", img);
waitKey(0);
destroyWindow("Example");
}
Error message:
I am using CodeBlocks in my windows 7 64 bit and I use MinGw for my default c/c++ compiler.
Few days ago I need to use OpenCV, after I struggle a lot of error, I get unsolveable error like this :
The sample code:
#include "cv.h"
#include "highgui.h"
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
cvShowImage( "Example1", img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( "Example1" );
}
I believe my linked & directory setting is correct. So please help me :) I am about to give up :(
Assuming that you are doing everything correct in the code and the image, this can be a problem due to incompatible opencv binaries.
Please have a look at a similar installation to compile and see if it works. I had a similar problem in my installation, which was fixed by compiling the binaries again.
The problem is most probably a failure when loading the image. But you will only be certain if you check the return of cvLoadImage():
IplImage* img = cvLoadImage( argv[1] );
if (!img)
{
printf("!!! cvLoadImage failed\n");
}
The function fails if the image format is not supported, or if the image is not found in the specified location.
You application expects to load the file passed from the command line, so you better execute your application with: Main.exe C:\some_img.png
You can also hardcode the filename in your code:
IplImage* img = cvLoadImage("C:\\some_img.png");
if (!img)
{
printf("!!! cvLoadImage failed\n");
}
Im using Opencv 2.3.1 on Visual studio 2010 (vc10)
I have configured opencv based on many tutorials and can compile & run C-syntax program like:
#include "StdAfx.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main ()
{
IplImage* img = cvLoadImage("D:\cat_helmet.jpg", CV_LOAD_IMAGE_UNCHANGED);
cvNamedWindow("display", CV_WINDOW_AUTOSIZE);
cvShowImage("display", img );
cvWaitKey(0);
return 0;
}
However, I cannot run the C++ syntax program like
#include "StdAfx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main( )
{
namedWindow( "Display window", CV_WINDOW_AUTOSIZE );
Mat image;
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
if(! image.data )
{
cout << "Could not open or find the image" << std::endl ;
return -1;
}
imshow( "Display window", image );
waitKey(0);
return 0;
}
I got the error messages (in the function calls: namedWindow, imread, imshow)
First-chance exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
Unhandled exception at 0x5361fcc3 in FirstOpencv2.3.exe: 0xC0000005: Access violation reading location 0x2079616c.
How can I fix this?
You say that you have followed a multitude of guides and tutorials. I've had great success with this one
http://www.anlak.com/using-opencv-2-3-1-with-visual-studio-2010-tutorial/
The thing is that this guy walks you through the 'park' and helps you unravel two major issues whilst setting up OpenCV 2.3.1; one of which is placement of .dll files in your project folder. The other is a missing .dll 'tbb_debug.dll' (the absense of this .dll is considered a bug in OpenCV 2.3.1).
He also provides some decent code-snippets for your to try out (in c++ syntax).
Good luck.
The above mentioned answers doesn't make sense. I am also facing the same problem. The main reason for this exception is that you are trying to display image (read by imread) which is empty. The main problem in the program is the line
image = imread("D:\cat_helmet", CV_LOAD_IMAGE_COLOR);
I think imread function is not behaving the way it is expected. One more thing, while going through the references i came across a following link:
http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
Here, imread is used via call by reference method. I am not a C++ expert, but i feel it could be the problem.
int main()
{
std::string imgPath("splash.bmp"); //Add your file name
Mat img = imread(imgPath);
namedWindow( "Example1", WINDOW_AUTOSIZE);
imshow("Example1", img);
waitKey(0);
return 0;
}
This code worked for me. Also, I put the file next to executable to decrease complexity.