Follow Install CUDA and cuDNN part: ua-cam.com/video/PlW9zAg4cx8/v-deo.html Updated Tutorial for OpenCV 4.5.1 with Virtual Environment Build: ua-cam.com/video/YsmhKar8oOc/v-deo.html YOLOv4 with Darknet on Windows: ua-cam.com/video/FE2GBeKuqpc/v-deo.html YOLOv3 YOLOv4 with OpenCV: ua-cam.com/video/FjyF03uawsA/v-deo.html YOLOv4 Darknet: ua-cam.com/video/FE2GBeKuqpc/v-deo.html YOLOv4 Custom Detector: ua-cam.com/video/sKDysNtnhJ4/v-deo.html YOLOv4 TensorFlow and TFLite: ua-cam.com/video/tCmC7nyfJp8/v-deo.html
Notes: 1. Uninstall VS Python 2. Install latest Anaconda3(python 3.8.5) 3. Uninstall included Numpy, install numpy==1.19.3 4. Install appropiate Nvidia CUDA, get developer cuDNN files and merge them with CUDA Thanks for the video it helped me 10x!
Thank You so much sir.I don't have words to express my gratitude.I badly needed to get OpenCV running with CUDA for my college project,and I was running out of time.I've spent many,many hours of the past week trying to get this work.I do not have much experience in such stuff and I couldn't find a detailed step by step video on this topic.Thank you so much once again.You made my day!
A big shoutout for you. You made very precise and simple video explaining all the step with clarity. I would definitely share your channel to my peers. Thanks a lot!!
Thanks you very much. For those struggling with the "ModuleNotFoundError: No module named 'cv2' ". In the step where you set up the CMake configuration add this entry "BUILD_opencv_python3" type boolean and check it.
@@siminesfshani8668 In Cmake, Before you hit configure, Cmake allows you to add entrys, so you add "BUILD_opencv_python3" and set it to TRUE, then after you hit configure you should see this included in the output: Python 3: Interpreter: C:/ProgramData/Anaconda3/python.exe (ver 3.8.5) Libraries: C:/ProgramData/Anaconda3/libs/python38.lib (ver 3.8.5) numpy: C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include (ver ) install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.8 Python (for build): C:/ProgramData/Anaconda3/python.exe ( This is MY configuration, you should have your own Path to your Python/Anaconda executables, make sure they are correct )
Hey mate thanks a ton! It would definitely be worth ensuring people are aware of the requirement to download and add the zlib.dll to the environment path to ensure correct running of cuDNN otherwise it will throw cuda related errors when compiling. Its an easy fix but something noone mentions in their installation tutorials and leads to unneccessary issues. Thanks for the tutorial, keep up the good work!
Dear all...It works! After 2 days, i can build OpenCV with CUDA support Excellent work. Thanks for the all the efforts. I am trying to build Darknet / Yolo4 on Windows 10. Any suggestion, how to proceed from here. If not mistaken, i can use the Anaconda base environment for the Darknet /Yolo4 as well. Cheers!
Yes you can. There is another video on Darknet YOLOv4 which you can follow from here. You will need opencv_worldxxxx.dll file (where xxx is the version of openCV, 440 in this video or 451 in the case of 2021 video). So if you plan to build darknet, you should build opencv with opencv_world enabled (tick box) in CMake. After that, you can follow this video ua-cam.com/video/FE2GBeKuqpc/v-deo.html
This took me about half a day to get right but I have to say your tutorial has been the best one I've found on this topic. There were a couple of issues that initially caused my setup not to work in anaconda: 1. Early on during the first CMake configuration there was a numpy error. Specifically I had numpy 1.19.4 in my base installation and ran into this issue (stackoverflow.com/questions/64654805/how-do-you-fix-runtimeerror-package-fails-to-pass-a-sanity-check-for-numpy-an). I resolved it by uninstalling 1.19.4 and installing 1.19.3. You might need to reconfigure after doing this. In my case I already built everything before noticing so I had to start from scratch. 2. After installing everything I tried to "import cv2 " in my base anaconda env and got this error: ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation. Couldn't find a good solution on the web but fortunately all I needed to do was open a new MiniConda shell env and then the import worked! Now I just needed to get this working in a separate environment. Unfortunately it seems that you can only compile for one python version. So if you have multiple conda environments with the same python version then no problem. But I had one conda env with python 3.8 and another with 3.7. Unfortunately I ended up having to build opencv separately for both environments. Wasn't pretty but at least now I have opencv with gpu working! Thanks a lot!
Hi @Simeon , Unfortunately, I have problem like you, "ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.", Could you help me clear all off step you have done to fix this, Thanks in advanced
I'm very sorry. I followed guide. Everything was ok, finally, I built everything in VS as it was in the video, however, after that I tried to import cv2 and it tells that there is no such module
Hello, I did it without any er rors until the cmake compilation process, but after doing the ALLBUILD build in visual studio, it gives me an error. Can you help me?
I built the opencv in directory F and python 38 is in C:/, and "i recieve ImportError: DLL load failed while importing cv2: The specified module could not be found." when try to import. I have tried rebuilding with numpy 1.19.5 version. How should i fix this? do i need to add path in environment variable?
You should try updated version of the tutorial. Perhaps you have not been able to tell CMake the path of your Python installation. This is made clear here: ua-cam.com/video/YsmhKar8oOc/v-deo.html
On second configure Configuring incomplete, errors occurred! See also "C:/Opencv_built/build/CMakeFiles/CMakeOutput.log". See also "C:/Opencv_built/build/CMakeFiles/CMakeError.log".
Not working with cuda 10.2 cudnn 8, python 3.9, vs 2019 and opencv 4.53. Is it possible that you can compile python bindings and binaries for this system and share it here?
Hello, I use the same graphics card ,and I installed CUDA-9.2 lastly in Windows 10. At cmake’s Configure and Generate step, all is fine and working well. But when I tried to build OpenCV-4.2.0 with CUDA in Visual Studio 2015, it take many errors about CUDA. I am trying to solve these problems and check all step for many times but no use. Is that CUDA-9.2 is compatible with OpenCV-4.2.0?
Hey i followed the installation very well till the end with zero errors or issues, but after i build the install part, i saw only 1 successful instead of 2 as shown in the video. when in anaconda prompt i am not able to import cv2. The error states no module named cv2. I have done this installation multiple times and i dont know what the issue is
Here are possible reasons. You have virtual environment of Python. You have multiple Python versions installed. There should be a file inside your build/lib/python3/Release folder called cv2.cp38-win_amd64.pyd .... Copy that in your site-packages folder of Anaconda3.
I installed OpenCV as in the video. But I can't import cv2. I am getting an error. The error is as follows: >>> import cv2 Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2' Can you help me?
Gracias todo esta perfecto. Se recomienda PRIMERO: eliminar python, anaconda, Visual Studio, y luego instalar todo NUEVO: Anaconda y Visual Studio. Verificar las rutas.
Hola Rudy, como haces para hacer funcionar CV2 con Anaconda ? Ya intente settear el Python Path en CMake pero no tengo exito, algun tip ? Gracias de antemano
after following it all, when I check the import cv2 on anaconda it says Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2' Theres no error on the VS, what did I miss?
hi, when i build the sln file ALL_BUILD i get two types of errors (windows 11/opencv4.5.5/opencv-contrib4.5.5/vs2022): -- error codes -- (1) C1356 unable to find mspdbcore.dll libpng (2) C1060 compiler is out of heap space opencv_test_core_AVX (3) LNK1181 cannot open input file '..\..\lib\Release\opencv_phase_unwrapping455.lib' (4) C1076 compiler limit: internal heap limit reached opencv_gapi (5) C3859 Failed to create virtual memory for PCH opencv_videoio -- warning codes -- (1) #1394-D field of class type without a DLL interface used in a class with a DLL opencv_cudaarithm (2) #1388-D base class dllexport/dllimport specification differs from that of the derived class opencv_cudaarithm (3) C4505 'cv::cudev::atomicAdd': unreferenced function with internal linkage has been removed opencv_cudaarithm (4) C4267 '=': conversion from 'size_t' to 'int', possible loss of data opencv_core (5) LNK4098 defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library opencv_core (6) #1215-D function "tex2D(texture, float, float) [with T=float]" opencv_cudawarping (7) C4996 'cudaBindTexture2D': was declared deprecated opencv_cudawarping (8) C4805 '|': unsafe mix of type 'int' and type 'bool' in operation opencv_dnn (9) C4244 'argument': conversion from 'uint' to 'const unsigned char' opencv_cudastereo (10) C4244 '=': conversion from 'const _Ty' to 'float', possible loss of data opencv_cudaarithm (11) C4189 'ITEMS_PER_THREAD': local variable is initialized but not referenced opencv_dnn Total ERRORS: 147 Total WARNINGS: 2947 ERRORS: 58>LINK : fatal error LNK1181: cannot open input file '..\..\lib\Release\opencv_imgproc455.lib' 58>Done building project "opencv_features2d.vcxproj" -- FAILED. 78>please visit aka.ms/pch-help for more details 78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\backends\common\gcompoundbackend.cpp(1,1): error C1076: compiler limit: internal heap limit reached 78>(compiling source file '../../../opencv-4.5.5/modules/gapi/src/backends/common/gcompoundbackend.cpp') 78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1): error C3859: Failed to create virtual memory for PCH 78>(compiling source file '../../../opencv-4.5.5/modules/gapi/src/api/s11n.cpp') 78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1): 78>PCH: Unable to commit memory across file map 78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1): 78>please visit aka.ms/pch-help for more details build output tail: 197>------ Build started: Project: opencv_perf_cudafeatures2d, Configuration: Release x64 ------ 198>------ Build started: Project: opencv_perf_cudacodec, Configuration: Release x64 ------ 197>A task was canceled. 197>A task was canceled. 198>A task was canceled. 198>A task was canceled. 199>------ Build started: Project: opencv_perf_cudabgsegm, Configuration: Release x64 ------ 200>------ Build started: Project: opencv_perf_cudaarithm, Configuration: Release x64 ------ 199>A task was canceled. 199>A task was canceled. 200>A task was canceled. 200>A task was canceled. 201>------ Build started: Project: opencv_perf_core, Configuration: Release x64 ------ 202>------ Build started: Project: opencv_perf_calib3d, Configuration: Release x64 ------ 201>A task was canceled. 201>A task was canceled. 202>A task was canceled. 202>A task was canceled. 203>------ Build started: Project: opencv_perf_bioinspired, Configuration: Release x64 ------ 203>A task was canceled. 203>A task was canceled. 204>------ Build started: Project: ALL_BUILD, Configuration: Release x64 ------ 204>A task was canceled. 204>A task was canceled. ========== Build: 42 succeeded, 162 failed, 0 up-to-date, 0 skipped ========== ========== Build completed at 9:26 PM and took 24:34.245 minutes ==========
You will need to build for virtual environment again. You need to set all the paths to python3 directories in Cmake to point the virtual environment (which are by default set to base environment).
Hey I have a problem with the cmake build, after activating the BUILD_opencv_world, my visual studio can not find the lib/Release/opencv_world480.lib file.. I'm using cuda 12, cudnn 8.9, opencv 4.8 and opencv contrib 4.8
I could compile OpenCV in VS 2017 without warnings or errorsconfigured for CUDA 10.0, cuDNN 7.6.5(Nvidia GTX 1070), on Python 3.8, and added an ENTRY BUILD_opencv_python3 and checked it before compiling in CMake without any errors. Tried 2 time to install same CUDA and cuDNN as yours but crashes In ALL BUILD compilation I get Build: 188 succeeded, but with INSTALL I only get 1 succeed and anaconda prompt does not recognize opencv. Watched 2 videos about compiling custom OpenCV and both show 2 succeed. What the heck is wrong?
this is the worst thing i have installed in years. the module can't be found tryed all the answer here and above, i tried remove all my python version, then remove all my system variables, the build have no errors, when i compile in the visual studio. this is imposible and sad
Hello, I successfully installed and builded everything. I can get same output when write cv2.cuda.getCudaEnabledDeviceCount() on command panel. But how can I use this command a .py file. When I try to use, I am getting error.
Hi sir when building I get linking error "LNK1181 can't find input file \lib\Release\opencv_core440.lib". This error also happens but with different .lib files such as opencv_flann440.lib, opencv_imageproc440.lib, etc. I don't get any errors during the Configuring or Generating process. How do I fix this?
when I try to import cv2 i get the error: ImportError: OpenCV loader: missing configuration file: ['config-3.8.py', 'config-3.py']. Check OpenCV installation. Any idea how to fix this?
hi, it worked for me thank you, but can i know what happened if i delete the " build " folder after everything is done? I still can use cv2 module or not?
My laptop have 2 graphic card ( intel, nvidia gpu) , i setup opencv like your video but when i run a project , it's auto run with intel gpu, how can i run with nvidia gpu?
all went well with no errors... but when i import cv2 in conda it does not find the opencv module... is there a wat to link the build installed in another driveto anaconda base environment? somehow the opencv is not linking with the anaconda library...
If everything builds fine without any error and you still get "Module Not Found" error, You need to update numpy to latest version and then clear cache in Cmake by going to file >> delete cache. Then build everything again and it will work.
Great video!!! But I am facing a problem here: my build folder is missing the .sln file along with many others. I don't understand what I did wrong, could you please help me with this?
I have DLL module problem now. Traceback (most recent call last): File "", line 1, in File "C:\Python38\lib\site-packages\cv2\__init__.py", line 96, in bootstrap() File "C:\Python38\lib\site-packages\cv2\__init__.py", line 86, in bootstrap import cv2 ImportError: DLL load failed while importing cv2: The specified module could not be found.
Iftekher Hossain im not sure how and why. But what I did was: uninstall my previous python (3.7.5) and install to (3.7.9). You also need to check the path of its download. Dont store it at AppData/local. Instead create new folder “Python37” at C:// or anything. Then after you installed your python, then you can proceed with this tutorial
@@TheCodingBug I missed to check that part, yes setting path for python is not easy. I finally could able to compile all without error and with python after few attempt. I gave thumps up to this video as I also learned from this video, it is a short and crisp video to setup the opencv without fuss.
@TheCodingBug Hi. thanks for the video . when I follow the steps it got work on conda base env can I copy it to another env or do i need to rebuild it from scratch with new env python path ?
I have a problem after installing the OpenCV.sln and anaconda cmd write "import cv2" where it says Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2' Please help me!
Dude, add this to your Cmake configuration and try again "BUILD_opencv_python3" and set its value to True (Checkbox), I spend a whole day trying to make this work. Good luck !
In Cmake when you hit Configure, after the process is done, there is an Output right ? This output should have something like this (Depending on your paths to python or if you are using Anaconda) : Python 3: Interpreter: C:/ProgramData/Anaconda3/python.exe (ver 3.8.5) Libraries: C:/ProgramData/Anaconda3/libs/python38.lib (ver 3.8.5) numpy: C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include (ver ) install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.8 Python (for build): C:/ProgramData/Anaconda3/python.exe
@@dedenapraia maybe my path to python and anaconda are wrong. Currently it is NOT in ProgramData, but C:\Users\caomi\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8
@@helloankur2009 In CMake GUI, search for PYTHON3_ and you will see a bunch of paths, which are set to base Anaconda3 directories. You need to set all of them to virtual environment directories. For example: PYTHON3_EXECUTABLE is set to C:\USsers\Anaconda3\python.exe It will become C:\Users\Anaconda3\env\myVirtualEnv\python.exe and same goes for all other PYTHON3_ paths. If it does not work, I will be posting an updated tutorial next week with all the configurations in a script. Which will be easier to setup.
@@TheCodingBug Hi I am able to use in pycharm by the base interpreter from c:\User\\...\\..\\. Thanks for your help and support.. can you share some code on how to use cv2 with Cuda to open image and video?
@@TheCodingBug Actually I checked everything on the web and it shows it supports cuda with compute capacity of 5.0 but after I did all the things it showed around 200 errors in Visual Studio will building all build and most of the errors were with linker showing unable to open file and sometimes unable to detect file. This was through LNK1181. Any suggestions???
@@thatHandsomeGeek you can try updated method for building opencv (2021) that I've posted. I am unable to verify for this GPU as I do not have access to yhis GPU.
I have some problems after installing the OpenCV.sln, where it says Traceback (most recent call last): File "", line 1, in ModuleNotFoundError: No module named 'cv2'
I get "Error in configuration process, project files may be infalid" from CMake when i click Configure for the second time, after setting extra module path to opencv_contrib... I've tried both OpenCV 4.4.0 and 4.5.0 and i keep getting this error.
@@miroslavgechev4852 Using your method, my cmake has stopped crashing, but now I am getting this error: Configuring incomplete, errors occurred! See also "D:/yolo/build/CMakeFiles/CMakeOutput.log". See also "D:/yolo/build/CMakeFiles/CMakeError.log".
Do you have any idea why this error occurs? Thanks in advance. raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames)) ImportError: OpenCV loader: missing configuration file: ['config-3.7.py', 'config-3.py']. Check OpenCV installation.
Your site-packages/cv2 does not have config-3.7.py file. Either you have multiple Python versions or there is the wrong file at that location (maybe config-3.6.py)
@@mdiftekherhossain6152 If you have native python, only install one version (Probably Python 3.8). Uninstall all other versions. Alternatively, you can install Anaconda with Python 3.8 and reinstall OpenCV. Anaconda is always a convenient way to install Python.
yes. I have native python and initially, cmake path was that. I have changed all the paths to the anaconda path. will uninstalling native python help to get rid of the error? Thanks for your suggestion
@@mdiftekherhossain6152 No. You will have to build OpenCV for one environment (either native or Anaconda). You will have to build it again and carefully check which version CMake picks up in PYTHON3_EXECUTABLE etc.
Hi. The installation of OpenCV from source is equivalent to installing using pip in a way that for every virtual environment (VE), you activate the VE, and then do pip install for that particular environment. Similarly, to build a package from source and installing it to VE requires that we set the right paths for CMake. For system wide installation, notice the options in CMAKE starting with PYTHON3. They all are pointed to the system wide directories. You need to point them to corresponding VE directories. Following is an example: PYTHON3_EXECUTABLE=~/.envs/myenv/bin/python.exe PYTHON3_INCLUDE_DIR=~/.envs/myenv/bin/python/include Hope that it will solve the problem. If not, comment down below and I will make a tutorial on how to build it for VE.
You can do this for any environment. Just make sure that CMake picks up paths for Python3 correctly (all paths including site_packages, python.exe etc). If it does not, You will have to manually define them. Otherwise, it will return "Module not found" error when you will import it to Python.
Its been long since I abandoned PyCharm so I am not sure how this can be done because as far as I can remember, PyCharm had its own repository to install from (somewhere in the project setting).
Thanks for the turotial. Ive followed the steps and everything went successfully (no errors during the build process). However, when i´ve checked the opencv through import cv2 in the base environment in anaconda, it returned the error ( ModuleNotFoundError: No module named 'cv2'). So what could the problem be?
@@khaledjbaili8654 You need to upgrade numpy as then build again. During CMake build, the message is printed at the end showing for which python version the build would be installed. If you do not see this message, you will not get python bindings. Numpy is used during creation of python bindings. If its outdated version, it will not going to work.
@@TheCodingBug okay i will rebuild again. do i have to rebuild starting from the begining (from cmake) or from visual studio?. Just want be sure that every thing is done as it should be. Ive placed the build file in Disk E:\OPENCV_CUDA, while the default path of the kernel (base) of anaconda as i open it, is (base) C:\Users\engjb>. should the build be in the same path or it doesnt matter
Hi, you are my last hope, I am using OpenCV 4.4.0 with numpy 1.20.0, trying to bind tensorflow version 2.4.0 and it gives me an error (NotImplementedError: Cannot convert a symbolic Tensor (random_zoom/zoom_matrix/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported), but it also works fine on numpy version 1.19.2, but from this version CV2 crashes with an error (RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd). Please tell me what could be the problem? python 3.8.5
@@TheCodingBug I apologize for the importunity, but please tell me, I started to give out a similar error "print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU'))) AttributeError: module 'tensorflow' has no attribute 'config'"
If you are installing cuda for GPU or following this video ( ua-cam.com/video/FE2GBeKuqpc/v-deo.html ) for the yolov4 don't forgot to select BUILD_opencv_world during the CMAKE process otherwise you will be in trouble during the Darknet installation. If you find this comment helpful then please pin it. or if I am wrong please let me know I will remove this comment. So that it will not create any confusion. Thank You.
@@saber3747 TensorFlow needs compatible version of CUDA qnd cuDNN. you can inatall TensorFlow GPU in a separate environment along with supported CUDA amd cuDNN. Here's how to do it. ua-cam.com/video/toJe8ZbFhEc/v-deo.html
Thank you for your video. I have followed every steps in the video but still I get no module found when trying to import cv2. Do you know how I can fix it? Please help
@@luiscao7241 I managed to fix that by setting the directory for python libraries. I found this solution among the comments in the video. Here is the link screenshot of the comment: www.dropbox.com/s/96e3rg61tkorg2n/Photo%202021-01-10%2C%2012%2036%2055%20AM.png?dl=0
If everything builds fine without any error and you still get "Module Not Found" error, You need to update numpy to latest version and then clear cache in Cmake by going to file >> delete cache. Then build everything again and it will work.
Sometimes it does not open with administrator rights so the build process can throw an error. So using the command prompt as Administrator ensures that the project file will be opened as Administrator.
Hi man, thanks a lot for the tutorial, really appreciated, I am new to building things with CMake so I don't have much experience, but when I click on Configure for the second time it gives me errors, that I don't know how to solve... If you want I can send you the error.log file
@@TheCodingBug Sorry if I bother you too much, but now I have another error. After compiling the ALL_Build thing and then INSTALL, and all went perfectly, but if I try to import the library on Python it won't let me...
No problem. I hope you are using Anaconda because that makes the whole process easier. But if you are using native python, make sure that CMake GUI picks up python 2/3 paths after you hit Configure for the first time. If it is not picking python paths, you will have to add it manually. If I have understood the problem rightly, this will solve the problem. If you can share the error, may be I will be in a better position to help.
Hi Codebug. You are excellent. Your videos are very easy to understand. I could successfully install the opencv-gpu in my laptop (it has GTX1070) I have a question. After compiling opencv gpu version, my anaconda or pycharm is unable to detect the compiled version. example: my build path is D:\opencv\build . when I use windows cmd CLI, and python the following command prints 1. import cv2 count = cv2.cuda.getCudaEnabledDeviceCount() print(count) but If try the same comand inside anoconda CLI or pycharm the print brings 0. Pls explain sir, after the successful compiling of opencv-gpu version, how to integrate (import) in anoconda or pycharm? thank you. my email id is dompower at gmail.com
It looks like you have multiple versions of Python installed (Anaconda and Native). During CMake build process, CMake automatically detects the python3 paths (including python.exe, site_packages etc). OpenCV will be installed for these python versions only. If it is picking up Anaconda paths, it will work with Anaconda Prompt. But if it is picking up Native python3 paths, it will work with windows CMD. Regarding PyCharm, I have never used it with custom build OpenCV. As far as I can recall, PyCharm has its own repository, which has pre-built OpenCV. But I am not sure how to integrate custom build to it.
@@TheCodingBug thanks for your solution. Would you pls guide me how can I uninstall the native python version? I strongly believe it is installed part of pycharm installation...
@@TheCodingBug Thank you very much sir. You are right. There are two versions of python. OpenCV-GPU ( i mean built from source as per your guidelines) was built for native python version. That's good. Bcs when I reinstalled pyCharm, it recognized native python and opencv-gpu (built from source) and everything is ok now. thanks you.
I am sorry to hear that. But if you use exactly same versions of everything as mine, you will be able to successfully build it. There are newer versions of Python, OpenCV, and CUDA since I made this tutorial and those might not work well with same configurations.
@@TheCodingBug Thats what i did though, figured that was an issue and reverted back to the same versions. Vc even throws errors saying vc 2017 is needed for no reason.
@@TheCodingBug VC 2019 is the issue, for some reason it seems to be very unstable. Im going to run VC 2017 from now on. Its workign perfectly even with regular python!
@@TheCodingBug yep Microsoft even locked vs 2017 behind logins so I'm keeping my copy held tight. I hope so too. Might make an updated tutorial showing how I did it with regular python for the path issues.
Hi.. I got error when building ALL_BUILD in visual studio. The error message was as follows error LNK2019: unresolved external symbol "public: __cdecl cv::cudacodec::EncoderParams::EncoderParams(void)" (??0EncoderParams@cudacodec@cv@@QEAA@XZ) referenced in function "struct _object * __cdecl pyopencv_cv_cudacodec_createVideoWriter(struct _object *,struct _object *,struct _object *)" (?pyopencv_cv_cudacodec_createVideoWriter@@YAPEAU_object@@PEAU1@00@Z) can anyone help me pls? Thanks in advance @TheCodingBug
Follow Install CUDA and cuDNN part: ua-cam.com/video/PlW9zAg4cx8/v-deo.html
Updated Tutorial for OpenCV 4.5.1 with Virtual Environment Build: ua-cam.com/video/YsmhKar8oOc/v-deo.html
YOLOv4 with Darknet on Windows:
ua-cam.com/video/FE2GBeKuqpc/v-deo.html
YOLOv3 YOLOv4 with OpenCV:
ua-cam.com/video/FjyF03uawsA/v-deo.html
YOLOv4 Darknet:
ua-cam.com/video/FE2GBeKuqpc/v-deo.html
YOLOv4 Custom Detector:
ua-cam.com/video/sKDysNtnhJ4/v-deo.html
YOLOv4 TensorFlow and TFLite:
ua-cam.com/video/tCmC7nyfJp8/v-deo.html
Notes:
1. Uninstall VS Python
2. Install latest Anaconda3(python 3.8.5)
3. Uninstall included Numpy, install numpy==1.19.3
4. Install appropiate Nvidia CUDA, get developer cuDNN files and merge them with CUDA
Thanks for the video it helped me 10x!
Installing Anaconda is not necessary, I always used Eclipse and never had problem with the compilation.
Thank You so much sir.I don't have words to express my gratitude.I badly needed to get OpenCV running with CUDA for my college project,and I was running out of time.I've spent many,many hours of the past week trying to get this work.I do not have much experience in such stuff and I couldn't find a detailed step by step video on this topic.Thank you so much once again.You made my day!
I am glad it was helpful.
@@TheCodingBug Straight up the best video on this topic on UA-cam.Thank you for making this video.
Mate, it was the most helpful video I have ever watched on UA-cam. Thank you very much, respect.
Out of all the tutorials I've found for this stuff, this one was by far the best. Thanks a lot.
A big shoutout for you. You made very precise and simple video explaining all the step with clarity. I would definitely share your channel to my peers.
Thanks a lot!!
Thanks you very much. For those struggling with the "ModuleNotFoundError: No module named 'cv2'
". In the step where you set up the CMake configuration add this entry "BUILD_opencv_python3" type boolean and check it.
Thank you!! I hope it'll help someone.
Thank you. Where we should add it exactly? I have followed all the steps but still I get cv2 not found.
@@siminesfshani8668 In Cmake, Before you hit configure, Cmake allows you to add entrys, so you add "BUILD_opencv_python3" and set it to TRUE, then after you hit configure you should see this included in the output:
Python 3:
Interpreter: C:/ProgramData/Anaconda3/python.exe (ver 3.8.5)
Libraries: C:/ProgramData/Anaconda3/libs/python38.lib (ver 3.8.5)
numpy: C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include (ver )
install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.8
Python (for build): C:/ProgramData/Anaconda3/python.exe
( This is MY configuration, you should have your own Path to your Python/Anaconda executables, make sure they are correct )
@@dedenapraia thank you it really helped
you are one of the person send by god 🙏
finally i can install it, thank you very much, but the problem i have is not updating numpy before cmake
Hey mate thanks a ton! It would definitely be worth ensuring people are aware of the requirement to download and add the zlib.dll to the environment path to ensure correct running of cuDNN otherwise it will throw cuda related errors when compiling. Its an easy fix but something noone mentions in their installation tutorials and leads to unneccessary issues. Thanks for the tutorial, keep up the good work!
Dear all...It works! After 2 days, i can build OpenCV with CUDA support Excellent work. Thanks for the all the efforts.
I am trying to build Darknet / Yolo4 on Windows 10. Any suggestion, how to proceed from here. If not mistaken, i can use the Anaconda base environment for the Darknet /Yolo4 as well. Cheers!
Yes you can. There is another video on Darknet YOLOv4 which you can follow from here. You will need opencv_worldxxxx.dll file (where xxx is the version of openCV, 440 in this video or 451 in the case of 2021 video). So if you plan to build darknet, you should build opencv with opencv_world enabled (tick box) in CMake. After that, you can follow this video ua-cam.com/video/FE2GBeKuqpc/v-deo.html
This took me about half a day to get right but I have to say your tutorial has been the best one I've found on this topic. There were a couple of issues that initially caused my setup not to work in anaconda:
1. Early on during the first CMake configuration there was a numpy error. Specifically I had numpy 1.19.4 in my base installation and ran into this issue (stackoverflow.com/questions/64654805/how-do-you-fix-runtimeerror-package-fails-to-pass-a-sanity-check-for-numpy-an). I resolved it by uninstalling 1.19.4 and installing 1.19.3. You might need to reconfigure after doing this. In my case I already built everything before noticing so I had to start from scratch.
2. After installing everything I tried to "import cv2 " in my base anaconda env and got this error:
ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.
Couldn't find a good solution on the web but fortunately all I needed to do was open a new MiniConda shell env and then the import worked!
Now I just needed to get this working in a separate environment. Unfortunately it seems that you can only compile for one python version. So if you have multiple conda environments with the same python version then no problem. But I had one conda env with python 3.8 and another with 3.7. Unfortunately I ended up having to build opencv separately for both environments. Wasn't pretty but at least now I have opencv with gpu working! Thanks a lot!
Thank you for sharing the solutions to the most common problems.
Hi @Simeon , Unfortunately, I have problem like you, "ImportError: ERROR: recursion is detected during loading of "cv2" binary extensions. Check OpenCV installation.", Could you help me clear all off step you have done to fix this, Thanks in advanced
How come when i check cv2.getCudaEnabledDeviceCount() result is 0. how to set to 1?
Very helpful, informative and straightforward video. Thank you!
I'm very sorry. I followed guide. Everything was ok, finally, I built everything in VS as it was in the video, however, after that I tried to import cv2 and it tells that there is no such module
Try the updated tutorial: ua-cam.com/video/YsmhKar8oOc/v-deo.html
Worked without any errors. However, there were bunch of warnings during build process of Visual Studio. But still it's working fine. Thanks!
I am glad I could help. Warnings are okay. Errors are not.
Hello, I did it without any er
rors until the cmake compilation process, but after doing the ALLBUILD build in visual studio, it gives me an error. Can you help me?
I built the opencv in directory F and python 38 is in C:/, and "i recieve ImportError: DLL load failed while importing cv2: The specified module could not be found." when try to import.
I have tried rebuilding with numpy 1.19.5 version. How should i fix this? do i need to add path in environment variable?
You should try updated version of the tutorial. Perhaps you have not been able to tell CMake the path of your Python installation. This is made clear here:
ua-cam.com/video/YsmhKar8oOc/v-deo.html
Same problem with someone. Used clean anaconda(3.8.5) but failed, tried python3.8.5 instead and copy the stuff as someone suggested.
On second configure
Configuring incomplete, errors occurred!
See also "C:/Opencv_built/build/CMakeFiles/CMakeOutput.log".
See also "C:/Opencv_built/build/CMakeFiles/CMakeError.log".
Try this updated tutorial. It uses alternative method to build opencv which is faster.
ua-cam.com/video/YsmhKar8oOc/v-deo.html
When building is finiched ,I got 7 errors what should i do ? I need to colorize images and videos can i move forward or not ?
Not working with cuda 10.2 cudnn 8, python 3.9, vs 2019 and opencv 4.53. Is it possible that you can compile python bindings and binaries for this system and share it here?
Check my 2021 tutorial for openCV 4.5
Please, add a similar video for LInux OS (Ubuntu 20.04 preferably). Thank you in advance, very good work so far! Thumbs up!
You are the best!
Hello, I use the same graphics card ,and I installed CUDA-9.2 lastly in Windows 10. At cmake’s Configure and Generate step, all is fine and working well.
But when I tried to build OpenCV-4.2.0 with CUDA in Visual Studio 2015, it take many errors about CUDA. I am trying to solve these problems and check all step for many times but no use. Is that CUDA-9.2 is compatible with OpenCV-4.2.0?
Great Tutorial, Thanks.
I am glad it was helpful.
Hey i followed the installation very well till the end with zero errors or issues, but after i build the install part, i saw only 1 successful instead of 2 as shown in the video. when in anaconda prompt i am not able to import cv2. The error states no module named cv2. I have done this installation multiple times and i dont know what the issue is
Here are possible reasons.
You have virtual environment of Python.
You have multiple Python versions installed.
There should be a file inside your build/lib/python3/Release folder called cv2.cp38-win_amd64.pyd .... Copy that in your site-packages folder of Anaconda3.
It worked. Thank you so much sir.
I am glad it was helpful.
I installed OpenCV as in the video. But I can't import cv2. I am getting an error. The error is as follows:
>>> import cv2
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
Can you help me?
You can follow the updated video ua-cam.com/video/YsmhKar8oOc/v-deo.html
@@TheCodingBug Thank you for your answer. I will try it
Thank you. I made sure I have tested it before giving the like and subscribe LOL
I am glad it was helpful.
Gracias todo esta perfecto. Se recomienda PRIMERO: eliminar python, anaconda, Visual Studio, y luego instalar todo NUEVO: Anaconda y Visual Studio. Verificar las rutas.
Hola Rudy, como haces para hacer funcionar CV2 con Anaconda ? Ya intente settear el Python Path en CMake pero no tengo exito, algun tip ? Gracias de antemano
@@dedenapraia Coloca el PATH de Anaconda, no de Python.
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
how to fix this
Try this updated tutorial: ua-cam.com/video/YsmhKar8oOc/v-deo.html
after following it all, when I check the import cv2 on anaconda it says Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
Theres no error on the VS, what did I miss?
The issue is addressed in this updated video ua-cam.com/video/YsmhKar8oOc/v-deo.html
hi, when i build the sln file ALL_BUILD i get two types of errors (windows 11/opencv4.5.5/opencv-contrib4.5.5/vs2022):
-- error codes --
(1) C1356 unable to find mspdbcore.dll libpng
(2) C1060 compiler is out of heap space opencv_test_core_AVX
(3) LNK1181 cannot open input file '..\..\lib\Release\opencv_phase_unwrapping455.lib'
(4) C1076 compiler limit: internal heap limit reached opencv_gapi
(5) C3859 Failed to create virtual memory for PCH opencv_videoio
-- warning codes --
(1) #1394-D field of class type without a DLL interface used in a class with a DLL opencv_cudaarithm
(2) #1388-D base class dllexport/dllimport specification differs from that of the derived class opencv_cudaarithm
(3) C4505 'cv::cudev::atomicAdd': unreferenced function with internal linkage has been removed opencv_cudaarithm
(4) C4267 '=': conversion from 'size_t' to 'int', possible loss of data opencv_core
(5) LNK4098 defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library opencv_core
(6) #1215-D function "tex2D(texture, float, float) [with T=float]" opencv_cudawarping
(7) C4996 'cudaBindTexture2D': was declared deprecated opencv_cudawarping
(8) C4805 '|': unsafe mix of type 'int' and type 'bool' in operation opencv_dnn
(9) C4244 'argument': conversion from 'uint' to 'const unsigned char' opencv_cudastereo
(10) C4244 '=': conversion from 'const _Ty' to 'float', possible loss of data opencv_cudaarithm
(11) C4189 'ITEMS_PER_THREAD': local variable is initialized but not referenced opencv_dnn
Total ERRORS: 147
Total WARNINGS: 2947
ERRORS:
58>LINK : fatal error LNK1181: cannot open input file '..\..\lib\Release\opencv_imgproc455.lib'
58>Done building project "opencv_features2d.vcxproj" -- FAILED.
78>please visit aka.ms/pch-help for more details
78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\backends\common\gcompoundbackend.cpp(1,1): error C1076: compiler limit: internal heap limit reached
78>(compiling source file '../../../opencv-4.5.5/modules/gapi/src/backends/common/gcompoundbackend.cpp')
78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1): error C3859: Failed to create virtual memory for PCH
78>(compiling source file '../../../opencv-4.5.5/modules/gapi/src/api/s11n.cpp')
78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1):
78>PCH: Unable to commit memory across file map
78>C:\Users\austo\OneDrive\Desktop\pycuda_gpu\opencv-4.5.5\modules\gapi\src\api\s11n.cpp(1,1):
78>please visit aka.ms/pch-help for more details
build output tail:
197>------ Build started: Project: opencv_perf_cudafeatures2d, Configuration: Release x64 ------
198>------ Build started: Project: opencv_perf_cudacodec, Configuration: Release x64 ------
197>A task was canceled.
197>A task was canceled.
198>A task was canceled.
198>A task was canceled.
199>------ Build started: Project: opencv_perf_cudabgsegm, Configuration: Release x64 ------
200>------ Build started: Project: opencv_perf_cudaarithm, Configuration: Release x64 ------
199>A task was canceled.
199>A task was canceled.
200>A task was canceled.
200>A task was canceled.
201>------ Build started: Project: opencv_perf_core, Configuration: Release x64 ------
202>------ Build started: Project: opencv_perf_calib3d, Configuration: Release x64 ------
201>A task was canceled.
201>A task was canceled.
202>A task was canceled.
202>A task was canceled.
203>------ Build started: Project: opencv_perf_bioinspired, Configuration: Release x64 ------
203>A task was canceled.
203>A task was canceled.
204>------ Build started: Project: ALL_BUILD, Configuration: Release x64 ------
204>A task was canceled.
204>A task was canceled.
========== Build: 42 succeeded, 162 failed, 0 up-to-date, 0 skipped ==========
========== Build completed at 9:26 PM and took 24:34.245 minutes ==========
coool thanks for this vid! you make my day!!!!
bro i am having tensorflow in other environment but this has installed on base how to activate this to my tensorflow environment please guide me
You will need to build for virtual environment again. You need to set all the paths to python3 directories in Cmake to point the virtual environment (which are by default set to base environment).
Hey I have a problem with the cmake build, after activating the BUILD_opencv_world, my visual studio can not find the lib/Release/opencv_world480.lib file.. I'm using cuda 12, cudnn 8.9, opencv 4.8 and opencv contrib 4.8
I've tried using the 4.7 version of opencv and contrib, it still not build the opencv_world file in build/lib/Release directory
followed exactly but got 39 success and 153 failed in vs 2017 please help
It does not work on VS 2017. Also, try this updated tutorial for OpenCV 4.5.1. ua-cam.com/video/YsmhKar8oOc/v-deo.html
mine took 5.1 sec to generate 🤔🤔
i am getting this error please help
Could NOT find CUDNN (missing: CUDNN_LIBRARY CUDNN_INCLUDE_DIR) (Required is at least version "7.5")
Hi. You need to install right version of CUDA and cuDNN.
ModuleNotFoundError: No module named 'cv2'
The build and installation showed no errors :/
Try this updated method: ua-cam.com/video/YsmhKar8oOc/v-deo.html
@@TheCodingBug Thanks, it worked!
When i try and build in VS code 2019, the build will fail and say that visual studio 2019 is not support. Did you have this issue?
I didn't get this error. You can check the updated tutorial for OpenCV build here ua-cam.com/video/YsmhKar8oOc/v-deo.html
thank you so much. i did it!
I could compile OpenCV in VS 2017 without warnings or errorsconfigured for CUDA 10.0, cuDNN 7.6.5(Nvidia GTX 1070), on Python 3.8, and added an ENTRY BUILD_opencv_python3 and checked it before compiling in CMake without any errors.
Tried 2 time to install same CUDA and cuDNN as yours but crashes
In ALL BUILD compilation I get Build: 188 succeeded, but with INSTALL I only get 1 succeed and anaconda prompt does not recognize opencv. Watched 2 videos about compiling custom OpenCV and both show 2 succeed. What the heck is wrong?
I am not sure. Perhaps an updated tutorial is needed that addresses all the issues reported in the comments.
me too, only 1 succeed!
hi sir, i have problem to install. where i must install location for python??
this is the worst thing i have installed in years. the module can't be found tryed all the answer here and above, i tried remove all my python version, then remove all my system variables, the build have no errors, when i compile in the visual studio. this is imposible and sad
Hello, I successfully installed and builded everything. I can get same output when write cv2.cuda.getCudaEnabledDeviceCount() on command panel. But how can I use this command a .py file. When I try to use, I am getting error.
sorunu çözebildiniz mi
I run ALL_BUILD and it shows this error "LNK1104: cannot open file 'python38_d.lib'"
Hi. You can try alternative method. ua-cam.com/video/YsmhKar8oOc/v-deo.html
@@TheCodingBug Success run, thx.
Hi sir when building I get linking error "LNK1181 can't find input file \lib\Release\opencv_core440.lib". This error also happens but with different .lib files such as opencv_flann440.lib, opencv_imageproc440.lib, etc. I don't get any errors during the Configuring or Generating process. How do I fix this?
Where are the links?
Everything good till 5:50 but after I point it to modules dir it and click configure it does not give more options any possible fix?
just remove the text from search tab it fixes it
I am glade its fixed.
when I try to import cv2 i get the error:
ImportError: OpenCV loader: missing configuration file: ['config-3.8.py', 'config-3.py']. Check OpenCV installation.
Any idea how to fix this?
Whether we need to add python development workload in visual studio 2019 during the installation process?
No that is not required. Only check the options which I have checked.
@@TheCodingBug tnks for d reply
how I detect face by using opencv+cuda? need your help
I will be making a video tutorial about that. Stay tuned!
hi, it worked for me thank you, but can i know what happened if i delete the " build " folder after everything is done? I still can use cv2 module or not?
I am glad it helped. You can delete everything in the build folder except "lib" directory.
ii have error on undefined refrefernce function on opencv cuda build can u give any idea to solve thsi
For OpenCV 4.5 which cuda and cudnn versions do I need? and How can I activate the opencv gpu for python too? thank you.
I have separate video for opencv 4.5.1 ua-cam.com/video/YsmhKar8oOc/v-deo.html
It also covers the installation for virtual environment of Python.
My laptop have 2 graphic card ( intel, nvidia gpu) , i setup opencv like your video but when i run a project , it's auto run with intel gpu, how can i run with nvidia gpu?
all went well with no errors... but when i import cv2 in conda it does not find the opencv module... is there a wat to link the build installed in another driveto anaconda base environment? somehow the opencv is not linking with the anaconda library...
Where you able to fix the issue? I am facing the same
If everything builds fine without any error and you still get "Module Not Found" error, You need to update numpy to latest version and then clear cache in Cmake by going to file >> delete cache. Then build everything again and it will work.
Excelent! :D
Great video!!! But I am facing a problem here: my build folder is missing the .sln file along with many others. I don't understand what I did wrong, could you please help me with this?
You can try updated video with a different method. ua-cam.com/video/YsmhKar8oOc/v-deo.html
I have DLL module problem now.
Traceback (most recent call last):
File "", line 1, in
File "C:\Python38\lib\site-packages\cv2\__init__.py", line 96, in
bootstrap()
File "C:\Python38\lib\site-packages\cv2\__init__.py", line 86, in bootstrap
import cv2
ImportError: DLL load failed while importing cv2: The specified module could not be found.
It seems one or more modules of opencv didn't compile right. Are you sure there were no errors during build?
Its okay, everything has solved
I am glad it is resolved. For future readers, you can share the solution. Maybe it'll help someone.
how did you solve the problem?
Iftekher Hossain im not sure how and why. But what I did was: uninstall my previous python (3.7.5) and install to (3.7.9). You also need to check the path of its download. Dont store it at AppData/local. Instead create new folder “Python37” at C:// or anything. Then after you installed your python, then you can proceed with this tutorial
Thanks. the explanations were great... but in the last step I still got 131 errors :( FML
Try this updated method.
ua-cam.com/video/YsmhKar8oOc/v-deo.html
can i delete the opencv file after built?
I have covered the cleaning process in my 2021 updated video: ua-cam.com/video/YsmhKar8oOc/v-deo.html
@@TheCodingBug wah I didn't expect such fast reply from you. Thank you sir, I will check it out
Por favor, muestre todas las banderas / selecciones y caminos indicadas en el CMake de su instalación. Gracias.
What is your cudnn version?
It's shown in the video.
You can try the updated tutorial for it ua-cam.com/video/YsmhKar8oOc/v-deo.html
I think, python path issues should be addressed in the video which can be quite difficult for beginners.
I agree. But it's straight forward if we install Python with Anaconda.
@@TheCodingBug I think, confusion is because Anaconda is not mentioned in the videos title or in description or even the first screen frame.
After people complained about Python paths, I mentioned in description that I am using Anaconda with Python 3.8.
@@TheCodingBug I missed to check that part, yes setting path for python is not easy. I finally could able to compile all without error and with python after few attempt. I gave thumps up to this video as I also learned from this video, it is a short and crisp video to setup the opencv without fuss.
I am glad I could help.
Big thanks!
@TheCodingBug Hi. thanks for the video .
when I follow the steps it got work on conda base env can I copy it to another env or do i need to rebuild it from scratch with new env python path ?
What if i only have amd GPU, is there any other way?
No AMD GPU do not support CUDA.
I have a problem after installing the OpenCV.sln and anaconda cmd write "import cv2" where it says
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
Please help me!
Dude, add this to your Cmake configuration and try again "BUILD_opencv_python3" and set its value to True (Checkbox), I spend a whole day trying to make this work. Good luck !
@@dedenapraia I have same problem, I added that new entry in CMake and still getting same result
I have the same problem, please help to tell me a solution
In Cmake when you hit Configure, after the process is done, there is an Output right ? This output should have something like this (Depending on your paths to python or if you are using Anaconda) :
Python 3:
Interpreter: C:/ProgramData/Anaconda3/python.exe (ver 3.8.5)
Libraries: C:/ProgramData/Anaconda3/libs/python38.lib (ver 3.8.5)
numpy: C:/ProgramData/Anaconda3/Lib/site-packages/numpy/core/include (ver )
install path: C:/ProgramData/Anaconda3/Lib/site-packages/cv2/python-3.8
Python (for build): C:/ProgramData/Anaconda3/python.exe
@@dedenapraia maybe my path to python and anaconda are wrong. Currently it is NOT in ProgramData, but
C:\Users\caomi\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Python 3.8
After complete all step. How to use that build in pycharm from virtual environment ?
For a virtual environment, you have to set python3 paths to the virtual environment (all of them). Then compile it again.
@@TheCodingBug thanks. can you give me some link or demo where to set path ?
@@helloankur2009 In CMake GUI, search for PYTHON3_
and you will see a bunch of paths, which are set to base Anaconda3 directories. You need to set all of them to virtual environment directories. For example:
PYTHON3_EXECUTABLE is set to C:\USsers\Anaconda3\python.exe
It will become C:\Users\Anaconda3\env\myVirtualEnv\python.exe
and same goes for all other PYTHON3_ paths.
If it does not work, I will be posting an updated tutorial next week with all the configurations in a script. Which will be easier to setup.
@@TheCodingBug Hi I am able to use in pycharm by the base interpreter from c:\User\\...\\..\\. Thanks for your help and support.. can you share some code on how to use cv2 with Cuda to open image and video?
My graphics card 940mx is not there on wikipedia page of cuda so what should I write at cuda arch bin in cmake????
This card is not supported.
@@TheCodingBug Actually I checked everything on the web and it shows it supports cuda with compute capacity of 5.0 but after I did all the things it showed around 200 errors in Visual Studio will building all build and most of the errors were with linker showing unable to open file and sometimes unable to detect file. This was through LNK1181. Any suggestions???
@@thatHandsomeGeek you can try updated method for building opencv (2021) that I've posted.
I am unable to verify for this GPU as I do not have access to yhis GPU.
everything was successfully build and installed but it's still not using cuda.
Did you manage to solve the problem ? Opencv was installed for me, I can import the module in python, but it is still using CPU.
I have some problems after installing the OpenCV.sln, where it says
Traceback (most recent call last):
File "", line 1, in
ModuleNotFoundError: No module named 'cv2'
Are you installing it in virtual environment?
@@TheCodingBug no, not in the virtual environment
In that case, make sure that CMake was able to successfully detect paths for python3.
TheCodingBug how can i do that??
TheCodingBug my python version for anaconda is 3.8 while the basic one is not 3.7
I get "Error in configuration process, project files may be infalid" from CMake when i click Configure for the second time, after setting extra module path to opencv_contrib...
I've tried both OpenCV 4.4.0 and 4.5.0 and i keep getting this error.
I got the same error. Have you solved it?
install cudnn correctly, that fixed it for me
I am using Windows 10, and my cmake-gui crashes every time when I select the module directory for OPENCV_EXTRA_mODULES_PATH. How to solve this issue?
Don't click on the select path button, instead entering the path manually in the value field worked for me.
@@miroslavgechev4852 Using your method, my cmake has stopped crashing, but now I am getting this error:
Configuring incomplete, errors occurred!
See also "D:/yolo/build/CMakeFiles/CMakeOutput.log".
See also "D:/yolo/build/CMakeFiles/CMakeError.log".
Hello i dont have to nvidia geforce gtx 1016. What can i do?? Help please
Do you have any other model of nvidia GPU?
@@TheCodingBug i have Jetson nano and Jetson xavier
@@ozlematz2528 I am not sure about Jetson nano.
@@TheCodingBug Ok .Thank :))
Do you have any idea why this error occurs? Thanks in advance.
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.7.py', 'config-3.py']. Check OpenCV installation.
Your site-packages/cv2 does not have config-3.7.py file. Either you have multiple Python versions or there is the wrong file at that location (maybe config-3.6.py)
would you please suggest me how can I resolve this problem?
@@mdiftekherhossain6152 If you have native python, only install one version (Probably Python 3.8). Uninstall all other versions. Alternatively, you can install Anaconda with Python 3.8 and reinstall OpenCV. Anaconda is always a convenient way to install Python.
yes. I have native python and initially, cmake path was that. I have changed all the paths to the anaconda path. will uninstalling native python help to get rid of the error? Thanks for your suggestion
@@mdiftekherhossain6152 No. You will have to build OpenCV for one environment (either native or Anaconda). You will have to build it again and carefully check which version CMake picks up in PYTHON3_EXECUTABLE etc.
If buid "BUILD_ALL", this is also install opencv with GPU for anaconda, python ?
Yes it would. Infact, I am using Anaconda python in this tutorial.
Hey, it's not working in conda virtual env, can u help pls ?
Hi. The installation of OpenCV from source is equivalent to installing using pip in a way that for every virtual environment (VE), you activate the VE, and then do pip install for that particular environment. Similarly, to build a package from source and installing it to VE requires that we set the right paths for CMake. For system wide installation, notice the options in CMAKE starting with PYTHON3. They all are pointed to the system wide directories. You need to point them to corresponding VE directories. Following is an example:
PYTHON3_EXECUTABLE=~/.envs/myenv/bin/python.exe
PYTHON3_INCLUDE_DIR=~/.envs/myenv/bin/python/include
Hope that it will solve the problem. If not, comment down below and I will make a tutorial on how to build it for VE.
@@TheCodingBug thanks, it solved the problem but I had to rebuild
I am glad issue is resolved.
@@TheCodingBug can i apply the same method for env created via virtualenv or having a conda evn is compulsory?
You can do this for any environment. Just make sure that CMake picks up paths for Python3 correctly (all paths including site_packages, python.exe etc). If it does not, You will have to manually define them. Otherwise, it will return "Module not found" error when you will import it to Python.
Thanks for your turtorial. I have a problem. How to make Pycharm IDE regconize this rebuild opencv module?
Its been long since I abandoned PyCharm so I am not sure how this can be done because as far as I can remember, PyCharm had its own repository to install from (somewhere in the project setting).
Add the path to the cv2 directory to your PYTHONPATH system variable. That should help.
@@g4laxy551 thanks mate
Thanks for the turotial. Ive followed the steps and everything went successfully (no errors during the build process). However, when i´ve checked the opencv through import cv2 in the base environment in anaconda, it returned the error ( ModuleNotFoundError: No module named 'cv2'). So what could the problem be?
You need to update your numpy installation before making OpenCV. Use command
pip install --upgrade numpy
@@TheCodingBug thanks for the reply. however, it didnt work. Besides I dont understand what does upgrading numpy have to do with cv2 ?
@@khaledjbaili8654 You need to upgrade numpy as then build again. During CMake build, the message is printed at the end showing for which python version the build would be installed. If you do not see this message, you will not get python bindings.
Numpy is used during creation of python bindings. If its outdated version, it will not going to work.
@@TheCodingBug okay i will rebuild again. do i have to rebuild starting from the begining (from cmake) or from visual studio?. Just want be sure that every thing is done as it should be. Ive placed the build file in Disk E:\OPENCV_CUDA, while the default path of the kernel (base) of anaconda as i open it, is (base) C:\Users\engjb>. should the build be in the same path or it doesnt matter
@@khaledjbaili8654 Rebuild from cmake. First go to File and clear Cache. Then rebuild all configurations from cmake. Then form visual studio.
Hi, you are my last hope, I am using OpenCV 4.4.0 with numpy 1.20.0, trying to bind tensorflow version 2.4.0 and it gives me an error (NotImplementedError: Cannot convert a symbolic Tensor (random_zoom/zoom_matrix/strided_slice:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported), but it also works fine on numpy version 1.19.2, but from this version CV2 crashes with an error (RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd). Please tell me what could be the problem?
python 3.8.5
You should try the latest opencv with TF2.4 or try to build TF2.3.1 instead.
@@TheCodingBug thanks, I'll try
@@TheCodingBug I apologize for the importunity, but please tell me, I started to give out a similar error "print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
AttributeError: module 'tensorflow' has no attribute 'config'"
If you are installing cuda for GPU or following this video ( ua-cam.com/video/FE2GBeKuqpc/v-deo.html ) for the yolov4 don't forgot to select BUILD_opencv_world during the CMAKE process otherwise you will be in trouble during the Darknet installation.
If you find this comment helpful then please pin it. or if I am wrong please let me know I will remove this comment. So that it will not create any confusion.
Thank You.
Absolutely right.
I have cuda 10.0 installed in my anacodna environment, will it affect my anacodna environment if I go back to the website and download cuda 10.1.2?
You can install multiple versions of CUDA. However, only one will be added to PATH variable of the the system.
@@TheCodingBug python 3.8's tensorflow-gpu cannot connect to a GPU by CUDA, which means I can only use OPENCV to connect to a GPU?
@@saber3747 TensorFlow needs compatible version of CUDA qnd cuDNN. you can inatall TensorFlow GPU in a separate environment along with supported CUDA amd cuDNN. Here's how to do it. ua-cam.com/video/toJe8ZbFhEc/v-deo.html
@@TheCodingBug good, thank you.
Thank you for your video. I have followed every steps in the video but still I get no module found when trying to import cv2. Do you know how I can fix it? Please help
same issue
@@luiscao7241 I managed to fix that by setting the directory for python libraries. I found this solution among the comments in the video. Here is the link screenshot of the comment:
www.dropbox.com/s/96e3rg61tkorg2n/Photo%202021-01-10%2C%2012%2036%2055%20AM.png?dl=0
You only need to set the python3 lines when doing configuration using cmake
@@siminesfshani8668 you are right. Thank you
If everything builds fine without any error and you still get "Module Not Found" error, You need to update numpy to latest version and then clear cache in Cmake by going to file >> delete cache. Then build everything again and it will work.
Is Anaconda necessary? Can’t I use only python?
You can use native Python as well. Just make sure CMake picks up the paths correctly (and it will if Python is added to PATH variable).
Why not just press Open Project at 6:50?
Sometimes it does not open with administrator rights so the build process can throw an error. So using the command prompt as Administrator ensures that the project file will be opened as Administrator.
That’s right. That’s why I have my VS set up to open as admin.
Hi man, thanks a lot for the tutorial, really appreciated, I am new to building things with CMake so I don't have much experience, but when I click on Configure for the second time it gives me errors, that I don't know how to solve...
If you want I can send you the error.log file
Hi. You can create an "issue" on the GitHub link I shared in the description and paste the error there. I will look into this.
@@TheCodingBug I solved, didn't install cuDNN correctly...thanks anyways!
No worries. I am glad that the problem is resolved.
@@TheCodingBug Sorry if I bother you too much, but now I have another error. After compiling the ALL_Build thing and then INSTALL, and all went perfectly, but if I try to import the library on Python it won't let me...
No problem. I hope you are using Anaconda because that makes the whole process easier. But if you are using native python, make sure that CMake GUI picks up python 2/3 paths after you hit Configure for the first time. If it is not picking python paths, you will have to add it manually.
If I have understood the problem rightly, this will solve the problem. If you can share the error, may be I will be in a better position to help.
Hi Codebug. You are excellent. Your videos are very easy to understand. I could successfully install the opencv-gpu in my laptop (it has GTX1070)
I have a question. After compiling opencv gpu version, my anaconda or pycharm is unable to detect the compiled version.
example: my build path is D:\opencv\build .
when I use windows cmd CLI, and python the following command prints 1.
import cv2
count = cv2.cuda.getCudaEnabledDeviceCount()
print(count)
but If try the same comand inside anoconda CLI or pycharm the print brings 0.
Pls explain sir, after the successful compiling of opencv-gpu version, how to integrate (import) in anoconda or pycharm?
thank you. my email id is dompower at gmail.com
It looks like you have multiple versions of Python installed (Anaconda and Native). During CMake build process, CMake automatically detects the python3 paths (including python.exe, site_packages etc). OpenCV will be installed for these python versions only. If it is picking up Anaconda paths, it will work with Anaconda Prompt. But if it is picking up Native python3 paths, it will work with windows CMD.
Regarding PyCharm, I have never used it with custom build OpenCV. As far as I can recall, PyCharm has its own repository, which has pre-built OpenCV. But I am not sure how to integrate custom build to it.
@@TheCodingBug thanks for your solution. Would you pls guide me how can I uninstall the native python version? I strongly believe it is installed part of pycharm installation...
@@TheCodingBug Thank you very much sir. You are right. There are two versions of python. OpenCV-GPU ( i mean built from source as per your guidelines) was built for native python version. That's good. Bcs when I reinstalled pyCharm, it recognized native python and opencv-gpu (built from source) and everything is ok now. thanks you.
Wasted hours on this. Vc throws about 171 errors. Python is fucking garbage on windows. My god.
I am sorry to hear that. But if you use exactly same versions of everything as mine, you will be able to successfully build it. There are newer versions of Python, OpenCV, and CUDA since I made this tutorial and those might not work well with same configurations.
@@TheCodingBug Thats what i did though, figured that was an issue and reverted back to the same versions. Vc even throws errors saying vc 2017 is needed for no reason.
@@TheCodingBug VC 2019 is the issue, for some reason it seems to be very unstable. Im going to run VC 2017 from now on. Its workign perfectly even with regular python!
@@techbuildspcs Thats new for me!! I hope someone else having same issue finds this information useful.
@@TheCodingBug yep Microsoft even locked vs 2017 behind logins so I'm keeping my copy held tight. I hope so too. Might make an updated tutorial showing how I did it with regular python for the path issues.
Hi.. I got error when building ALL_BUILD in visual studio. The error message was as follows
error LNK2019: unresolved external symbol "public: __cdecl cv::cudacodec::EncoderParams::EncoderParams(void)" (??0EncoderParams@cudacodec@cv@@QEAA@XZ) referenced in function "struct _object * __cdecl pyopencv_cv_cudacodec_createVideoWriter(struct _object *,struct _object *,struct _object *)" (?pyopencv_cv_cudacodec_createVideoWriter@@YAPEAU_object@@PEAU1@00@Z)
can anyone help me pls? Thanks in advance
@TheCodingBug
I'm currently using nvidia rtx 3060..
installed cuda 11.7
visual studio 2022
opencv 4.6.0
Try with VS 2019