createShapeContextDistanceExtractor()->computeDistance throws exception for certain shaped (Bug #4490)


Added by Do Bi over 9 years ago. Updated over 9 years ago.


Status:New Start date:2015-07-21
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Affected version:branch 'master' (3.0-dev) Operating System:Windows
Difficulty: HW Platform:x86
Pull request:

Description

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 <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1<< 3) - 1))*4) & 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 <math.h>
#include <iostream>

using namespace cv;
using namespace std;

vector<Point> GetContour(const Mat& img) {
cv::threshold(img, img, 128, 255, cv::THRESH_BINARY);
vector<vector<Point>> conts;
cv::findContours(img, conts, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);
if (conts.empty())
return vector<Point>();
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 << createShapeContextDistanceExtractor()->computeDistance(shape1, shape2) << endl;
}@

in VC2013.

With other shapes or with createHausdorffDistanceExtractor instead of createShapeContextDistanceExtractor it does not crash.


History

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/5076

Also available in: Atom PDF