How to compile OpenCV 2.3 with ffmpeg support with Visual Studio 2010 - opencv

It's two days I'm search around the web for a tutorial to compile OpenCV 2.3 with ffmpeg support under windows, but nothing found. I'm using pre-built version of OpenCV in VS2010 but I cannot read from network camera, it's why I need ffmeg support.

The answer your looking for is here and it works for the 32 bit and 64 bit configurations.
I used this build of FFMPEG.
http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z
1) Download OpenCV 2.3
2) Open the root CMakeLists.txt and insert the line set(HAVE_FFMPEG 1)
3) Download http://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-git-1aeb88b-win64-dev.7z (or the 32 bit build if u fancy it)
4) Edit avformat.h found in the ffmpeg include dir with #define INT64_C
5) Edit cap_ffmpeg_impl.hpp from the highgui project with #define snprintf _snprintf
6) in your highgui project properties under C/C++>Additional Include Directories add path of the include directory of FFMPEG you just downloaded
7)On the same property page under Linker>General>Additional Library Dependencies add the path of the lib directory of FFMPEG you just downloaded
8)On the same property page under Linker>Input>Additional dependencies add ALL the names of the libraries of ffmpeg found in lib (avformat.lib, avscale.lib, avcore.lib etc)
9) build the highgui project
10) Add the path of the .dll files that came with FFMPEG to the System Path environment variable.
That's it! 10 easy steps ;)

Build OpenCV with CMake from sources. Choose USE_FFMPEG flag.
Get ffmpeg from http://ffmpeg.zeranoe.com/builds/

In my experiment, FFMPEG is not directly supported in window. The flag WITH_FFMPEG only appears under UNIX(opencv 2.3 CMakeLists.txt). So, if you want to build opencv 2.3 with ffmpeg support, you should edit the CmakeLists.txt or the project opencv_highgui yourself. And then get ffmpeg from WWW. You may also need to edit cap_ffmpeg_impl.hpp.

Related

Building an OpenCV Application with Static Libraries

Edit:
Problem solved after a few steps. You can take a look at my post on the OpenCV Q&A page.
http://answers.opencv.org/question/152366/build-application-with-static-libraries/
I'm trying to statically link my C++ (CMake) application to run on another computer which does not have OpenCV installed.
So far,
I built OpenCV from source by setting BUILD_SHARED_LIBS to OFF, so I can see library files under lib directory. (with .a extension)
I edited the environment variable for the new build of OpenCV, my IDE does see include directories and files, so this step also seems ok.
Added "-static" parameter to target_link_libraries command in CMake:
target_link_libraries(HoGPeopleDetector ${OpenCV_LIBS} "-static")
Then rebuilt the application, EXE size increased to 1.6 MB from 200 KB. So I guess linking process was successful.
The application works well when I run it within my IDE. However, when I try to run it from the EXE file, it still expects DLL files. (libopencv_core310.dll and maybe more)
IDE: CLion 2017.1.2 OpenCV: 3.1
Problem solved after a few steps. You can take a look at my post on the OpenCV Q&A page.
http://answers.opencv.org/question/152366/build-application-with-static-libraries/
Overall, it was "remember to clear your CMake cache file between each invocation of cmake" and to move/copy the opencv_ffmpegXXX.dll (310 in my case), put it in the same directory with your EXE.

How to install OpenCV 3.1 with nonfree module?

I'm trying to write a program that uses SURF algorithm and I know that the nonfree module must be installed separately. I've downloaded and installed the latest version of CMake(3.5.2) and I'm following the instructions from:
https://github.com/itseez/opencv_contrib/ . I'm using the GUI and I run Visual Studio 2015 on a 64 bit Windows 10.
Since I know that for SURF you must include xfeatures2d when it asked me the source of the code I only specified the xfeatures2d folder. When I first pressed the configure button I had some errors(I've attached an image of them). I managed to get rid of one of the errors, the one that said to write a line of code at the top of the file
cmake_minimum_required(VERSION 3.5), but I still have one error:
CMake Error at CMakeLists.txt:4 (ocv_define_module):
Unknown CMake command "ocv_define_module".
I'm also attaching a picture of the CMakeLists.txt. Please help me find the problem.
Also, if you could help my install all modules at once, I would be grateful. Or do I have to set as input every folder in the modules folder?
GUI error and CMakeLists.txt
Try using Visual Studio 12 2013 for compilation, this has worked for me, but not the other (newer) versions of Visual Studio.

How to cross compile OpenCV with ffmpeg

I want to cross compile opencv with ffmpeg for arm.
I have cross compiled ffmpeg, how do I configure cmake to see the ffmpeg?
Edit: I am cross compiling for AR Drone 2.0. I use toolchain under platform/linux.
The answer to your specific problem is to use cmake-gui which provides you a visual interface to ease the process of setting up variables, like your ffmpeg package location.
However I have 2 recommendations:
Download the most updated toolchain.
DO NOT USE THIS GUIDE. Use instead the toolchain that you find in the package in sources\platforms\android\android.toolchain.cmake: read inside, you'll find the correct instructions at the beginning of the file.
Another optional recommendation: use ninja as build system, much faster.
I was successful in cross compiling OpenCV with ffmpeg for AR Drone's ARM processor by writing my own toolchain file where I explicitly set all the linker, pkg_config and compiler paths to relevant directories containing the cross-compiled stuff.
I have written a blog post detailing the entire process here:
How to Cross-Compile OpenCV with FFmpeg for AR Drone (ARM Processor).

Missing files, DirectX SDK (d3dx9.lib, d3dx9.h)

I installed the DirectX SDK June 10, but when I include the d3dx9.h, the compiler can't find it.
I checked the SDK directory, and I didn't find it there either.
files missing: d3dx9.lib, d3dx9.h, dxfile.h.
The DirectX SDK installation will add a system environment variable DXSDK_DIR that holds the path to wherever the SDK was installed to. Instead of inserting an absolute path in your Include and Library Directories, I'd recommend using this variable to set the Include and Library path for DX dependencies.
As Include Directory add: $(DXSDK_DIR)Include
As Library Directory add: $(DXSDK_DIR)Lib\x86 or $(DXSDK_DIR)Lib\x64 on a 64-bit architecture
So your VC++ Directories should look something like this:
The $(DXSDK_DIR) resolves to the path where you installed the SDK, normally "C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)" and works even if you chose another path, which makes it more available between different people.
The library file (d3dx9.lib) should be in C:\path\to\Microsoft DirectX SDK (June 2010)\Lib\x86\ as well as in C:\path\to\Microsoft DirectX SDK (June 2010)\Lib\x64\
Both include files you mentioned exist in C:\path\to\Microsoft DirectX SDK (June 2010)\Include\
If you're still not able to find them, download and install the SDK from here:
http://www.microsoft.com/en-us/download/details.aspx?id=6812
I downloaded and used this one and I can asure you, that those files are present!!
When I had this problem, I found that I had the d3dx9.h in the
[Program Files(x86) \ Microsoft DirectX SDK (June 2010) \ include] folder.
The compiler needed it to be in
[Program Files(x86) \ Windows Kits \ 8.1 \ include \ shared].
I copied the file to the other location and it worked, but I wonder if that was the smartest fix.
in my case, following code works for me:
//#include <d3dx9.h>
#include <d3d9.h>
//#pragma comment(lib, "d3dx9.lib")
#pragma comment(lib, "d3d9.lib")

cvBlobsLib with mingw

Does anybody know how to build cvBlobsLib using MinGW? On official page http://opencv.willowgarage.com/wiki/cvBlobsLib there is only instruction for VS.
There is also linux version of this lib http://opencv.willowgarage.com/wiki/cvBlobsLib?action=AttachFile&do=view&target=cvblobs8.3_linux.tgz , but its makefile cannot be used in windows as i see.
If you use eclipse then you dont have a lot of work:
Create a new project, using MinGW toolchain.
Go to the project properties, and under C/C++ General >> Paths and Symbols add the openCV library paths.
compile the project and it should be OK.
Use this
http://opencv.willowgarage.com/wiki/cvBlobsLib#Build_intructions
if you have more problems (especially NOTE 3)

Resources