简体   繁体   中英

How to include OpenCV header files into C++ project?

I'm a rookie in both C++ and OpenCV, so please do excuse me if my question is foolish. Basically I'm trying to follow this tutorial for processing image by native C++. But the problem is I'm unable to include the necessary header files #include <opencv2/core/core.hpp> . Can anyone please help me to fix this issue?

Code:

#include <jni.h>
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "enhance.h"
using namespace std;
using namespace cv;

JNIEXPORT void JNICALL
Java_org_fossasia_phimpme_editor_editimage_filter_PhotoProcessing_nativeApplyFilter(JNIEnv     *env, jclass type, jlong inpAddr,jlong outAddr) {
   Mat &src = *(Mat*)inpAddr;
   Mat &dst = *(Mat*)outAddr;
   applyFilter(src, dst);
 }

I do not believe this is a C or OpenCV problem what you have is Linking problem

If you try to include #include <opencv2/core/core.hpp> and it cannot read it, then this means that your compiler cannot find OpenCV2 folder in its search list, this is because it's not part of visual studio, so you need to download openCV library then add it to your project and then link it to your project in order to use it!

What you need to do is go to project properties first select ALL configuration then under configuration properties select C/C++ then you will see additional include directories go add the directory to openCV2 ie if you made folder in your project called include, add opencv2 there then in your address just use .\\include\\ and remember to always end your path with \\ to avoid linking problems then you can include #include <opencv2/core/core.hpp> inside your project

If you have specific libraries you can add it in Linker then go to additional library directories there you can add libraries if you have it as .lib files

NOTE: MAKE SURE YOU SET THE RIGHT PLATFORM so don't do this settings for X86 and then expect it to work for X64 yes if you made the setting for X64 project, these settings will not apply to X86 project so you need to make sure you specify the settings for the right platform

Full description on how to set up your project can be found in their documentation HERE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM