OpenCV doesn't work with Visual Studio - c++

I just installed openCV ver. 3.00 beta on my computer and I'm trying to test it with VS2013. I followed quick start guide:
1) Installation for windows, using pre-build libraries.
2) OpenCV inside Microsoft VS, using local method and x64/vc12 directory for libraries.
As a result, their example(listed in link #2) produced an error:
#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/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], 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;
}
The output is:
1>------ Build started: Project: test_openCV, Configuration: Debug Win32 ------
1>LINK : fatal error LNK1104: cannot open file 'opencv_calib3d300d.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
As far as I understand, my program can see openCV libraries, but for some reason cannot open them. Please help.
Thanks
Update: Tried to do what was recommended in first four comments, no result still. So I will post here full information:
Project: CUDA 6.5 (I need to work with CUDA).
Source file: Source.cpp
Mode: Debug, x64.
Enviromental variables:
OPENCV_DIR: C:\programs\misha\opencv\build\x64\vc12
Path (the last string): %OPENCV_DIR%\bin
Page Properties:
C\C++ -> General -> Additional Include Directories(last string):
$(OPENCV_DIR)\..\..\include
Linker -> General -> Additional Library Directories(last string):
$(OPENCV_DIR)\lib
Linker -> Input -> Additional Dependencies:
opencv_calib3d300d.lib
opencv_core300d.lib
opencv_features2d300d.lib
opencv_flann300d.lib
opencv_highgui300d.lib
opencv_imgcodecs300d.lib
opencv_imgproc300d.lib
opencv_ml300d.lib
opencv_objdetect300d.lib
opencv_photo300d.lib
opencv_shape300d.lib
opencv_stitching300d.lib
opencv_superres300d.lib
opencv_ts300d.lib
opencv_video300d.lib
opencv_videoio300d.lib
opencv_videostab300d.lib
Output:
1>------ Build started: Project: test_openCV, Configuration: Debug x64 ------
1>LINK : fatal error LNK1104: cannot open file 'opencv_calib3d300d.lib'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So, I cannot build x64 project for some reason. Error is the same.
Update 2: If you can build this example (or any example with OpenCV), can you please send it on genkin#physics.msu.ru? I will figure it out by myself

Unfortunately that solution did not work for me.
I made it work by adding as additional dependencies(Linker -> Input -> Additional Dependencies:) only those libraries located in my $(OPENCV_DIR)\lib folder. Namely: opencv_ts300d.lib;opencv_world300d.lib.

After a long time of different attempts, I found the answer here. For x64 project, in addition to what I did above, you have to:
1) Restart your PC after setting enviromental variables. Variable Path was not updated on my computer without restart.
2) In addition to libraries added above, you have to add (although, for this example some of them might not be used):
ippicvmt.lib
IlmImfd.lib
libtiffd.lib
libpngd.lib
libjasperd.lib
libjpegd.lib
libwebpd.lib
zlibd.lib
comctl32.lib
Edit: I recently had to install it again on a new PC. As user1060873 pointed out, you have to add only the libraries located in your $OPENCV$/lib folder. For example, on my PC it is C:\opencv\build\x64\vc12\lib. Note, that for debug mode you should add opencv_world310d.lib, and for release opencv_world310.lib

I'm also facing the same problem. I am using win7 x64 with VS2015 and OpenCV 3.2
After several hours of struggling I finally found out the answer. Each version is not the same, and there may be some differences. So this is what I did :
Find where your libraries are for Additional Library, it is located on $OPENCV$/lib folder
ONLY put those is $OPENCV$/lib folder into the Additional Library (Project properties, Configuration Properties, Linker, Input). In my case I put opencv_world300d.lib (according to official tutorial which is not up to date!) into my Additional Library. But after I check the library folder, there is opencv_world320d.lib, so instead of 300 I write 320.

Solved this problem by unchecking the "inherit from parent or project defaults" checkbox under Linker->Input->Additional Dependencies
I added "opencv_world300d.lib" since Im using opencv 3.0.0 build x64 vc11

Related

Trying to build mysql-connector-cpp on Windows

I want to be able to build mysql-connector/c++ applications in debug mode (VS2k17), and understand the only way I can do that is to first build mysql-connector-cpp from source on my computer (Windows 10/64bit). I tried the following:
cmake . -DWITH_SSL=C:\Users\Rawb\source\libraries\OpenSSL-Win64
and it looks to complete successfully ...
Install location: C:/Users/Rawb/MySQL/MySQL Connector C++ 8.0
Connector libraries will be installed at: lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/Rawb/source/repos/mcc2/mysql-connector-cpp
but when I run the following cmake build ...
cmake --build . --config
it fails with this output ...
LINK : fatal error LNK1104: cannot open file 'ssleay32.lib' [C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj]
Done Building Project "C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj" (default targets) -- FAILED.
Done Building Project "C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\ALL_BUILD.vcxproj" (default targets) -- FAILED.
Build FAILED.
"C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\ALL_BUILD.vcxproj" (default target) (1) ->
"C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj" (default target) (10) ->
(Link target) ->
LINK : fatal error LNK1104: cannot open file 'ssleay32.lib' [C:\Users\Rawb\source\repos\mcc2\mysql-connector-cpp\connector.vcxproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:14.57
What might I be doing wrong? Do I just need to place the ssleay32.lib file somewhere? I do have a copy of it but not sure how it should be included. Or is it more complex? I.e. Do I need to build Open SSL first on my machine as well? This is a deep rabbit hole for me, I may be in over my head haha!
NOTE: I also asked this question on reddit with no luck, so hoping someone here might know.
If you're using MSVS (any version, including MSVS 2017), then I'd suggest using "NMake" (instead of cmake). Or just create a new C/C++ library project in the MSVS IDE.
The flag you're looking for is /LIBPATH. I don't think you need "-D", but you certainly need "/LIBPATH".
Here are the MSVS linker options:
https://learn.microsoft.com/en-us/cpp/build/reference/linker-options?view=vs-2017
Finally, you might be able to do all the troubleshooting/tracing you want without actually debugging (and rebuilding) the connector code.
Here's how to enable tracing in the MySQL Connector:
https://dev.mysql.com/doc/connector-cpp/1.1/en/connector-cpp-debug-tracing.html
Please let me know if this helps.

Building vcxproj file gives me a informationless error "The system cannot find the path specified"

When I build a project in vs 2017, I can get errors like this:
1>------ Build started: Project: TortoiseGitMerge, Configuration: Debug Win32 ------
1>Performing Custom Build Tools
1>The system cannot find the path specified.
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 3.
1>Done building project "TortoiseMerge.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 10 up-to-date, 0 skipped ==========
In this error message, there is no information leading me closer to a solution.
Which path was specified?
How do I find out? What is the exact reason that the path in question was not written in that error message?
Performing Custom Build Tools
That isn't enough to know what is going on. You'll want to jack up the build verbosity so you can see these custom build commands getting executed. Finding the one that failed then gives you a shot at diagnosing the mishap.
Use Tools > Options > Projects and Solutions > Build and Run, "MSBuild project build output verbosity" = Detailed. The build trace you now see in the Output window gets a lot more chatty and should show the actual command that fell over.

Failed to use imwrite() in Qt Creator in Debug mode

I used imwrite() function in Qt Creator. I failed to run the code in Debug mode,while successfully in Release mode.
I wrote a test program.The followings is what I have done:
First to use OpenCV, I added the following code in .pro:
INCLUDEPATH+=D:\Work_Software\OpenCV3.1\opencv\build\include
LIBS+=D:\Work_Software\OpenCV3.1\opencv\build\x64\vc12\lib\*.lib
Then I added a Push Button. The slot function is:
void MainWindow::on_pushButton_clicked()
{
Mat img;
img=imread("F:\\My_Desktop\\foot1.jpg",0);
imwrite("F:\\My_Desktop\\result.jpg",img);
namedWindow("test");
imshow("test",img);
waitKey(0);
}
Finally, in Release mode, I can successfully read and write the image. However, failed to write in Debug mode. The error information is:
UPDATE
imread works in debug mode, for example, I change the slot function into:
void MainWindow::on_pushButton_clicked()
{
Mat img;
img=imread("F:\\My_Desktop\\foot1.jpg",0);
namedWindow("test");
imshow("test",img);
waitKey(0);
imwrite("F:\\My_Desktop\\result.jpg",img);
}
I can successfully load and imshow the image in Debug mode, but when I closed the windows, the same error happened.
The content of lib folder:
I have just seen a problem like mine similar problem , but it could not fix mine.
It happens because you included all library using *.lib command. In debug mode if you links with release libraries it fails. It works in release mode cause it links with release libs as it comes first due to string sort. See the image
Here 2411d.lib stands for debug library and 2411.lib stands for release library. I faced this issue and fixed separate linking in debug & release mode. You can either make 2 folders of debug and release libraries or you can mention the library names instead of *.lib.
[change the version for you]
Debug link: LIBS+=D:\Work_Software\OpenCV2.411\opencv\build\x64\vc12\lib\*‌​d.lib
Release link: LIBS+=D:\Work_Software\OpenCV2.411\opencv\build\x64\vc12\lib\*‌​2411.lib
OR
To separate folder See the images:
Folder stucture:
Debug Library folder:
Release Library folder:
UPDATE
If opencv is not built with qt properly please follow link
OpenCV dll and lib files are differ in terms of CPU architecture (32-64 bit) and Debug-Release mode. if you switch to Debug mode you must use dll and lib files for Debug mode (depends on CPU architecture).

The program can't start because opencv_core2410d.dll is missing

I installed visual studio 2012.i have windows 8.1.then i extract opencv 2.4.10 in c partition.
Created the visual C++ project->win32 Console application.
As I have x64 machine
build menu->Configuration manager->platform->x64
then i set below configuration in my vs project.
project->properties->configuration->all configuration
VC++Directories->Library Directories->
C:\opencv\build\x64\vc11\bin,C:\opencv\build\x64\vc11\lib
C/C++->Genaral->Additional Include Derectories->
C:\opencv\build\include,C:\opencv\build\include\opencv2,C:\opencv\build\include\opencv
change the
Configuration->Debug
Select Linker->Input->Additional Dependencies
opencv_core2410d.lib
opencv_highgui2410d.lib
opencv_imgproc2410d.lib
opencv_calib3d2410d.lib
opencv_contrib2410d.lib
opencv_features2d2410d.lib
opencv_flann2410d.lib
opencv_gpu2410d.lib
opencv_legacy2410d.lib
opencv_ml2410d.lib
opencv_nonfree2410d.lib
opencv_objdetect2410d.lib
opencv_photo2410d.lib
opencv_stitching2410d.lib
opencv_superres2410d.lib
opencv_ts2410d.lib
opencv_video2410d.lib
then
change Configuration->Release
select Linker->Input->Additional Dependencies
opencv_core2410.lib
opencv_highgui2410.lib
opencv_imgproc2410.lib
opencv_calib3d2410.lib
opencv_contrib2410.lib
opencv_features2d2410.lib
opencv_flann2410.lib
opencv_gpu2410.lib
opencv_legacy2410.lib
opencv_ml2410.lib
opencv_nonfree2410.lib
opencv_objdetect2410.lib
opencv_photo2410.lib
opencv_stitching2410.lib
opencv_superres2410.lib
opencv_ts2410.lib
opencv_video2410.lib
opencv_videostab2410.lib
then i created a class and wrote the code
#include "stdafx.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
int main(){
//declare a new iplimage pointer
IplImage*myimage;
//load image
myimage = cvLoadImage("D:\\visual studio 2012\\katussa.jpg",1);
cvNamedWindow("Smile",1);
cvShowImage("Smile",myimage);
//wait for the key to close the window
cvWaitKey(0);
cvDestroyWindow("Smile");
cvReleaseImage(&myimage);
return 0;
}
when i run i got the error message
The program can't start because opencv_core2410d.dll is missing.
You need to add OpenCV to your system path:
You need to add the directory C:\opencv\build\x86\vc10\bin to your system PATH. This directory contains OpenCV DLLs required for running your code.
Open Control Panel → System → Advanced system settings → Advanced Tab → Environment variables...
On the System Variables section, select Path (1), Edit (2), and type C:\opencv\build\x86\vc10\bin; (3), then click Ok.
ninja edit:
make sure you have follow all the steps on this tutorial
Sometimes you may get this error even when you have added the relevent bin file, for example \opencv-x.x.x\build\install\x64\vc15\bin, to the System Path Environment Variable.
In my case, it worked once I rebooted my PC. Or maybe just restart visual studio and see if it's working, before you reboot the system.

OpenCV on eclipse on windows

I'm trying to install opencv on windows, here are my steps:
downloaded opencv 2.4.3 from website
run the exe, extracted the folder in the same path
opened eclipse (with MinGW previously set and configured)
created new project XYZ
added new folder "src"
added new class "main.cpp"
added the following code:
hash include <cv.h>
hash 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;
}
added the two paths
"E:\Sources\opencv\build\include"
"E:\Sources\opencv\build\include\opencv"
got the compilation error "Symbol 'cv' could not be resolved"
Please advice if any step is missing
you gonna need the latest stable version of openCV 2.4.3 .
Eclipse Juno ! (Eclipse IDE for C/C++ Developers )
And
MinGW - Minimalist GNU for Windows
we will ignore x86/64 choice, since we gonna work with a 32 compiler / and 32 openCV build, even though the system is a 64 one !
Step 1 : Download and Install
Eclipse
Download Eclipse from and decompress the archive . ( I assumed that you already have JRE on your computer , if not ! download and install it ) .
MinGW
Download MinGW . the installer will lead you through the process !
you might have to add the bin directory to the path ! (Default path : C/MinGW/bin )
OpenCV
Download openCV exe from the link , extract the files (in the C:/ directory in this tutorial ) .
Make sure you have the file structure below .
don't forget to add the bin directory => Path !
As I mentioned earlier ! I'll use x86 build even if i have a 64 OS to avoid compiler problems and to keep this tutorial open to x86 OS users !
Step 2 : Create and Configure
Open the Eclipse IDE !
Create a new C++ project : File > New > C++ Project
Choose a Hello Word Project to have a pre structured one !
Don't forget to select the MinGW toolchains
Click Finish and let's get to work !
Now that you have you first Hello word project ! replace the Code in the Soure file .cpp by the code below
///////////////CODE///////////
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat im = imread(argc == 2 ? argv[1] : "lenna.png", 1);
if (im.empty())
{
cout << "Cannot open image!" << endl;
return -1;
}
imshow("image", im);
waitKey(0);
return 0;
}
///////////////CODE///////////
Obviously there are multiple errors on the code , yes ! we have to link the libraries !
Now go to Properties >> C/C++ Build >> Settings
on the Tool Setting tab >> GCC C++ Compiler >> Includes and include opencv path !
[opencvDir\build\include]
Now scroll to MinGW C++ Linker >> Libraries and add the Library search path [opencvDIR\build\x86\mingw\lib]
in the Libraries part ! we add as much librarie as we need for the project !
here I added 4 libraries just for tutorial sake even if well need only the highgui one for our test code to work !
The libraries names can be found on the [opencvDIR\build\x86\mingw\lib]
Example ! for libopencv_video243.dll.a wee add opencv_video243 in the linker !
click OK !
Now we can build our first project !
You figured that you have to add a picture to the project as implied in the source code "lenna.png"
Use lenna for good luck
Build and Run the project !
If you see the beautiful lady :) Congrats :)
have a look here for snapshots!
opencveclipse-on-windows
cv.h is for the old C API. To use the Cpp API try the following:
#include <opencv2/opencv.hpp>