How do I link a third party library using the unreal build tool?

Hello!

I am very unfamiliar with the unreal build tool and I need to link several third party libraries to UE4, starting with OpenCV.

I started with a first-person code template and attempted to edit the generated build.cs game module to add the include directory as well as link the .lib and .dll dependencies.

Here is the code so far:


using UnrealBuildTool;

public class UnrealRobotics : ModuleRules
{
public UnrealRobotics(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { ā€œCoreā€, ā€œCoreUObjectā€, ā€œEngineā€, ā€œInputCoreā€ });

    // Create OpenCV Path
    string OpenCVPath = UEBuildConfiguration.UEThirdPartySourceDirectory + "OpenCV";

    // Add include Path
    PublicIncludePaths.Add(OpenCVPath + "/inc");
    PublicIncludePaths.Add(OpenCVPath + "/inc/opencv2");

    // Get Library Path
    string LibPath;
    bool isdebug = Target.Configuration == UnrealTargetConfiguration.Debug && BuildConfiguration.bDebugBuildsActuallyUseDebugCRT;
    if (Target.Platform == UnrealTargetPlatform.Win64)
        LibPath = OpenCVPath + "/lib/Win64/VS" + WindowsPlatform.GetVisualStudioCompilerVersionName();
    else if (Target.Platform == UnrealTargetPlatform.Win32)
        LibPath = OpenCVPath + "/lib/Win32/VS" + WindowsPlatform.GetVisualStudioCompilerVersionName();
    else
	{
		string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString());
		System.Console.WriteLine(Err);
		throw new BuildException(Err);
	}
    
    // Add Library Path
    PublicLibraryPaths.Add(LibPath);
    System.Console.WriteLine(LibPath);

    // Add Dependencies
    if (!isdebug)
    {
        PublicAdditionalLibraries.Add("opencv_calib3d2410.lib");
        PublicAdditionalLibraries.Add("opencv_contrib2410.lib");
        PublicAdditionalLibraries.Add("opencv_core2410.lib");
        PublicAdditionalLibraries.Add("opencv_features2d2410.lib");
        PublicAdditionalLibraries.Add("opencv_flann2410.lib");
        PublicAdditionalLibraries.Add("opencv_gpu2410.lib");
        PublicAdditionalLibraries.Add("opencv_highgui2410.lib");
        PublicAdditionalLibraries.Add("opencv_imgproc2410.lib");
        PublicAdditionalLibraries.Add("opencv_legacy2410.lib");
        PublicAdditionalLibraries.Add("opencv_ml2410.lib");
        PublicAdditionalLibraries.Add("opencv_nonfree2410.lib");
        PublicAdditionalLibraries.Add("opencv_objdetect2410.lib");
        PublicAdditionalLibraries.Add("opencv_ocl2410.lib");
        PublicAdditionalLibraries.Add("opencv_photo2410.lib");
        PublicAdditionalLibraries.Add("opencv_stitching2410.lib");
        PublicAdditionalLibraries.Add("opencv_superres2410.lib");
        PublicAdditionalLibraries.Add("opencv_ts2410.lib");
        PublicAdditionalLibraries.Add("opencv_video2410.lib");
        PublicAdditionalLibraries.Add("opencv_videostab2410.lib");
        PublicDelayLoadDLLs.Add("opencv_calib3d2410.dll");
        PublicDelayLoadDLLs.Add("opencv_contrib2410.dll");
        PublicDelayLoadDLLs.Add("opencv_core2410.dll");
        PublicDelayLoadDLLs.Add("opencv_features2d2410.dll");
        PublicDelayLoadDLLs.Add("opencv_flann2410.dll");
        PublicDelayLoadDLLs.Add("opencv_gpu2410.dll");
        PublicDelayLoadDLLs.Add("opencv_highgui2410.dll");
        PublicDelayLoadDLLs.Add("opencv_imgproc2410.dll");
        PublicDelayLoadDLLs.Add("opencv_legacy2410.dll");
        PublicDelayLoadDLLs.Add("opencv_ml2410.dll");
        PublicDelayLoadDLLs.Add("opencv_nonfree2410.dll");
        PublicDelayLoadDLLs.Add("opencv_objdetect2410.dll");
        PublicDelayLoadDLLs.Add("opencv_ocl2410.dll");
        PublicDelayLoadDLLs.Add("opencv_photo2410.dll");
        PublicDelayLoadDLLs.Add("opencv_stitching2410.dll");
        PublicDelayLoadDLLs.Add("opencv_superres2410.dll");
        PublicDelayLoadDLLs.Add("opencv_ts2410.dll");
        PublicDelayLoadDLLs.Add("opencv_video2410.dll");
        PublicDelayLoadDLLs.Add("opencv_videostab2410.dll");
    }
    else
    {
        PublicAdditionalLibraries.Add("opencv_calib3d2410d.lib");
        PublicAdditionalLibraries.Add("opencv_calib3d2410d.lib");
        PublicAdditionalLibraries.Add("opencv_contrib2410d.lib");
        PublicAdditionalLibraries.Add("opencv_core2410d.lib");
        PublicAdditionalLibraries.Add("opencv_features2d2410d.lib");
        PublicAdditionalLibraries.Add("opencv_flann2410d.lib");
        PublicAdditionalLibraries.Add("opencv_gpu2410d.lib");
        PublicAdditionalLibraries.Add("opencv_highgui2410d.lib");
        PublicAdditionalLibraries.Add("opencv_imgproc2410d.lib");
        PublicAdditionalLibraries.Add("opencv_legacy2410d.lib");
        PublicAdditionalLibraries.Add("opencv_ml2410d.lib");
        PublicAdditionalLibraries.Add("opencv_nonfree2410d.lib");
        PublicAdditionalLibraries.Add("opencv_objdetect2410d.lib");
        PublicAdditionalLibraries.Add("opencv_ocl2410d.lib");
        PublicAdditionalLibraries.Add("opencv_photo2410d.lib");
        PublicAdditionalLibraries.Add("opencv_stitching2410d.lib");
        PublicAdditionalLibraries.Add("opencv_superres2410d.lib");
        PublicAdditionalLibraries.Add("opencv_ts2410d.lib");
        PublicAdditionalLibraries.Add("opencv_video2410d.lib");
        PublicAdditionalLibraries.Add("opencv_videostab2410d.lib");
        PublicDelayLoadDLLs.Add("opencv_calib3d2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_contrib2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_core2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_features2d2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_flann2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_gpu2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_highgui2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_imgproc2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_legacy2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_ml2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_nonfree2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_objdetect2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_ocl2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_photo2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_stitching2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_superres2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_ts2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_video2410d.dll");
        PublicDelayLoadDLLs.Add("opencv_videostab2410d.dll");
    }
}

}


I put all the files in the ThirdParty directory. The above code causes a compiler error (error LNK1181: cannot open input file ā€˜opencv_calib3d2410.libā€™). I have tried How to link *.dll about third party library? - C++ - Unreal Engine Forums

and

with no progress! Any help would be greatly appreciated :slight_smile:

Iā€™m not sure what fixed it, but following A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums as close as possible seems to be what fixed it! For reference, here is the new project.build.cs file:


using UnrealBuildTool;
using System.IO;

public class UnrealRobotics : ModuleRules
{
    private string ModulePath
    {
        get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); }
    }

    private string ThirdPartyPath
    {
        get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); }
    }

    public UnrealRobotics(TargetInfo Target)
    {
        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RHI", "RenderCore", "ShaderCore" });

        LoadOpenCV(Target);
    }

    public bool LoadOpenCV(TargetInfo Target)
    {
        bool isLibrarySupported = false;

        // Create OpenCV Path
        //string OpenCVPath = Path.Combine(UEBuildConfiguration.UEThirdPartySourceDirectory, "OpenCV");
        string OpenCVPath = Path.Combine(ThirdPartyPath, "OpenCV");

        // Get Library Path
        string LibPath = "";
        bool isdebug = Target.Configuration == UnrealTargetConfiguration.Debug && BuildConfiguration.bDebugBuildsActuallyUseDebugCRT;
        if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            LibPath = Path.Combine(OpenCVPath, "Libraries", "Win64");
            isLibrarySupported = true;
        }
        else if (Target.Platform == UnrealTargetPlatform.Win32)
        {
            LibPath = Path.Combine(OpenCVPath, "Libraries", "Win32");
            isLibrarySupported = true;
        }
        else
        {
            string Err = string.Format("{0} dedicated server is made to depend on {1}. We want to avoid this, please correct module dependencies.", Target.Platform.ToString(), this.ToString());
            System.Console.WriteLine(Err);
        }

        if (isLibrarySupported)
        {
            // Add Library Path
            //PublicLibraryPaths.Add(LibPath);

            // Add Dependencies
            if (!isdebug)
            {
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_contrib2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_core2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_features2d2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_flann2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_gpu2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_highgui2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_imgproc2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_legacy2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ml2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_nonfree2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_objdetect2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ocl2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_photo2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_stitching2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_superres2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ts2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_video2410.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_videostab2410.lib"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_calib3d2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_contrib2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_core2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_features2d2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_flann2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_gpu2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_highgui2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_imgproc2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_legacy2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ml2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_nonfree2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_objdetect2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ocl2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_photo2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_stitching2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_superres2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ts2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_video2410.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_videostab2410.dll"));
            }
            else
            {
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_calib3d2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_contrib2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_core2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_features2d2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_flann2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_gpu2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_highgui2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_imgproc2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_legacy2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ml2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_nonfree2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_objdetect2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ocl2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_photo2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_stitching2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_superres2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_ts2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_video2410d.lib"));
                PublicAdditionalLibraries.Add(Path.Combine(LibPath, "opencv_videostab2410d.lib"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_calib3d2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_contrib2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_core2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_features2d2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_flann2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_gpu2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_highgui2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_imgproc2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_legacy2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ml2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_nonfree2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_objdetect2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ocl2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_photo2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_stitching2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_superres2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_ts2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_video2410d.dll"));
                PublicDelayLoadDLLs.Add(Path.Combine(LibPath, "opencv_videostab2410d.dll"));
            }

            PublicIncludePaths.Add(Path.Combine(OpenCVPath, "Includes"));
        }

        Definitions.Add(string.Format("WITH_OPENCV_BINDING={0}", isLibrarySupported ? 1 : 0));

        return isLibrarySupported;
    }
}

However, you still have to include headers using the full path to your /ThirdParty directory. For the above code, I dumped all the includes into ā€œProject/ThirdParty/OpenCV/Includesā€ directory and all the .libā€™s and .dllā€™s into the ā€œProject/ThirdParty/OpenCV/Libraries/Win32ā€ (and Win64) directories. In addition, when running the .dllā€™s couldnā€™t be found, so I dumped all of the x64 ones into the Project/Binaries/Win64 folder.

Hereā€™s a webcam in unreal! :smiley:

Hi there ,

in first place, congrats because you got it running!

Iā€™m not able to make it. Im trying to add OCV 3.0 to a C++ project, based on a first person shootr template with no starter content. Iā€™m only adding this line on my character class:

#include "opencv2/imgproc.hpp"

It looks like itā€™s finding the includes and libraries, but on debug time it throws an error Iā€™m attaching

error.txt

OCV 3.0 is properly instaled at my system and I have a OCV project running on VS2013 in release, debug, x64 and x86 archs. So I discarded it could be a compilator issue or a incorrect CV version. Iā€™m attaching to this post my ***.Build.cs in order you can check it.

Iā€™ve configured project property to add thirdparty folder and Iā€™ve checked several times paths and libraries are correct.
Any idea?
Thank you so much and best regards

Ok, ā€œā€ā€œā€ā€œā€œsolvedā€ā€ā€œā€"

Unreal has some kind of problem in using OpenCV 3.0. Itā€™s unnable to build the project with that library. So the ā€œsolutionā€ is to downgrade OpenCV. Iā€™ve downgraded to OpenCV 2.4.1.0 and it workedā€¦ I supose itā€™s going to be easier to rebuild my own libraries using 2.4.0.1 than wait until Epic fixes this issue.

I hope this could be usefull for somebody in getting less frustrated than me :slight_smile:
BTW, my build.cs currently only adds this lines at the end of the constructor method:

if (Target.Platform == UnrealTargetPlatform.Win64)
{
    PublicAdditionalLibraries.AddRange(new string[] { 
        "C:/opencv2410/build/x64/vc12/lib/opencv_core2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_highgui2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_imgproc2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_calib3d2410.lib"});
    PublicIncludePaths.AddRange(new string[] { "C:/opencv2410/build/include"});
}

I had to change to old namespace including

#include "opencv2/highgui/highgui.hpp"

instead

#include "opencv2/highgui.hpp"

Best regards,

Ok, ā€œā€ā€œā€œsolvedā€ā€ā€œā€

It looks like Unreal is not working as expected with OpenCV 3.0 at the moment. So the ā€œā€ā€œā€œsolutionā€ā€ā€œā€ is just a downgrade of OpenCV version. Iā€™ve downgraded from 3.0 to 2.4.1.0. With this downgrade, I added only this lines at the end of the constructor:

if (Target.Platform == UnrealTargetPlatform.Win64)
{
    PublicAdditionalLibraries.AddRange(new string[] { 
        "C:/opencv2410/build/x64/vc12/lib/opencv_core2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_highgui2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_imgproc2410.lib", 
        "C:/opencv2410/build/x64/vc12/lib/opencv_calib3d2410.lib"});
    PublicIncludePaths.AddRange(new string[] { "C:/opencv2410/build/include"});
}

We have to change the namespace to the old way as well so use

#include "opencv2/highgui/highgui.hpp"

instead of

#include "opencv2/highgui.hpp"

I supose this is easier than watting until Epic fixes this issue :slight_smile:
I really hope this could be useful for someone else in getting less frustrated than me :stuck_out_tongue:
Best regards,

Hello ,

I was able to compile the code as I was also getting the LNK1181 error. however I cant figure out how you were able to get the results shown above. If itā€™s not to much to ask, do you think you would be able to provide the steps you took to achieve getting a camera to work UE4? I have tried following the steps on :

and

But got lost in the process. Any help would be greatly appreciated.
Thanks,
Kirmet

I created this tutorial on the wiki: A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

I hope it is what you are looking for!

Have fun,

Thank you so much ,

I just have a look at your tuto. As soon as I can follow it, Iā€™ll tell you how it was :smiley:

Anyways, in first place, thank you for that effort and keep on working hard.

EDIT
BTW, I saw you are have some problems with includes. My build is so much simpler than yours, so probably itā€™s not working properly in the most cases, but I can use regular inclues, so here it is the code Iā€™m attaching on my build file at the end of the constructor:

if (Target.Platform == UnrealTargetPlatform.Win64)
        {
            PublicAdditionalLibraries.AddRange(new string[] { 
                "C:/opencv2410/build/x64/vc12/lib/opencv_core2410.lib", 
                "C:/opencv2410/build/x64/vc12/lib/opencv_highgui2410.lib", 
                "C:/opencv2410/build/x64/vc12/lib/opencv_imgproc2410.lib", 
                "C:/opencv2410/build/x64/vc12/lib/opencv_calib3d2410.lib"});
            PublicIncludePaths.AddRange(new string[] { 
                "C:/opencv2410/build/include"});
        }

With this code above Iā€™m able to use includes like this:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"

Best regards,

1 Like

Thanks for pointing me to your Tutorial ! Sadly I still was unable to achieve promising results. I managed to get everything to compile but I was unable to get the webcam to project onto the surface. here are my results.

52829-results.png

I am not sure Where I am going wrong. I have tried using a Kinect and a PS3 eyetoy cam and have also tried different camera IDā€™s.

I have attached my build.cs file, webcamreader.h and webcamreader.cpp in txt format. I am still learning UE4 and am happy to see guys like you all who are not afraid of pushing the boundaries. Thanks in advance to whomever can shed some light on this.

[link text][3]
[link text][4]
[link text][5]

Hello again, congrats on getting it to compile!

It sounds like opencv might not be able to access your camera drivers. Iā€™m not 100% sure, but I think the Kinect has to be used with its own SDK. If you can, I would try connecting only one simple webcam to your computer and use device ID 0. If you need more data than just the camera feed, (skeletal data, disparity, ect.) then you will need to link the libraries provided by those devices.

To make sure that opencv is reading your webcam, you can try a simple opencv console application to read and output device 0. An example can be found here: OpenCV C++ video capture | Freedom is coding

If opencv can read your camera feed, then make sure your material (M_Webcam) actually has a texture parameter, and not just a static texture sample. Also make sure it is named ā€˜Textureā€™, case sensitivity and all!

Good Luck,

Hello ,

Good to see that it is possible! Once I get a little more time, I will update the tutorial with the proper includes.

Thanks,

Nah, thanks to you, Iā€™m only adding minimal suggestions to your work.

In the other hand, you see my opencv folder named as opencv2410. Thatā€™s because I was trying to run opencv3 libraries, but I was unable to get it working, so I had to downgrade to 2.4.1.0 version. Anywas, I still have installed my opencv3 so thatā€™s why the folder is named in this way. You should change that folderā€™s name to the default in order to make your tuto easier to follow :smiley:

Probably a note warning that OCV3 is still not working or can be problematic (maybe I couldnā€™t get it working, but maybe there is some way to achieve it) would be apreciated by several users like me (I wasted like 4 days trying to fix that until I gave up) xDDD

Best regards,

Hi there ā€œOCV + Unreal4ā€ guys :smiley:

Iā€™ve been having problems with a concrete function from OpenCV:

cv::findContours(contoursImg, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

Looks like Unreal 4.7.6 reflection system is not working as it should, because it has problems when freeing contours attribute ( std::vector< std::vector < cv::Point > > ). This code is comming from a working program with some image processing. If I apply a Canny filter instead findContours the program works fine, but I need contoursā€¦ :frowning:

Iā€™ve found this link:

But no update there since april.
Iā€™ve already checked Iā€™m linking to the right libraries (dynamic and static), tried to free that vector before the methodā€™s ending, but reflection system wraps my memory management and rises the same issue.

Has anybody tried to use this function and have the same issue?
Any new would be very appreciated :slight_smile:
Best regards,

Thank you !

It seems ue4 might of had a problem loading the drivers for both Kinect and PS eyetoy, I have tried doing the simple opencv console application as you suggested above and I was able to get a visual feed using the PS eyetoy. I then decided to use an old Logitech cam i had laying around with the UE4 project and it worked!!..it almost brings a tear to my eye.

I have one question tho, Have you tried or do you know whether this can be packaged as a mobile app. I have tried packaging it but I get errors stating that it is unable to find the core.hpp.

Thanks again!
Kirmet

Hi everyone,

First of all, I wanted to say thank you to everyone who has been participating in this post. This is a great example of what we want AnswerHub to become; a place where the community can help and learn from each other.

OpenCV is not a library that we support directly, but we want users to be able to add third party libraries if they want to use one, so another big thank you for helping get this particular library working with the Engine. I walked through the tutorial that created (Very well done, with only some minor discrepancies) and was able to get it working on the first try.

Unfortunately I do not have easy access to a Kinect or PS EyeToy, so I canā€™t do any testing on those devices. I am also not sure if a project using this library can be packaged for mobile. If this is still a concern, I can dig into that and see what I can come up with.

Thanks again for everyoneā€™s hard work on this, and please let us know if you run into any additional trouble with OpenCV. We may not be able to provide direct support, but will help if we can.

Hi ,

Great to see your involvement in this. :slight_smile:

One thing that you could try is to use OpenCV 3.0 instead of OpenCV 2.4.

When I tried OpenCV 3.0 I got errors in header files that were very difficult for me to debug, particularly so given my limited expertise in the Unreal Build System. I ā€œsolvedā€ it by implementing the functions I wanted in a new third party library and linking to that, since OpenCV 3.0 compiled fine with plain Visual Studio 2013. That works, but of course it is a bit cumbersome and limited to not be able to use OpenCV functions directly in my Unreal Engine project code.

/Daniel

Hello all,

I managed to fix the opencv 3.0.0 problem with (hopefully) no consequences. The problem is that in opencvā€™s utility.hpp, which is included in core.hpp, there is a function called ā€˜checkā€™ that conflicts with (afaik) epicā€™s check macro. To solve this, I commented out line 729 in utility.hpp. This -could- break something futher down the line, but it allows me to include core, highgui, imgproc, and videoio with no compile errors. :slight_smile:

I will test this fix later to make sure it actually works at runtime, and if it does I will update the tutorial later today, and probably slap all of the opencv3 code in a plugin for convenience.


EDIT I updated my tutorial to work with opencv 3. A big thank you to whoever edited the tutorial with fixed includes. :slight_smile:

I also included an OpenCV plugin in the tutorial, which is free to download for whoever wants it! It includes all the opencv 3 files you need, in addition to handling all the includes / linking for you. Install instructions are in the readme.

Have fun,

Hello again ,

I updated my tutorial (finally) to work with opencv 3, and included a plugin for convenience!

Have a good day,

Amazing news ! :smiley:

Glad to read them. As soon as I can perform the tests, Iā€™ll check it out and send you some feedback (I hope in the next week, because Iā€™m pretty busy now with project documentation issues xDD) Theses changes will take me a couple of days considering the amount of modifications:

My OpenCV client code is compiled into DLLs because Unreal doesnā€™t suite properly with C++ standard containers, so its Garbage Collector collides with my OpenCV codeā€¦ To avoid that, after several tests, I decided to compile my OpenCV code into a third party library (DLL) and now it works as expected. Iā€™m telling you this JIC you run into the same issue (memory freeing issue after OCV method calling). If thatā€™s the case, encapsulate your code as I told you and it should work.

Thank you for all your efforts and keep on checking :wink:
Best regards,

Hi

Congratulations for your plugin and documentation. It works on the unreal editor, and on windows launcher option too.

But I cannot package for android, although I tried a lot of answers searching on google (adding opencv directories on includes and paths basically). Here is the fatal error:

LogPlayLevel: UnrealBuildTool: ā€¦WebcamReader.h(6,10) : fatal error: ā€˜opencv2/core.hppā€™ file not found

Should it work on mobile platforms? In case not, is it planned packaging for mobiles?

Thanks for your answer.