Updated by Alexander Shishkov almost 13 years ago
The following code in "opencv / modules / contrib / src / chamfermatching.cpp" has an risk of leaving annotate_img uninitialized, causing Assertion Fail in following stages:
<pre><code class="cpp">
for (int y=0;y<h;++y) {
for (int x=0;x<w;++x) {
unsigned char edge_val = edges_img.at<uchar>(y,x);
if ( (edge_val!=0) ) {
q.push(std::make_pair(x,y));
dist_img.at<float>(y,x)= 0;
if (&annotate_img!=NULL) {
annotate_img.at<Vec2i>(y,x)[0]=x;
annotate_img.at<Vec2i>(y,x)[1]=y;
}
}
else {
dist_img.at<float>(y,x)=-1;
}
}
}
</code></pre>
The code should be like this:
<pre><code class="c">
for (int y=0;y<h;++y) {
for (int x=0;x<w;++x) {
// initialize
if (&annotate_img!=NULL) {
annotate_img.at<Vec2i>(y,x)[0]=x;
annotate_img.at<Vec2i>(y,x)[1]=y;
}
unsigned char edge_val = edges_img.at<uchar>(y,x);
if ( (edge_val!=0) ) {
q.push(make_pair(x,y));
dist_img.at<float>(y,x)= 0;
}
else {
dist_img.at<float>(y,x)=-1;
}
}
}
</code></pre>
I am testing on :
Windows XP
Visual Studio Professional 2008
OpenCV 2.3.1
<pre><code class="cpp">
for (int y=0;y<h;++y) {
for (int x=0;x<w;++x) {
unsigned char edge_val = edges_img.at<uchar>(y,x);
if ( (edge_val!=0) ) {
q.push(std::make_pair(x,y));
dist_img.at<float>(y,x)= 0;
if (&annotate_img!=NULL) {
annotate_img.at<Vec2i>(y,x)[0]=x;
annotate_img.at<Vec2i>(y,x)[1]=y;
}
}
else {
dist_img.at<float>(y,x)=-1;
}
}
}
</code></pre>
The code should be like this:
<pre><code class="c">
for (int y=0;y<h;++y) {
for (int x=0;x<w;++x) {
// initialize
if (&annotate_img!=NULL) {
annotate_img.at<Vec2i>(y,x)[0]=x;
annotate_img.at<Vec2i>(y,x)[1]=y;
}
unsigned char edge_val = edges_img.at<uchar>(y,x);
if ( (edge_val!=0) ) {
q.push(make_pair(x,y));
dist_img.at<float>(y,x)= 0;
}
else {
dist_img.at<float>(y,x)=-1;
}
}
}
</code></pre>
I am testing on :
Windows XP
Visual Studio Professional 2008
OpenCV 2.3.1