x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 https://answers.unrealengine.com/questions/188959/how-to-link-dll-about-third-party-library.html

and

https://forums.unrealengine.com/showthread.php?61365-AR-implemented-with-OpenCV-webcam-capture-drawn-to-dynamic-texture

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

Product Version: UE 4.8
Tags:
more ▼

asked Jun 15 '15 at 10:55 PM in C++ Programming

avatar image

Ginku
81 6 8 10

avatar image Rokew666 Nov 25 '16 at 01:55 PM

Hello all.

I am currently following your tutorial about the integration of OpenCV 3.0 into Unreal Engine 4.14. I tried it couple of times and seem to allways get the same error at the end of when I enable the plugin. It reads: The following modules are missing or built with a different engine version: UE4Editor-OpenCV.dll Would you like to rebuild them now? I click Yes, the build fails and it does not copile. In the end it reads : X could not be compiled. Try rebuilding from source manually.

I am currently preety new to the Unreal engine, so I don't know how to go about this error, tried to find out why the newer versions of the engine don't work but no luck. Any help would be appriciated.

As a project I'm trying to make a simple camera web recorder that build an augmented module above it. To put it simply an augmented reality model.

Best regards, Rokew

avatar image Ginku Nov 26 '16 at 08:02 PM

Hello Rokew,

I have updated my plugin/tutorial (finally) for UE4 4.14.0 and opencv 3.0. There was a small API change that needed fixing, which is why the plugin wouldn't compile. :)

Have fun with your augmented reality project!

-Ginku

avatar image Rokew666 Nov 28 '16 at 01:43 PM

Hello again,

First of all thank you very much for your time and upgrade to the plugin (also the tutorial). As I mentioned above, I'm still new to the whole Unreal engine. I would like to ask you a question if you don't mind since the whole engine is a little confusing to me, for now.

I would need the camera reader to show the input on the screen (not the billboard in the world) so that the only thing you see is your input from your camera, how could I do that?

Thank you in advance if you would be so kind to help me out.

Best regards Rokew

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

6 answers: sort voted first

I created this tutorial on the wiki: https://wiki.unrealengine.com/Integrating_OpenCV_Into_Unreal_Engine_4

I hope it is what you are looking for!

Have fun, Ginku

more ▼

answered Jul 31 '15 at 11:26 PM

avatar image

Ginku
81 6 8 10

avatar image Kirmet The Frog Aug 04 '15 at 09:11 PM

Thanks for pointing me to your Tutorial Ginku! 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. alt text

alt text

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 link text link text

results.png (240.7 kB)
bp_webcam.png (190.7 kB)
avatar image Ginku Aug 04 '15 at 11:59 PM

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: https://thefreecoder.wordpress.com/2012/09/11/opencv-c-video-capture/

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, Ginku

avatar image Kirmet The Frog Aug 17 '15 at 04:26 PM

Thank you Ginku!

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

avatar image Tim C ♦♦ STAFF Oct 19 '15 at 08:30 PM

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 Ginku 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.

Tim

avatar image dsjolie Oct 20 '15 at 10:00 AM

Hi Tim,

Great to see your involvement in this. :)

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

avatar image Ginku Oct 21 '15 at 02:44 PM

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. :)

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. :)

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, Ginku

avatar image Nostro Tempore Nov 01 '15 at 11:07 PM

Hi Ginku

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I'm not sure what fixed it, but following https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System 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.

alt text

Here's a webcam in unreal! :D

more ▼

answered Jun 17 '15 at 11:02 PM

avatar image

Ginku
81 6 8 10

avatar image maije Jul 02 '15 at 01:01 PM

Hi there Ginku,

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

avatar image maije Jul 03 '15 at 08:34 AM

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 :-) I really hope this could be useful for someone else in getting less frustrated than me :-P Best regards, maije

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hi there "OCV + Unreal4" guys :-D

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... :-(

I've found this link:

https://answers.unrealengine.com/questions/36777/crash-with-opencvfindcontour.html

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 :-) Best regards, maije

more ▼

answered Aug 06 '15 at 12:14 PM

avatar image

maije
6 5 8

avatar image num3ric Jan 29 '16 at 09:19 PM

Oh, I'm facing the exact same issue with findContours CV3. Which solution did you end up going with in the end?

avatar image maije Jan 30 '16 at 03:39 PM

At last I had to precompile my code into a DLL and use it as external library inside Unreal :-) In general, I recommed to precompile your external code into DLLs to avoid memory issues with unreal's garbage collector :-)

I hope this could be a little help ;-)

avatar image dsjolie Feb 02 '16 at 08:10 AM

I'm curious if you ran into any other issues with cv::findContours when you were investigating this issue. I had similar symptoms and as I kept digging I got strange memory-management-related errors in simple examples using cv::findContours, without Unreal Engine. When I google the issue it seems there is a history of compability issues between Visual Studio and cv::findContours.

I'm running Windows 10 and Visual Studio 2015. I get issues on several computers, but one other possibility is that installing Unreal Engine somehow affects the development environment.

Did you get any issues with cv::findContours without Unreal Engine?

avatar image maije Feb 02 '16 at 08:39 AM

Hi dsjolie :-)

No, I had no issues working with findContours out of Unreal. After dive into this question, I figured out that it was a problem not with findContours but with the std::vector filled inside. I guessed Unreal's Garbage Collector didn't know how to free that vector filled "out of its scope" inside OCV. I readed somewhere that Unreal's GB presents some known incompatibilities with standard containers as well, so they recomend you to use their own containers.

Considering the fact that OCV works with standard containers, I found no more solutions than precompile the code which uses those containers into a DLL :-)

In any case I would never defend the use of Windows or VS as a stable development environment (Windows latest version even less). I'm only using Windows (7 Pro) and VS (2013) because there is more documentation and Unreal's hot reload functions were built to work in collaboration with VS. I would prefer to use Ubuntu + QTCreator, which is possible, but less supported ;-)

I don't think Unreal Engine is interfering with OCV normal behaviour, but maybe I'm wrong. Best regards and I hope to be a help in some aspect :-)

avatar image dsjolie Feb 02 '16 at 08:58 AM

Hi maije,

Thanks for the quick reply! :)

I'll try to update you all if/when I get to the bottom of this on my end.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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 :-) 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, maije

more ▼

answered Jul 03 '15 at 08:28 AM

avatar image

maije
6 5 8

avatar image Kirmet The Frog Jul 29 '15 at 03:07 AM

Hello Ginku,

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 :

https://github.com/lmalave/unreal-augmented-reality-toolkit and https://forums.unrealengine.com/showthread.php?61365-AR-implemented-with-OpenCV-webcam-capture-drawn-to-dynamic-texture

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thank you so much Ginku,

I just have a look at your tuto. As soon as I can follow it, I'll tell you how it was :-D

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, maije

more ▼

answered Aug 04 '15 at 09:12 AM

avatar image

maije
6 5 8

avatar image Ginku Aug 05 '15 at 12:04 AM

Hello maije,

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

Thanks, Ginku

avatar image maije Aug 05 '15 at 07:28 AM

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 :-D

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, maije

avatar image Ginku Oct 21 '15 at 09:08 PM

Hello again maije,

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

Have a good day, Ginku

avatar image maije Oct 22 '15 at 08:12 AM

Amazing news Ginku! :-D

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 ;-) Best regards, maije

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Hello,

I followed your tutorial,and got the problem the same as Rokew's. you said that you had updated the newest tutorial but I couldn't find it. I just want to know how to fix the small API change,ver4.13 works fine. I am newb,too.

best regards

more ▼

answered Jan 11 '17 at 09:54 AM

avatar image

keffsmya
1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question