<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; master</li>
<li>Operating System / Platform =&gt; Windows 64 Bit</li>
<li>Compiler =&gt; Visual Studio 15 2017 Win64</li>
</ul>
<h5 dir="auto">Detailed description</h5>

<p dir="auto">When doing Configure on master branch in Windows with CV_DISABLE_OPTIMIZATION checked, it causes the CMake configuration process to fail on errors like these:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="CMake Error at cmake/OpenCVUtils.cmake:331 (target_include_directories):
  Cannot specify include directories for target &quot;opencv_test_core_SSE4_1&quot;
  which is not built by this project.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:675 (ocv_target_include_directories)
  cmake/OpenCVModule.cmake:1239 (ocv_target_include_modules)
  modules/core/CMakeLists.txt:97 (ocv_add_accuracy_tests)

CMake Error at cmake/OpenCVUtils.cmake:331 (target_include_directories):
  Cannot specify include directories for target &quot;opencv_test_core_SSE4_2&quot;
  which is not built by this project.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:675 (ocv_target_include_directories)
  cmake/OpenCVModule.cmake:1239 (ocv_target_include_modules)
  modules/core/CMakeLists.txt:97 (ocv_add_accuracy_tests)

....."><pre class="notranslate"><code class="notranslate">CMake Error at cmake/OpenCVUtils.cmake:331 (target_include_directories):
  Cannot specify include directories for target "opencv_test_core_SSE4_1"
  which is not built by this project.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:675 (ocv_target_include_directories)
  cmake/OpenCVModule.cmake:1239 (ocv_target_include_modules)
  modules/core/CMakeLists.txt:97 (ocv_add_accuracy_tests)

CMake Error at cmake/OpenCVUtils.cmake:331 (target_include_directories):
  Cannot specify include directories for target "opencv_test_core_SSE4_2"
  which is not built by this project.
Call Stack (most recent call first):
  cmake/OpenCVModule.cmake:675 (ocv_target_include_directories)
  cmake/OpenCVModule.cmake:1239 (ocv_target_include_modules)
  modules/core/CMakeLists.txt:97 (ocv_add_accuracy_tests)

.....
</code></pre></div>
<p dir="auto">and many more of the same error for the various components that are selected for building.</p>

<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">In Windows 10 x64, CMake (v3.7.2), clone the repo, checkout <code class="notranslate">master</code> branch, and run CMake Configure with <em>Visual Studio 15 2017 Win64</em> as the compiler.</p>
<h5 dir="auto">System information (version)</h5>

<ul dir="auto">
<li>OpenCV =&gt; 4.1.2</li>
<li>Operating System / Platform =&gt; Linux / Ubuntu 18.04</li>
<li>Compiler =&gt; <g-emoji class="g-emoji" alias="grey_question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2754.png">❔</g-emoji></li>
</ul>
<h5 dir="auto">Detailed description</h5>
<p dir="auto">When running the code below that call <code class="notranslate">solvePnPGeneric</code> from Python the program crashes because the C++ code expect a different type for <code class="notranslate">reprojectionError</code>  from the one passed by <code class="notranslate">solvePnPGeneric</code> by default. The argument is however <a href="https://docs.opencv.org/master/d9/d0c/group__calib3d.html#ga624af8a6641b9bdb487f63f694e8bb90" rel="nofollow">documented</a> as optional. Passing the argument with the correct type avoid the error.</p>
<p dir="auto">I suspect that the binding of the <code class="notranslate">solvePnPGeneric</code> function do not pass the correct argument type for <code class="notranslate">reprojectionError</code> by default.</p>
<p dir="auto">The error:</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;error.py&quot;, line 15, in &lt;module&gt;
    obj_points, img_points, cameraMatrix, distCoeffs #, reprojectionError=r
cv2.error: OpenCV(4.1.2) /io/opencv/modules/calib3d/src/solvepnp.cpp:1017: error: (-2:Unspecified error) in function 'int cv::solvePnPGeneric(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::OutputArrayOfArrays, cv::OutputArrayOfArrays, bool, cv::SolvePnPMethod, cv::InputArray, cv::InputArray, cv::OutputArray)'
&gt; Type of reprojectionError must be CV_32FC1 or CV_64FC1!:
&gt;     'type == CV_32FC1 || type == CV_64FC1'
&gt; where
&gt;     'reprojectionError.type()' is 0 (CV_8UC1)"><pre class="notranslate">Traceback (most recent call last):
  File <span class="pl-s"><span class="pl-pds">"</span>error.py<span class="pl-pds">"</span></span>, line 15, <span class="pl-k">in</span> <span class="pl-k">&lt;</span>module<span class="pl-k">&gt;</span>
    obj_points, img_points, cameraMatrix, distCoeffs <span class="pl-c"><span class="pl-c">#</span>, reprojectionError=r</span>
cv2.error: OpenCV(4.1.2) /io/opencv/modules/calib3d/src/solvepnp.cpp:1017: error: (-2:Unspecified error) <span class="pl-k">in</span> <span class="pl-k">function</span> <span class="pl-en">'int</span> cv::solvePnPGeneric(cv::InputArray, cv::InputArray, cv::InputArray, cv::InputArray, cv::OutputArrayOfArrays, cv::OutputArrayOfArrays, bool, cv::SolvePnPMethod, cv::InputArray, cv::InputArray, cv::OutputArray)<span class="pl-s"><span class="pl-pds">'</span></span>
<span class="pl-s">&gt; Type of reprojectionError must be CV_32FC1 or CV_64FC1!:</span>
<span class="pl-s">&gt;     <span class="pl-pds">'</span></span>type == CV_32FC1 <span class="pl-k">||</span> <span class="pl-c1">type</span> == CV_64FC1<span class="pl-s"><span class="pl-pds">'</span></span>
<span class="pl-s">&gt; where</span>
<span class="pl-s">&gt;     <span class="pl-pds">'</span></span>reprojectionError.type()<span class="pl-s"><span class="pl-pds">'</span> is 0 (CV_8UC1)</span></pre></div>
<p dir="auto">This might be closely linked to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="531627180" data-permission-text="Title is private" data-url="https://github.com/opencv/opencv/issues/16040" data-hovercard-type="issue" data-hovercard-url="/opencv/opencv/issues/16040/hovercard" href="https://github.com/opencv/opencv/issues/16040">#16040</a> which is about Java binding of solvePnPGeneric</p>
<h5 dir="auto">Steps to reproduce</h5>
<p dir="auto">Run this code (OpenCV 4.1.2 / Python 3.6.8)</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import cv2

obj_points = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 0], [1, 0, 0]], dtype=np.float32)
img_points = np.array(
    [[700, 400], [700, 600], [900, 600], [900, 400]], dtype=np.float32
)

cameraMatrix = np.array(
    [[712.0634, 0, 800], [0, 712.540, 500], [0, 0, 1]], dtype=np.float32
)
distCoeffs = np.array([[0, 0, 0, 0]], dtype=np.float32)
#r = np.array([], dtype=np.float32)
x, r, t, e = cv2.solvePnPGeneric(
    obj_points, img_points, cameraMatrix, distCoeffs #, reprojectionError=r
)
print(e)
print(t)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">cv2</span>

<span class="pl-s1">obj_points</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">1</span>, <span class="pl-c1">0</span>], [<span class="pl-c1">1</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>]], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
<span class="pl-s1">img_points</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(
    [[<span class="pl-c1">700</span>, <span class="pl-c1">400</span>], [<span class="pl-c1">700</span>, <span class="pl-c1">600</span>], [<span class="pl-c1">900</span>, <span class="pl-c1">600</span>], [<span class="pl-c1">900</span>, <span class="pl-c1">400</span>]], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>
)

<span class="pl-s1">cameraMatrix</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>(
    [[<span class="pl-c1">712.0634</span>, <span class="pl-c1">0</span>, <span class="pl-c1">800</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">712.540</span>, <span class="pl-c1">500</span>], [<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">1</span>]], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>
)
<span class="pl-s1">distCoeffs</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([[<span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>, <span class="pl-c1">0</span>]], <span class="pl-s1">dtype</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">float32</span>)
<span class="pl-c">#r = np.array([], dtype=np.float32)</span>
<span class="pl-s1">x</span>, <span class="pl-s1">r</span>, <span class="pl-s1">t</span>, <span class="pl-s1">e</span> <span class="pl-c1">=</span> <span class="pl-s1">cv2</span>.<span class="pl-en">solvePnPGeneric</span>(
    <span class="pl-s1">obj_points</span>, <span class="pl-s1">img_points</span>, <span class="pl-s1">cameraMatrix</span>, <span class="pl-s1">distCoeffs</span> <span class="pl-c">#, reprojectionError=r</span>
)
<span class="pl-en">print</span>(<span class="pl-s1">e</span>)
<span class="pl-en">print</span>(<span class="pl-s1">t</span>)</pre></div>
<p dir="auto">The error can be bypassed by uncommenting the <code class="notranslate">#r = np.array([], dtype=np.float32)</code> lines.</p>
<p dir="auto">Thanks for the amazing work and happy to help or provide more information!</p>