Ask Your Question

How to reproduce OpenCV official build locally

asked 2018-01-13 03:46:11 -0500

Pzixel gravatar image

updated 2018-01-15 06:48:43 -0500

I used to use OpenCV build vc14_vc15from the official github page: . But I have realised that it is compiled without CUDA support which I need, e.g. see build/include/opencv2 screenshot

enter image description here

When I build it myself (e.g. using this instruction) I don't have any include folder at all. But I need it because I need cudaobjdetect.hpp and several other guys (such as features2d.hpp) being located here.

Why my local build doesn't look like those in opencv-3.4.0-vc14_vc15.7z and how can I achieve same result, but with several extra CMake switches (like CUDA in this example)? I mean I want OpenCV to be built with CUDA support and cudaobject.hpp located in build/include/opencv2 folder.

Ok, I configured CMake with following options:


But in this case OpenCV just doesn't get built, see log part with error:

For more context: here is full log

CUDA is installed with following flags:

Start-Process -FilePath "cuda_9.1.exe" -ArgumentList "-s nvcc_9.1 cublas_9.1 cublas_dev_9.1 cufft_9.1 cufft_dev_9.1 npp_9.1 npp_dev_9.1" -Wait
edit retag flag offensive close merge delete


see this post I have got same error... CUDA 9.1 and msvc 2017 is it compatibel?

LBerger gravatar imageLBerger ( 2018-01-15 06:08:39 -0500 )edit

Ye, just change the header value. Here is my script for it: . It's ok to change it because it how NVidia itself is doing it:

Pzixel gravatar imagePzixel ( 2018-01-15 06:23:52 -0500 )edit

Hmm, it seems to be a known incompatibility, see post at `12/29/2017 08:38 PM on last url. Beign said, that's funny enough that they have broken compatibility with minor update (15.3 -> 15.4). Going to search some workarounds...

Pzixel gravatar imagePzixel ( 2018-01-15 06:59:44 -0500 )edit

Ok, I managed to configure AppVeyor to use MSVC 1911 which is working fine with CUDA 9.1. HOwever, build is failing because of timeout. Is there any way to speed it up? Build log:

Pzixel gravatar imagePzixel ( 2018-01-15 09:37:46 -0500 )edit

Just for info, in windows "to reproduce OpenCV official build locally" and get the same directory structure you need to build the INSTALL project in Visual Studio and look inside the install directory.

cudawarped gravatar imagecudawarped ( 2018-02-14 02:11:48 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-01-13 07:14:08 -0500

LBerger gravatar image

updated 2018-01-13 07:16:22 -0500

you will need git and cmake. you can follow this tutorial

You have to set -DWITH_CUDA:BOOL=ON instead of OFF

If you don't want tou use this scriptyou can use cmake-gui

edit flag offensive delete link more


@LBerger ty, i'l try it asap

Pzixel gravatar imagePzixel ( 2018-01-13 08:13:24 -0500 )edit

I have tried it. It reproduces an official build, horray! :) Now I'm trying to use CUDA switch to generate it... Don't know how much time it takes.. The last time I tried it took 6 hours or something. I heard that you can specify architecture for CUDA to make reduce this time, but i didn't find any good documentation which switshes what values must have to make it happen.

Pzixel gravatar imagePzixel ( 2018-01-13 09:19:05 -0500 )edit

Yes you should use only one architecture to reduce compilation time (may be one hour with one architecture) May be this blog can help you

LBerger gravatar imageLBerger ( 2018-01-13 09:34:55 -0500 )edit

For CUDA build time, see also.

Eduardo gravatar imageEduardo ( 2018-01-13 14:04:46 -0500 )edit

@LBerger I updated my question, see it, please. I followed this tutorial, however, I can't build the project.

Pzixel gravatar imagePzixel ( 2018-01-15 04:48:26 -0500 )edit

I think I have to write a separate question, because in theory this one is working. However, on practice build never finishes.

Pzixel gravatar imagePzixel ( 2018-01-15 12:06:39 -0500 )edit

At line 1814 i have got exactly same error with :

1>--     CMake generator:             Visual Studio 15 2017 Win64
1>--     CMake build tool:            C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/MSBuild.exe
1>--     MSVC:                        1912

and error is

32>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\type_traits(504): error : expression must have a constant value
32>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14.12.25827\include\type_traits(505): error : expression must have a constant value
LBerger gravatar imageLBerger ( 2018-01-15 13:14:48 -0500 )edit

@LBerger it's because you are using latest VS. If you use VS2017Update1 then it works as expected. MS has broken something with latest update.

Pzixel gravatar imagePzixel ( 2018-01-15 13:21:19 -0500 )edit


94> --     CMake generator:             Visual Studio 14 2015 Win64
94>  --     CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
94>  --     MSVC:                        1900
94>  --       AVX2 (9 files):


94>  --   NVIDIA CUDA:                   YES (ver 9.1, CUFFT CUBLAS NVCUVID)
94>  --     NVIDIA GPU arch:             50
94>  --     NVIDIA PTX archs:

It's OK after 34 minutes i7-5820 ssd disk only opencv and no opencv_contrib

LBerger gravatar imageLBerger ( 2018-01-15 14:20:24 -0500 )edit

@LBerger this is why I marked is as an answer. However, one hour is too much for CI which cancels the build if it takes so much time, so I'm searching for some way to actually build in less than hour. I think I may actually exclude opencv_contrib. I'l try it tomorrow, thank you.

Pzixel gravatar imagePzixel ( 2018-01-15 14:24:18 -0500 )edit

Question Tools

1 follower


Asked: 2018-01-13 03:46:11 -0500

Seen: 657 times

Last updated: Jan 15 '18