Setup OpenCV-2.3 for Visual Studio 2010 - c++

I'm trying to use opencv 2.3 with Visual Studio 2010 Express. My code is from example:
#include "stdafx.h"
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
int c;
// allocate memory for an image
IplImage *img;
// capture from video device #1
CvCapture* capture = cvCaptureFromCAM(1);
// create a window to display the images
cvNamedWindow("mainWin", CV_WINDOW_AUTOSIZE);
// position the window
cvMoveWindow("mainWin", 5, 5);
while(1)
{
// retrieve the captured frame
img=cvQueryFrame(capture);
// show the image in the window
cvShowImage("mainWin", img );
// wait 10 ms for a key to be pressed
c=cvWaitKey(10);
// escape key terminates program
if(c == 27)
break;
}
return 0;
}
What have I done so far?
Added build\bin and one of build\{x86|x64}\{vc9\vc10\mingw}\bin to my system path (to use DLLs).
Added build\{x86|x64}\{vc9\vc10\mingw}\lib or build\{x86|x64}\{vc9\vc10\mingw}\staticlib as library directories to my linker settings.
Added build\include and build\include\opencv as include directories to my compiler settings.
And the result is:
1>LINK : fatal error LNK1104: cannot open file 'c:\OpenCV2.3\build\x86\vc10\lib.obj'
There's no lib.obj in OpenCV folders. I've only unziped OpenCV-2.3.0-win-superpack.exe, without using CMake software.
What am I doing wrong?

Well, the official guide is for installing OpenCV 2.1 on VS2010, so I wrote some instructions below that shows how to properly install and configure the x86 version of OpenCV 2.3 on Visual Studio 2010 (Express), since a lot of folks seem to have problems setting it up correctly.
Download OpenCV-2.3.0-win-superpack.exe and execute it to extract all files to a folder named OpenCV2.3. Inside this folder there are 2 directories: build and opencv. All the setup on VS2010 will refer to the build directory. For practical purposes I moved the folder OpenCV2.3 to my C:\ drive, so pay attention to the paths I suggest on this guide as yours might be different.
On Visual Studio, create a new Win32 Console Application project and name it whatever you like. After that, a new window will show up. Click on the tab Application Settings and make sure the option Empty Project gets selected:
Add a new file main.cpp to the folder Source Files, then add this code to main.cpp:
#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;
}
At this point, we need to configure the project so it can locate OpenCV headers and libraries. Go to the Project Properties (ALT+F7), and once the new window shows up do the following:
On the Configuration box, select All Configurations
Open Configuration Properties > C/C++ > General, and edit the field Additional Include Directories to add these 3 paths (for the headers):
C:\OpenCV2.3\build\include\opencv
C:\OpenCV2.3\build\include\opencv2
C:\OpenCV2.3\build\include
Note that include\opencv is for the C interface of OpenCV and include\opencv2 if for the C++ interface. We are also adding the folder include to prevent our build from being broken by some headers of the C interface that refer to C++ headers as opencv2\core.
Then, add the path of the libraries on Configuration Properties > Linker > General, and on the Additional Library Directories field, add this: C:\OpenCV2.3\build\x86\vc9\lib:
Finally, for this simple test we are going to add the libraries opencv_core230.lib and opencv_highgui230.lib. So go to Configuration Properties > Linker > Input and add them:
When writing more complex applications you'll probably need to add other OpenCV libs that I did not
mentioned on this little project of ours.
Press F7 to Build Solution and you should see:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
To be able to execute the application you'll need to modify the PATH environment variable of your system to add the location of OpenCV's DLLs. Add this to end of PATH:
; C:\OpenCV2.3\build\x86\vc9\bin

If you are struggling with editing the PATH environment variables, you can also copy the required .dll files to your project folder:
The dll files are located in this folder ../OpenCV2.3/build.x86/vc9/bin
Then copy them to the folder where .exe file is created:
c:\Users\PIMMES\Documents\Visual Studio 2010\Projects\eigenfaces\Debug (Ofcourse you have to change the path to your Debug folder)
You only have to copy the .dll files which you are using in your project (#include for example) For example if you get an error message saying opencv_core231d.dll is not found then get this .dll file from the above location (bin folder) and copy to your project Debug folder.
Hope this helps..

Whenever I make a program that uses opencv 2.2 or greater I include everything, and then comment out the libraries I don't need. Try this, I'm sure you need more than highgui.h
#include "opencv2\opencv.hpp"
using namespace cv;
//#pragma comment(lib, "opencv/opencv_calib3d231.lib")
//#pragma comment(lib, "opencv/opencv_contrib231.lib")
#pragma comment(lib, "opencv/opencv_core231.lib")
//#pragma comment(lib, "opencv/opencv_features2d231.lib")
//#pragma comment(lib, "opencv/opencv_flann231.lib")
//#pragma comment(lib, "opencv/opencv_gpu231.lib")
//#pragma comment(lib, "opencv/opencv_haartraining_engine.lib")
#pragma comment(lib, "opencv/opencv_highgui231.lib")
//#pragma comment(lib, "opencv/opencv_imgproc231.lib")
//#pragma comment(lib, "opencv/opencv_legacy231.lib")
//#pragma comment(lib, "opencv/opencv_ml231.lib")
#pragma comment(lib, "opencv/opencv_objdetect231.lib")
//#pragma comment(lib, "opencv/opencv_ts231.lib")
//#pragma comment(lib, "opencv/opencv_video231.lib")

Related

Import .lib file in vs 2019 not working for me

i downloaded libvnc library and compiled it.
Now i have vncclient.lib and vncserver.lib.
How can i import in vs 19 ?
I tried this way:
Property - Linker - Input and put in Additional Dependencies the folder of the .lib file.
After in main i write this.
#pragma comment(lib, "vncclient.lib")
#pragma comment(lib, "vncserver.lib")
if i compile program found the library but if i try some code like
#include <rfb.h>
int main(int argc, char** argv)
{
rfbScreenInfoPtr server = rfbGetScreen(&argc, argv, 400, 300, 8, 3, 4);
server->frameBuffer = malloc(400 * 300 * 4);
rfbInitServer(server);
rfbRunEventLoop(server, -1, FALSE);
the compiler marks me as an error and cannot find the data, what am I doing wrong?
"Additional dependencies" is for actual .lib files, if you want to add an entire path do it on either the "VC++ Directories" page or in the Linker->General page's "Additional library directries" line.
If you want this library to be available to all projects you build I suggest you add it to the user property page (available through the View->Other Windows->Property Manager menu item), expand the build configurations and select properties from the right click menu of the Microsoft.Cpp..User items.

Fatal error in starting up OpenCV 2.4.6 on VS 2008, file not found

I am using this tutorial to get started with OpenCV 2.4.6 on VS 2008:
http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html
I followed all instructions (my OpenCV is not in the default Program Files (x86) folder, it's in
C:\opencv_built
Unlike in the tutorial, I put very simple code, just to make sure all included files are reachable and if it builds successfully etc:
#include "stdafx.h"
#include <iostream> // for standard I/O
#include <string> // for strings
#include <iomanip> // for controlling float print precision
#include <sstream> // string to number conversion
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using namespace std;
using namespace cv;
double getPSNR ( const Mat& I1, const Mat& I2);
Scalar getMSSIM( const Mat& I1, const Mat& I2);
int main(int argc, char *argv[])
{
return 0;
}
But I get a fatal error when I try to build:
fatal error C1083: Cannot open include file: 'opencv2/imgproc/imgproc.hpp': No such file or directory c:\Users\Administrator\Documents\Visual Studio 2008\Projects\firstopencv\firstopencv\firstopencv.cpp 17
This is obviously referring to this line:
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
I don't know where to find the dll files, or what to do next? I know this must be really easy but I've searched for any of the dll files, eg.
opencv_core243d.lib
but I get no search results.
1. Check your path to \vc10 folder. It should be either:
C:\opencv_built\build\x86\vc10
or
C:\opencv_built\x86\vc10
2. Go to
Start>Edit environment variables for your account>Under System variables > New...
Variable Name: OPENCV_DIR
Variable Value: Insert your path from step 1 here.
3. Open Visual Studio, make new project, go to Property Pages
4. Under C/C++ > Additional Include Directories
Insert $(OPENCV_DIR)\..\..\include
5. Under Linker > General > Additional Include Directories
Insert $(OPENCV_DIR)\lib
6a. (For DEBUG property!) Under Linker > Input > Additional Dependencies
Insert
opencv_core246d.lib
opencv_imgproc246d.lib
opencv_highgui246d.lib
opencv_ml246d.lib
opencv_video246d.lib
opencv_features2d246d.lib
opencv_calib3d246d.lib
opencv_objdetect246d.lib
opencv_contrib246d.lib
opencv_legacy246d.lib
opencv_flann246d.lib
6b. (For RELEASE property!) Under Linker > Input > Additional Dependencies
Insert
opencv_core246.lib
opencv_imgproc246.lib
opencv_highgui246.lib
opencv_ml246.lib
opencv_video246.lib
opencv_features2d246.lib
opencv_calib3d246.lib
opencv_objdetect246.lib
opencv_contrib246.lib
opencv_legacy246.lib
opencv_flann246.lib
This should be enough. If you get missing .dll window after running code, copy desired .dll from your C:\opencv_built\build\x86\vc10\bin or C:\opencv_built\x86\vc10\bin to your project folder.
It's not a dll file, it's a header file. The file is called imgproc.hpp
If you compiler can't find it it's either because it isn't there, or it's because you haven't told your compiler where to find it.
The important part for VS is the “Additional Include Directories”, look at that part again on the web page you followed.
Okay the fix was this:
Under Linker -> General -> Additional Library Dependencies
I put:
C:\opencv_built\lib\Debug

Microsoft Visual Studios 2012 Can't open "python33.lib"

I'm using the Boost libraries in MicroSoft Visual Studios 2012 for a C++ program that is going to have Python embedded into it. The problem is when I try to Build Solution [F7]; I get this ::
Error 1 error LNK1104: cannot open file 'python33.lib' C:\Users\usr\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\LINK
The problem is, I have no idea what this is, means, or any clue of how to fix it.
I have already tried to move my python folder into my Desktop, as it was originally in the C:\, I thought maybe it was a permissions error, but that didn't do anything.
Here is my code from a tutorial that I was reading in preparation for the porject::
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <boost/lambda/lambda.hpp>
#include <boost/python.hpp>
using namespace boost::python;
int main( int argc, char ** argv ) {
try {
Py_Initialize();
object main_module((
handle<>(borrowed(PyImport_AddModule("__main__")))));
object main_namespace = main_module.attr("__dict__");
handle<> ignored(( PyRun_String( "print \"Hello, World\"",
Py_file_input,
main_namespace.ptr(),
main_namespace.ptr() ) ));
} catch( error_already_set ) {
PyErr_Print();
}
}
--Visual Studios 2012
--Windows 7 x64
--Python 3.3.2
--Boost libraries
--Python Embedded C++ program
--Link to tutorial page:: http://wiki.python.org/moin/boost.python/EmbeddingPython
Thanks for all the help David.
For anyone else who runs into this problem, here's what you need to do.
Right click on the Project name (ConsoleApplication1, ect) and under C/C++ general insure that your additional include directories include youe python include, Lib, and libs folders. As well as the boost root and the boost lib(32/64) folder.
Under the linker menu, in the input sub catagory, for additional dependencies, you'll need to add this into there.
C:\Python33\libs\python33.lib
C:\boost_1_54\lib32-msvc-11.0\boost_python-vc110-mt-gd-1_54.lib
Or whatever your install directory is. As well as any other required files.
Once that's done your project should build.
Once you're ready to run it you'll need to copy whatever .dll files are needed into the folder where the executable is built.

OpenCV (CvHaarClassifierCascade*) cvLoad doesn't load, unable to load xml file

I'm trying face detection using OpenCv 2.3. My trying to load "haarcascade_frontalface_alt_tree.xml" on my project, I'm constantly unable to load the xml file.
CvHaarClassifierCascade * pCascade = 0; // the face detector
const char* file ="C:\OpenCV2.3\opencv\data\haarcascades\haarcascade_frontalface_alt_tree.xml" ;
pCascade = (CvHaarClassifierCascade*) cvLoad(file , NULL, NULL, NULL);
if (!pCascade) {
exit(-1); // unable to load xml
}
I believe that I'm experiencing the same problem as this problem.
I have tried to load an image before the cvLoad command, but it didn't help.
I'm using OpenCV 2.3, made my configuration just like in this tutorial.
I'm using those libraries (I presume my configurations are correct, the file exist and can be open using Notepad++).
#include <stdio.h>
#include "opencv2\opencv.hpp"
#include "cv.h"
#include "highgui.h"
//#include "cvaux.h"
using namespace cv;
#pragma comment(lib, "opencv_core230d.lib")
#pragma comment(lib, "opencv_highgui230d.lib")
//#pragma comment(lib, "opencv_contrib230d.lib")
//#pragma comment(lib, "opencv_calib3d230d.lib")
//#pragma comment(lib, "opencv_features2d230d.lib")
//#pragma comment(lib, "opencv_flann230d.lib")
//#pragma comment(lib, "opencv_gpu230d.lib")
#pragma comment(lib, "opencv_haartraining_engined.lib")
#pragma comment(lib, "opencv_imgproc230d.lib")
//#pragma comment(lib, "opencv_legacy230d.lib")
//#pragma comment(lib, "opencv_ml230d.lib")
//#pragma comment(lib, "opencv_objdetect230d.lib")
//#pragma comment(lib, "opencv_video230d.lib")
To narrow down the issue, before calling cvLoad you should check to see if the file exists. Here's one way:
struct stat buf;
int statResult = stat(file,&buf);
if (statResult || buf.st_ino < 0) {
cout << "File not found: " << file << endl;
exit(-2);
}
You'll need to #include <sys/stat.h>
On my system (OS X 10.6.8/OpenCV 2.3), when I attempt to load haarcascade_frontalface_alt_tree.xml or haarcascade_frontalface_alt.xml I get an exception:
OpenCV Error: Unspecified error (The node does not represent a user object (unknown type?)) in cvRead, file /Users/steve/Development/opencv2/opencv/modules/core/src/persistence.cpp, line 4857
I think you are using an outdated OpenCV 1 tutorial that doesn't work with the current version of haarcascade_frontalface_alt_tree.xml. Try this OpenCV 2 tutorial instead. This code from that tutorial works for me:
CascadeClassifier face_cascade;
if (!face_cascade.load( file) ) {
cout << "Couldn't load face_cascade" << endl;
exit(-1);
}
cout << "Loaded face_cascade" << endl;
It happens also to me but finally I think I found the problem.
OpenCV has two different libraries *d.lib and *.lib the d means debug.
The problem is you need to setup the proper libraries to your environment (vs in my case) in the proper mode.
d.lib when you are in debug and .lib when you are in release.
Also in my project I need to run it in Release mode to make it work :)
This setup in my vs2009 could be found under Properties, Linker, Input, Additional dependencies.
Best regards
Check that the string with the "haarcascade_frontalface_alt.xml" file name is correct.
I had this problem and the directory separater was not being recognised. I changed the '\' character to '/' and the tutorial worked.
For your info, I was using MacOS 10.8.3 running Parallels with Windows 7, Visual Studio 2012 and opencv 2.44 - I was using the version 2 of the tutorial

Difficulties configuring openCV library in Visual C++

I'm trying to configure my Visual C++ to use the openCV libraries. I've followed the instructions on OpenCV website http://opencv.willowgarage.com/wiki/VisualC%2B%2B...
// OpenCV_Helloworld.cpp : Defines the entry point for the console application.
// Created for build/install tutorial, Microsoft Visual Studio and OpenCV 2.2.0
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int _tmain(int argc, _TCHAR* argv[])
{
// Open the file.
IplImage *img = cvLoadImage("photo.jpg");
if (!img) {
printf("Error: Couldn't open the image file.\n");
return 1;
}
// Display the image.
cvNamedWindow("Image:", CV_WINDOW_AUTOSIZE);
cvShowImage("Image:", img);
// Wait for the user to press a key in the GUI window.
cvWaitKey(0);
// Free the resources.
cvDestroyWindow("Image:");
cvReleaseImage(&img);
return 0;
}
I have altered the include and library directories in VC++ directories inside the Property Pages, and have added the additional dependencies. However, when I try and load an image with the same header files as the sample code, it says that cvLoadImage is undefined, as is cvNamedWindow
IplImage *img = cvLoadImage("JellyFish.jpg");
Any suggestions as to where I might have my problem?
You might try making sure your Code Generation for your project is Multi-threaded DLL (or Multi-threaded Debug DLL).
You need to configure using CMake. Get OpenCV 2.2 and try the following step by step guide.
http://kaushalsolanki.com/2011/01/compile-and-set-up-opencv-for-visual-studio-2010-with-64-bits-support-ipp-7-0-and-tbb/
I encountered the same error but i finally fixed it
I am using opencv 2.3
what I did was I changed all the additional dependencies
from opencv_core220d.lib to opencv_core231d.lib
we need to change all of the dependencies in the same way
and then i copied all the *.dll files from my bin>>debug folder to
where i had new project that is
helloworld>>helloworld
for example
C:\opencv\build\bin\debug copy all *.dll files to
C:\opencv\Projects\helloworld\helloworld