Error:(6, 10) fatal error: 'opencv2/opencv.hpp' file not found

asked 2017-11-22 02:35:59 -0500

namacos gravatar image

updated 2017-11-22 05:03:01 -0500

I know that there are many threads that have some solution for this problem but I did not managed to resolve my issue with non of them.

I spent like a few days already on this compile error and still no success.

I use Android Studio and opencv 3.3.1

I got opencv .a files placed under jniLibs. I got .h file under jni with heder like this

#include "opencv2/opencv.hpp"

If I remove that include everything builds and I am also able to call cpp methods from java via JNI. But when it comes to this include it seems like something is not connected correctly

inside my CMakeLists.txt i have this

cmake_minimum_required(VERSION 3.4.0)

set(OpenCV_DIR /usr/local/Cellar/opencv/3.3.1_1/share/OpenCV)


    /usr/local/Cellar/opencv/3.3.1_1/ )

find_package( OpenCV REQUIRED )

My biggest problem I this moment is I do not know how to locate the problem :(. I do not know if my CMakeList.txt is wrong, or build.gradle or what else... Please help me find the problem

When I build with android studio all I got is line

Error:(6, 10) fatal error: 'opencv2/opencv.hpp' file not found


edit1: for the SET(OpenCV_DIR "D:/libs/opencv-3.3/build/") comment

I am on Mac not on windows so my paths i little different I got


and inside this path I got

INSTALL_RECEIPT.json LICENSE                bin                  include              lib                  share

but not build

edit retag flag offensive close merge delete


Hi I'm not 100% sure but in my cmake files under Windows I have added the following lines:

    MESSAGE(FATAL_ERROR "OpenCV not found.")



#now adding ALL opencv dlls
FILE(GLOB opencv_dlls "${OpenCV_DIR}/x64/vc15/bin/*.dll")

VxW gravatar imageVxW ( 2017-11-22 02:58:31 -0500 )edit

hi, @namacos, there were 10 duplicates of your question here !

it's probably not your fault, seems to happen while ppl are in the moderation queue.

however, if you recall anything, that led to this, like a flaw in the website, please let us know !

berak gravatar imageberak ( 2017-11-22 03:04:02 -0500 )edit

where is your OpenCV_DIR defined ?

namacos gravatar imagenamacos ( 2017-11-22 03:09:33 -0500 )edit

my OpenCV_Dir is

SET(OpenCV_DIR "D:/libs/opencv-3.3/build/")
VxW gravatar imageVxW ( 2017-11-22 04:55:22 -0500 )edit

I know I should nod duplicate things, but to be honest non of the previous duplicates solves my problem. I tried everything. I seems like a common problem for some miss-configuration but there is no obvious solution to this (at least not for beginners like me).

namacos gravatar imagenamacos ( 2017-11-22 04:56:47 -0500 )edit

@VxW please see my edit, thanks

namacos gravatar imagenamacos ( 2017-11-22 05:03:31 -0500 )edit

I'm not familar with Mac but what happens if you set your OpenCV_Dir to the location where your OpenCV cmake file is located?

VxW gravatar imageVxW ( 2017-11-22 05:09:54 -0500 )edit
namacos gravatar imagenamacos ( 2017-11-23 06:51:11 -0500 )edit