Building and using OpenCV as a static library with Ffmpeg - c++

I'm trying write an OpenCV application. I've statically built OpenCV from source as I don't want dll files and my project compiles as long as I don't use cv::VideoCapture, in which case I get a link error LNK2019 unresolved external symbol.
I think this is because the cv::VideoCapture uses ffmpeg to work with video, which, because of it's license, cannot be statically linked in my project. I would be ok with linking the ffmpeg dynamically but I'm having trouble doing this. There is a opencv_ffmpeg310_64.dll file in the %OpenCV_DIR%\bin folder, but I'm clueless about how to dynamically link it to my project. Usually I have .lib files that come with the .dll but I can't find them anywhere.
Is it possible to statically link OpenCV and dynamically link ffmpeg, and how should I go about doing this?
Additional info:
Windows 10
Visual Studio 2015
OpenCV 3.1.0 x64 build

I finally got it working. I was wrong thinking I needed ffmpeg to get it working. The problem I had was solved by adding vfw32.lib to the library dependencies in Visual Studio.

Related

Install OpenCV without lib file

I have a version of OpenCV built with MinGW and I'm trying to include it in a Visual Studio project. I have the dlls and the header files, however no lib files were provided. Only dll.a files. I tried pointing the linker additional dependencies setting to the dll.a files however I still get unresolved external symbol errors.
How do I use this version of OpenCV if it doesn't have the lib files?
Note: I should mention, I'm trying to use this specific build because it is x86, which is what I need for this project, and the official site doesn't seem to provide x86 builds.

Linking error while using dlib with libjpeg

I am studying Machine Learning and Pattern Recognition and using dlib library for that. I was trying one example code face_detection_ex.cpp provided with the library. I created a separate project under Visual Studio 2010 and included the face_detection_ex.cpp example and dlib\all\source.cpp files. It build fine. But, if I enable DLIB_JPEG_SUPPORT by
#define DLIB_JPEG_SUPPORT
then it will throw the linking error LNK2019 for all the functions of libjpeg library used by the dlib library. I tried #pragma comment(lib, libjpeg) and I also tried to include the library in project properties, but still the same.
After spending 1 day on this error, I switched to linux and try to work in that. But there also I am getting the same linking errors.
Then on the dlib release-note I read that libjpeg library is included in dlib's external folder and use dlib's cmake file for the example code and cmake will perform the static linking. I tried that and with cmake it is linking. I tried to find out how the linking is happening as I want it to work with visual studio and other compilers also but I couldn't find out why the libjpeg library is unable to link.
Any suggestion?
EDIT: Here it is mentioned how to use dlib with Visual Studio. And how to compile the example on linux. So, as I have to link with libjpeg library, I added the -ljpeg in the command.
You can use CMake to generate a Visual Studio project that is properly configured and that's the easiest way to do this if you want to use Visual Studio.
However, if you really want to configure the Visual Studio project by hand then all you need to do is add the files in the dlib/external/libjpeg folder to your Visual Studio project and also add the dlib/external/libjpeg folder to the include search path.

How to link opencv and other dll files to output exe of visual studio 2013

I am new with visual studio, opencv.
I am using visual studio 2013, opencv and c++ for my project.
I configured (copied path) the opencv and other library to my computer environment system.
After run the project in visual studio, normally, there will be an exe file in the project.
I can copy the exe file in the project folder and copy to other place in my computer and it will run normally.
This is because my computer environment systems are configured with opencv and other library.
I want to do the same thing with other computers BUT I do not want to manually configure each computer with opencv and other libraries.
Are there any ways that I can do to link everythings all in exe file after run the project in visual studio 2013 so that I can run the exe without depend on the path of libaries and opencv?
EDITED
I use opencv installer opencv2.4.7.exe
In the current VS2013 my project, i configured my project and opencv installer as this link
http://www.anlak.com/using-opencv-2-4-x-with-visual-studio-2010-tutorial/
question : Can i use the library in folder C:\opencv\build\x64\vc11\staticlib come from the opencv installer no need create my own library from source opencv?
question : In case i need to generate new library from opencv source (http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html) or use lib in static folder of opencv installer, if i want to include it all to exe files, do i need to create new project and reconfigure?
Thank you.
First you need to rebuild openCV to generate static libraries instead of dynamically linked ones. This way all code that your application uses is thrown together in one single exe-file (which will probably be significantly bigger). This exe-file you can move to other computers and they should still work there, provided they have an architecture that is at least compatible with yours. So if you build it on an x86 perconal computer (32-bit), it should basically work on any other personal computer. If you build it on a x64 computer (AMD 64-bit), it will only run on other x64 machines. At least this is true assuming both systems use the same syscall API (Windows NT, POSIX...).
For openCV you do this by setting the BUILD_SHARED_LIBS build flag to false (see OpenCV as a static library (cmake options), the following line is taken from there):
cmake -DBUILD_SHARED_LIBS=OFF ..
Once you have done this, you will see that the openCV folder looks very similar to the one you have now, except that in your 'lib' folder there will now be .lib-files instead of .dll files (at least if you are working on Windows, which I assume you do since you are using Visual Studio).
Next step is to go to your project settings and set your linker to link with the static libraries instead of the dynamically ones. If you have used openCV's local method for linking, you can go to project settings -> linker -> input -> Addtional dependencies. There you change the extension of all the openCV libraries from .dll to .lib.
Now you should be able to rebuild your application and the resulting exe-file should have all dependent libraries contained in it.

Packaging libraries with .exe

I've made an application using both the OpenCV and WxWidgets library. The code runs fine on my development machine.
However, when I transfer it to another windows machine I get the error
*"The program can't start because cv110.dll is missing from your computer.
Try reinstalling the program to fix this problem".*
Now, I'm guessing installing the same versions of OpenCV and WxWidgets as used in development would resolve this problem but this is a bit much to ask of a casual 3rd party user of my code.
In my IDE (Windows Visual C++ 2008) I've linked to the relevant .lib files by going to Properties->Linker->Input
How would I go about packaging the .exe so that it works on non-development machines?
i.e. if I include the .dll files, how would I need to change the linker configuration to reflect this ? Or, can the .dll files referenced by the .lib files be incorporated into the .exe ?
Sorry, I know this issue has come up before but I can't seem to find a resolution specific to my case. Any help would be appreciated!
OpenCV is built using dynamic libraries
The correct thing to do is create an installer containing your exe and the correct dlls you need. See https://stackoverflow.com/questions/1285591/installer-recommendation

Compiling OpenCV for Visual C++ 9.0

I looked at many places but could not find anything telling me how to buld the lib files. I know how to link them, but openCV install folder only contains .a files. I cant find an sln file or dsp. How can I make the lib files? Right now all the samples get linker problems because the lib files dont exist.
Thanks
The Windows installer (.exe) for OpenCV 2.0 does not come with the binaries pre-built for vc++, nor does it have the .vcproj files for using vc++ to build them. You need to have cmake, which is available for free on the web. I used the GUI. Use that to build .vcproj files with which you can compile everything in VC++ 2008 or whatever. There are some gotchas. The question has been asked and answered.
.a files are libraries. On a unix platform they're typically statically linked libraries.
If you're on windows however they should be .dll files. How did you compile OpenCV and does it support compiling on windows?
In order to create the .sln files you need to run CMake on the OpenCV folder containing makefiles.