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 correctly link to and use OpenCV?

I'm using VS2015. Here's what I have so far:

  1. I've added the include files and the lib file to Build.cs file as follows:

          using UnrealBuildTool;
             public class MyProject : ModuleRules
             {
                 public MyProject(TargetInfo Target)
                 {
                         PublicIncludePaths.Add(@"C:/PathToOpenCV/build/include");
                         PublicAdditionalLibraries.Add(@"C:/PathToOpenCV/build/x64/vc12/lib/opencv_world300d.lib");
                         PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
                         PrivateDependencyModuleNames.AddRange(new string[] {  });
                 }
             }
    
    
  2. The DLL file of same name is sitting in the same directory as the LIB file.

  3. Everything compiles nicely at this point, including my custom actor classes.

  4. If I attempt to #include a .hpp file from the OpenCV source (such as objdectect.hpp) at the top of one of my existing headers, I get a bunch of nasty errors such as "error C4003: not enough actual parameters for macro 'check'", which I believe are macro collisions and other nastiness. I'm not about to try troubleshooting collisions with OpenCV if I can help it... WAY out of my league.

So if I ditch the OpenCV source entirely, is there a way to simply call out to a function in the OpenCV DLL without this headache? I presume it'd be the same for any DLL, but any explanation I've found so far has been outdated, incomplete, or has otherwise lead into a swamp of unanswered questions.

Product Version: UE 4.13
Tags:
more ▼

asked Oct 24 '16 at 05:54 PM in C++ Programming

avatar image

longearsdesign
6 1 2 3

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

3 answers: sort voted first

You can check my tutorial on integrating OpenCV into Unreal Engine 4.17 with Visual Studio 2017 :) https://wiki.unrealengine.com/Detailed_Account_Of_Integrating_OpenCV_Into_UE4_With_VS2017

more ▼

answered Dec 03 '17 at 04:28 AM

avatar image

mintchococookie
31 3

avatar image lumbabumba Mar 17 '19 at 10:04 PM

Hello, if someone else has problem to link OpenCV 4 with UE4 and gets the -too many arguments for function-like macro invocation 'check'- or the - syntax error: 'end Parse' ''- in the cvstd_wrapper.hpp its because UE4 macros are conflicting.

I don't know why someone would use 'check' for macros but u can find more here

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

I don't know how to do it but there's a tutorial on Wiki.

https://wiki.unrealengine.com/Integrating_OpenCV_Into_Unreal_Engine_4

more ▼

answered Oct 24 '16 at 05:59 PM

avatar image

samuelhely
59 1 6 8

avatar image longearsdesign Oct 24 '16 at 06:09 PM

I seem to remember this one being a dead-end as well. Perhaps I had an older version of this page, as I don't recall the resolution for library collisions being there. I'll give this one another try and reply back with my findings.

avatar image longearsdesign Oct 24 '16 at 06:24 PM

Gave it another shot, and the same thing happened as the first time I tried this one. Per the README file:

  • unzip this folder DONE

  • add the Binaries, Plugins, and ThirdParty folders to your UE4 project (merge if prompted) DONE

  • launch the project DONE

On launch, "The following modules are missing or built with a different engine version: UE4Editor-OpenCV.dll." Would you like to rebuild them now?" YES "MyProject could not be compiled. Try rebuilding from source manually."

I'm hoping I don't need to track down the developer for this apparently outdated plugin. But I'll keep it as an option if there's no simple way to call out to the DLL.

avatar image longearsdesign Oct 24 '16 at 06:41 PM

Attempting a build directly through VS: OpenCV.Build.cs(10,44): error CS0619: 'UnrealBuildTool.RulesCompiler.GetModuleFilename(string)' is obsolete... ; So I updated OpenCV.Build.cs per this answer. On build, I still get "fatal error LNK1181: cannot open input file 'opencv_ts300.lib'"... If there's some sign this plugin has been viable in recent history, I'll follow it down the rabbit hole.

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

I think I MAY have it solved. Now, I haven't tested out the functions yet, or tried to package with the DLL, but here are my steps:

  1. Add the following into your Build.cs file, in public MyProject(TargetInfo Target), using paths to your include folder and lib file for OpenCV (3.0.0 in this case):

    PublicIncludePaths.Add(@"C:/PathToOpenCV/build/include"); PublicAdditionalLibraries.Add(@"C:/PathToOpenCV/build/x64/vc12/lib/opencv_world300d.lib");

  2. In the OpenCV code, find and comment out the declaration "bool check() const;" In 3.0.0, it's in utility.hpp, on line 729.

  3. In the header file of the cpp file in which you want to use the OpenCV method, #include the appropriate header file from the OpenCV includes. Be sure to do that before any ".generated.h" header gets #included.

  4. In your code in the cpp file, type "cv::". You should see the OpenCV members exposed via the cv namespace!

more ▼

answered Oct 24 '16 at 07:07 PM

avatar image

longearsdesign
6 1 2 3

avatar image longearsdesign Oct 24 '16 at 08:10 PM

I'm able to work with the OpenCV members in VS, and can even play the game in UE4. However I'm off-and-on getting messages when I start up or try to play standalone: "The game module 'MyProject' could not be loaded. There may be an operating system error or the module may not be properly set up.' I'm really starting to get homesick for Unity at this point.

avatar image NymKappa Nov 10 '16 at 03:37 PM

This error means UE4 can't find the proper dlls to load at runtime. Make sure you've copied the OpenCV .dll next to your game .dll :-)

avatar image Ginku Nov 26 '16 at 07:49 PM

I have updated my tutorial and plugin for 4.14 with opencv 3.0. There was a small API change which is included in the updates. :)

As for the dll problems, your system needs to know where the dll's are at runtime. In my tutorial I suggest putting the 'opencv_world300.dll' file in the binaries folder of your project. This works for play-in-editor, but if you use any other features (such as packaging your game) then you will need to place this file in the same folder as your project's executable (project.exe) file.

Have fun with your OpenCV / UE4 projects! :)

-Ginku

avatar image Ansjj May 05 '17 at 08:25 PM

Hello Ginku,

I've been able to successfully run your plugin inside my UE4 4.14 project. Thank you so much, it has been great help. One issue I face is its resolution is stuck at 640 * 360 which is very low. Enabling should resize and changing resolution cause UE4 to crash. Can you please guide me how can I improve he resolution? I've tried multiple cameras, they are all Full HD.

Thanks in advance.

(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