How to fix unhandled OpenCVException from calling Cv2.SolvePnP()?
<p>I try to call <a href="http://shimat.github.io/opencvsharp/html/a8c1d94a-c3b6-f439-013a-3cc29ed1243c.htm" rel="nofollow"><code>Cv2.SolvePnP()</code></a> of <a href="https://github.com/shimat/opencvsharp" rel="nofollow">opencvsharp</a> like so:</p>

<pre><code>using System.Collections.Generic;

using OpenCvSharp;

namespace Test
{
    public class SolvePnPTest
    {
        public static void Main(string[] args)
        {
            var objectPoints = new List&lt;Point3f&gt;();
            objectPoints.Add(new Point3f(1, 2, 3));
            objectPoints.Add(new Point3f(1, 2, 3));
            objectPoints.Add(new Point3f(1, 2, 3));
            objectPoints.Add(new Point3f(1, 2, 3));

            var imagePoints = new List&lt;Point2f&gt;();
            imagePoints.Add(new Point2f(1, 2));
            imagePoints.Add(new Point2f(1, 2));
            imagePoints.Add(new Point2f(1, 2));
            imagePoints.Add(new Point2f(1, 2));

            var rvec = new double[3];
            var tvec = new double[3];

            var cameraMatrix = new double[,] { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
            var distortionCoefficients = new double[] { 1, 2, 3, 4, 5 };

            Cv2.SolvePnP(
                objectPoints,
                imagePoints,
                cameraMatrix,
                distortionCoefficients,
                out rvec,
                out tvec);
        }
    }
}
</code></pre>

<p>The call to <code>Cv2.SolvePnP</code> fails with an unhandled OpenCVException:</p>

<blockquote>
<pre><code>src.size == dst.size &amp;&amp; src.channels() == dst.channels()
</code></pre>
</blockquote>

<p><strong>What is <code>src</code>? What is <code>dst</code>?</strong></p>

<p>The details of the error including the stacktrace look like that:</p>

<pre><code>HResult=-2146232832
Message=src.size == dst.size &amp;&amp; src.channels() == dst.channels()
Source=OpenCvSharp
ErrMsg=src.size == dst.size &amp;&amp; src.channels() == dst.channels()
FileName=..\..\..\modules\core\src\convert.cpp
FuncName=cvConvertScale
Line=5475
StackTrace:
     at OpenCvSharp.NativeMethods.&lt;&gt;c.&lt;.cctor&gt;b__1332_0(ErrorCode status, String funcName, String errMsg, String fileName, Int32 line, IntPtr userdata)
     at OpenCvSharp.NativeMethods.calib3d_solvePnP_vector(Point3f[] objectPoints, Int32 objectPointsLength, Point2f[] imagePoints, Int32 imagePointsLength, Double[,] cameraMatrix, Double[] distCoeffs, Int32 distCoeffsLength, Double[] rvec, Double[] tvec, Int32 useExtrinsicGuess, Int32 flags)
     at OpenCvSharp.Cv2.SolvePnP(IEnumerable`1 objectPoints, IEnumerable`1 imagePoints, Double[,] cameraMatrix, IEnumerable`1 distCoeffs, Double[]&amp; rvec, Double[]&amp; tvec, Boolean useExtrinsicGuess, SolvePnPFlags flags)
     at Test.SolvePnPTest.Main(String[] args) in &lt;file path&gt;.
InnerException: 
</code></pre>

<p><strong>What's the problem with my code?</strong></p>

<p>The assertion in convert.cpp is in this opencv function:</p>

<pre><code>CV_IMPL void
cvConvertScale( const void* srcarr, void* dstarr,
                double scale, double shift )
{
    cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);

    CV_Assert( src.size == dst.size &amp;&amp; src.channels() == dst.channels() );
    src.convertTo(dst, dst.type(), scale, shift);
}
</code></pre>