added test for http://code.opencv.org/issues/2957
This commit is contained in:
parent
b37aaa8303
commit
05d888316a
@ -40,6 +40,7 @@
|
||||
//M*/
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
#include "opencv2/highgui.hpp"
|
||||
|
||||
using namespace cv;
|
||||
using namespace std;
|
||||
@ -429,4 +430,64 @@ TEST(Core_Drawing, polylines)
|
||||
int cnt = countNonZero(img);
|
||||
ASSERT_EQ(cnt, 21);
|
||||
}
|
||||
|
||||
//rotate/flip a quadrant appropriately
|
||||
static void rot(int n, int *x, int *y, int rx, int ry)
|
||||
{
|
||||
if (ry == 0) {
|
||||
if (rx == 1) {
|
||||
*x = n-1 - *x;
|
||||
*y = n-1 - *y;
|
||||
}
|
||||
|
||||
//Swap x and y
|
||||
int t = *x;
|
||||
*x = *y;
|
||||
*y = t;
|
||||
}
|
||||
}
|
||||
|
||||
static void d2xy(int n, int d, int *x, int *y)
|
||||
{
|
||||
int rx, ry, s, t=d;
|
||||
*x = *y = 0;
|
||||
for (s=1; s<n; s*=2)
|
||||
{
|
||||
rx = 1 & (t/2);
|
||||
ry = 1 & (t ^ rx);
|
||||
rot(s, x, y, rx, ry);
|
||||
*x += s * rx;
|
||||
*y += s * ry;
|
||||
t /= 4;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Imgproc_FindContours, hilbert)
|
||||
{
|
||||
int n = 64, n2 = n*n, scale = 10, w = (n + 2)*scale;
|
||||
Point ofs(scale, scale);
|
||||
Mat img(w, w, CV_8U);
|
||||
img.setTo(Scalar::all(0));
|
||||
|
||||
Point p(0,0);
|
||||
for( int i = 0; i < n2; i++ )
|
||||
{
|
||||
Point q(0,0);
|
||||
d2xy(n2, i, &q.x, &q.y);
|
||||
line(img, p*scale + ofs, q*scale + ofs, Scalar::all(255));
|
||||
p = q;
|
||||
}
|
||||
dilate(img, img, Mat());
|
||||
vector<vector<Point> > contours;
|
||||
findContours(img, contours, noArray(), RETR_LIST, CHAIN_APPROX_SIMPLE);
|
||||
printf("ncontours = %d, contour[0].npoints=%d\n", (int)contours.size(), (int)contours[0].size());
|
||||
img.setTo(Scalar::all(0));
|
||||
|
||||
drawContours(img, contours, 0, Scalar::all(255), 1);
|
||||
//imshow("hilbert", img);
|
||||
//waitKey();
|
||||
ASSERT_EQ(1, (int)contours.size());
|
||||
ASSERT_EQ(9832, (int)contours[0].size());
|
||||
}
|
||||
|
||||
/* End of file. */
|
||||
|
Loading…
x
Reference in New Issue
Block a user