<p dir="auto">environment：<br>
OpenCV(4.3.0)<br>
language：python 3.6</p>
<p dir="auto">1.load the data from txt files,and then convert type from float to int32.<br>
a.txt<br>
4.020161 0.372046<br>
4.086024 0.548271<br>
4.112598 0.539363<br>
4.162546 0.522878<br>
4.252789 0.684608<br>
4.265030 0.681673<br>
4.572025 0.757398<br>
4.752093 0.743017<br>
4.958206 0.821787<br>
5.138208 0.807434<br>
5.298540 0.906368<br>
5.542401 0.878399<br>
5.798231 1.013368<br>
6.018507 1.075400<br>
6.113993 1.135273<br>
6.425354 1.265514<br>
6.545009 1.264395<br>
6.731231 1.205198<br>
6.901707 1.293404<br>
7.236600 1.293581<br>
7.264717 1.276446<br>
7.542284 1.294016<br>
7.849143 1.123871<br>
7.888957 0.818015</p>
<p dir="auto">b.txt<br>
0.558444 0.486612<br>
0.590397 0.479795<br>
0.637800 0.728716<br>
0.688097 0.927678<br>
0.911380 1.735989<br>
0.946417 1.752804<br>
1.247624 2.280543<br>
1.341965 2.214138<br>
1.552272 2.264075<br>
1.891904 2.235193<br>
1.943452 2.234293<br>
2.129528 2.216326<br>
2.370298 2.131144<br>
2.654617 2.204402<br>
2.769804 2.168312<br>
2.967309 2.118495<br>
3.258043 2.180414<br>
3.386168 2.172515<br>
3.582158 2.205668<br>
3.909915 2.182819<br>
3.998347 2.194714<br>
4.266880 2.160797<br>
4.344415 2.154483<br>
4.714916 2.141987<br>
4.798001 2.135526<br>
4.965595 1.871750<br>
5.199670 1.789360<br>
5.334784 1.386364<br>
5.574860 1.413061<br>
5.858532 1.056488<br>
exmaple:<br>
v0=(np.loadtxt("vehicleOutline/vehicleOutline0.txt",dtype=float,delimiter=' ') * 1000).astype(np.int32)<br>
2.then reshape to (length,1,2),excute the function computeDistance</p>
<p dir="auto">example:<br>
sd=cv2.createShapeContextDistanceExtractor()<br>
a0 = arr[i].reshape(arr[i].shape[0],1,2)<br>
a1 = arr[j].reshape(arr[j].shape[0],1,2)<br>
print(i,"match",j,"=",sd.computeDistance(a0,a1))</p>
<p dir="auto">3.result:<br>
some of txt files went success,but others went wrong.top the data went wrong,i dont know how to slove it.</p>
<p dir="auto">Transferred from <a href="http://code.opencv.org/issues/4490" rel="nofollow">http://code.opencv.org/issues/4490</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="|| Do Bi on 2015-07-21 13:15
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: None
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x86 / Windows"><pre class="notranslate"><code class="notranslate">|| Do Bi on 2015-07-21 13:15
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: None
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x86 / Windows
</code></pre></div>
<h2 dir="auto">createShapeContextDistanceExtractor()-&gt;computeDistance throws exception for certain shaped</h2>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Using these two images

1) http://i.imgur.com/WKaFDl4.png
2) http://i.imgur.com/5ayU6qb.png

I get the following error

@OpenCV Error: Assertion failed (dims &lt;= 2 &amp;&amp; data &amp;&amp; (unsigned)i0 &lt; (unsigned)size.p[0] &amp;&amp; (unsigned)(i1 * DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1] * channels()) &amp;&amp; ((((sizeof(size_t)&lt;&lt;28)|0x8442211) &gt;&gt; ((DataType&lt;_Tp&gt;::depth) &amp; ((1&lt;&lt; 3) - 1))*4) &amp; 15) == elemSize1()) in cv::Mat::at, file C:\builds\master_PackSlave-win32-vc12-static\opencv\modules\core\include\opencv2/core/mat.inl.hpp, line 894@

when running this code:

@#include &quot;opencv2/imgproc/imgproc.hpp&quot;
#include &quot;opencv2/highgui/highgui.hpp&quot;
#include &quot;opencv2/shape/shape.hpp&quot;
#include &lt;math.h&gt;
#include &lt;iostream&gt;

using namespace cv;
using namespace std;

vector&lt;Point&gt; GetContour(const Mat&amp; img)
{
    cv::threshold(img, img, 128, 255, cv::THRESH_BINARY);
    vector&lt;vector&lt;Point&gt;&gt; conts;
    cv::findContours(img, conts, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
    if (conts.empty())
        return vector&lt;Point&gt;();
    return conts.front();
}

int main()
{
    auto shape1 = GetContour(cv::imread(&quot;D:/shape1.png&quot;, cv::IMREAD_GRAYSCALE));
    auto shape2 = GetContour(cv::imread(&quot;D:/shape2.png&quot;, cv::IMREAD_GRAYSCALE));
    cout &lt;&lt; createShapeContextDistanceExtractor()-&gt;computeDistance(shape1, shape2) &lt;&lt; endl;
}@

in VC2013.

With other shapes or with createHausdorffDistanceExtractor instead of createShapeContextDistanceExtractor it does not crash."><pre class="notranslate"><code class="notranslate">Using these two images

1) http://i.imgur.com/WKaFDl4.png
2) http://i.imgur.com/5ayU6qb.png

I get the following error

@OpenCV Error: Assertion failed (dims &lt;= 2 &amp;&amp; data &amp;&amp; (unsigned)i0 &lt; (unsigned)size.p[0] &amp;&amp; (unsigned)(i1 * DataType&lt;_Tp&gt;::channels) &lt; (unsigned)(size.p[1] * channels()) &amp;&amp; ((((sizeof(size_t)&lt;&lt;28)|0x8442211) &gt;&gt; ((DataType&lt;_Tp&gt;::depth) &amp; ((1&lt;&lt; 3) - 1))*4) &amp; 15) == elemSize1()) in cv::Mat::at, file C:\builds\master_PackSlave-win32-vc12-static\opencv\modules\core\include\opencv2/core/mat.inl.hpp, line 894@

when running this code:

@#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/shape/shape.hpp"
#include &lt;math.h&gt;
#include &lt;iostream&gt;

using namespace cv;
using namespace std;

vector&lt;Point&gt; GetContour(const Mat&amp; img)
{
    cv::threshold(img, img, 128, 255, cv::THRESH_BINARY);
    vector&lt;vector&lt;Point&gt;&gt; conts;
    cv::findContours(img, conts, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
    if (conts.empty())
        return vector&lt;Point&gt;();
    return conts.front();
}

int main()
{
    auto shape1 = GetContour(cv::imread("D:/shape1.png", cv::IMREAD_GRAYSCALE));
    auto shape2 = GetContour(cv::imread("D:/shape2.png", cv::IMREAD_GRAYSCALE));
    cout &lt;&lt; createShapeContextDistanceExtractor()-&gt;computeDistance(shape1, shape2) &lt;&lt; endl;
}@

in VC2013.

With other shapes or with createHausdorffDistanceExtractor instead of createShapeContextDistanceExtractor it does not crash.
</code></pre></div>
<h2 dir="auto">History</h2>