From abd9675a99b35e14473b1b75b7587c899673b2ba Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 31 Jan 2013 15:34:09 +0400 Subject: [PATCH 1/5] fixed bugs #1718, #2375; attached the new tests to test.py. --- modules/calib3d/src/calibration.cpp | 7 +++++-- modules/calib3d/src/modelest.cpp | 9 ++++++--- modules/python/test/test.py | 6 ++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/modules/calib3d/src/calibration.cpp b/modules/calib3d/src/calibration.cpp index a63448506..e48393502 100644 --- a/modules/calib3d/src/calibration.cpp +++ b/modules/calib3d/src/calibration.cpp @@ -3360,7 +3360,11 @@ void cv::projectPoints( InputArray _opoints, CvMat c_cameraMatrix = cameraMatrix; CvMat c_rvec = rvec, c_tvec = tvec; + double dc0buf[5]={0}; + Mat dc0(5,1,CV_64F,dc0buf); Mat distCoeffs = _distCoeffs.getMat(); + if( distCoeffs.empty() ) + distCoeffs = dc0; CvMat c_distCoeffs = distCoeffs; int ndistCoeffs = distCoeffs.rows + distCoeffs.cols - 1; @@ -3375,8 +3379,7 @@ void cv::projectPoints( InputArray _opoints, pdpddist = &(dpddist = jacobian.colRange(10, 10+ndistCoeffs)); } - cvProjectPoints2( &c_objectPoints, &c_rvec, &c_tvec, &c_cameraMatrix, - (distCoeffs.empty())? 0: &c_distCoeffs, + cvProjectPoints2( &c_objectPoints, &c_rvec, &c_tvec, &c_cameraMatrix, &c_distCoeffs, &c_imagePoints, pdpdrot, pdpdt, pdpdf, pdpdc, pdpddist, aspectRatio ); } diff --git a/modules/calib3d/src/modelest.cpp b/modules/calib3d/src/modelest.cpp index 76f6d6219..cecd708e7 100644 --- a/modules/calib3d/src/modelest.cpp +++ b/modules/calib3d/src/modelest.cpp @@ -460,20 +460,23 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to, double param1, double param2) { Mat from = _from.getMat(), to = _to.getMat(); - int count = from.checkVector(3, CV_32F); + int count = from.checkVector(3); - CV_Assert( count >= 0 && to.checkVector(3, CV_32F) == count ); + CV_Assert( count >= 0 && to.checkVector(3) == count ); _out.create(3, 4, CV_64F); Mat out = _out.getMat(); - _inliers.create(count, 1, CV_8U, -1, true); + _inliers.create(count, 1, CV_8U); Mat inliers = _inliers.getMat(); inliers = Scalar::all(1); + transpose(inliers, inliers); Mat dFrom, dTo; from.convertTo(dFrom, CV_64F); to.convertTo(dTo, CV_64F); + dFrom = dFrom.reshape(3, 1); + dTo = dTo.reshape(3, 1); CvMat F3x4 = out; CvMat mask = inliers; diff --git a/modules/python/test/test.py b/modules/python/test/test.py index 924708c48..7c511e4ef 100755 --- a/modules/python/test/test.py +++ b/modules/python/test/test.py @@ -16,6 +16,8 @@ import functools import cv2.cv as cv +from test2 import * + class OpenCVTests(unittest.TestCase): depths = [ cv.IPL_DEPTH_8U, cv.IPL_DEPTH_8S, cv.IPL_DEPTH_16U, cv.IPL_DEPTH_16S, cv.IPL_DEPTH_32S, cv.IPL_DEPTH_32F, cv.IPL_DEPTH_64F ] @@ -2200,10 +2202,6 @@ class DocumentFragmentTests(OpenCVTests): self.assertEqual(self.hashimg(h1), self.hashimg(h3)) self.assertNotEqual(self.hashimg(h1), self.hashimg(h2)) -class NewTests(OpenCVTests): - - pass - if __name__ == '__main__': print "testing", cv.__version__ random.seed(0) From 82b6419d12d7179fb8ecffd6bcce41cd4f12fcfe Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 31 Jan 2013 16:15:40 +0400 Subject: [PATCH 2/5] added tests for fast (ticket #2613) and estimateAffine3D (#2375) --- modules/python/test/test2.py | 39 ++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/modules/python/test/test2.py b/modules/python/test/test2.py index c7491ad97..6876d3915 100644 --- a/modules/python/test/test2.py +++ b/modules/python/test/test2.py @@ -41,12 +41,47 @@ class Hackathon244Tests(NewOpenCVTests): absa0 = np.abs(a) self.assert_(cv2.norm(a, cv2.NORM_L1) == 15) absa1 = cv2.absdiff(a, 0) - self.assert_(cv2.norm(absa1, absa0, cv2.NORM_INF) == 0) + self.assertEqual(cv2.norm(absa1, absa0, cv2.NORM_INF), 0) def test_imencode(self): a = np.zeros((480, 640), dtype=np.uint8) flag, ajpg = cv2.imencode("img_q90.jpg", a, [cv2.IMWRITE_JPEG_QUALITY, 90]) - self.assert_(flag == True and ajpg.dtype == np.uint8 and ajpg.shape[0] > 1 and ajpg.shape[1] == 1) + self.assertEqual(flag, True) + self.assertEqual(ajpg.dtype, np.uint8) + self.assertGreater(ajpg.shape[0], 1) + self.assertEqual(ajpg.shape[1], 1) + + def test_projectPoints(self): + objpt = np.float64([[1,2,3]]) + imgpt0, jac0 = cv2.projectPoints(objpt, np.zeros(3), np.zeros(3), np.eye(3), np.float64([])) + imgpt1, jac1 = cv2.projectPoints(objpt, np.zeros(3), np.zeros(3), np.eye(3), None) + self.assertEqual(imgpt0.shape, (objpt.shape[0], 1, 2)) + self.assertEqual(imgpt1.shape, imgpt0.shape) + self.assertEqual(jac0.shape, jac1.shape) + self.assertEqual(jac0.shape[0], 2*objpt.shape[0]) + + def test_estimateAffine3D(self): + pattern_size = (11, 8) + pattern_points = np.zeros((np.prod(pattern_size), 3), np.float32) + pattern_points[:,:2] = np.indices(pattern_size).T.reshape(-1, 2) + pattern_points *= 10 + (retval, out, inliers) = cv2.estimateAffine3D(pattern_points, pattern_points) + self.assertEqual(retval, 1) + if cv2.norm(out[2,:]) < 1e-3: + out[2,2]=1 + self.assertLess(cv2.norm(out, np.float64([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0]])), 1e-3) + self.assertEqual(cv2.countNonZero(inliers), pattern_size[0]*pattern_size[1]) + + def test_fast(self): + fd = cv2.FastFeatureDetector(30, True) + img = self.get_sample("samples/cpp/right02.jpg", 0) + img = cv2.medianBlur(img, 3) + imgc = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) + keypoints = fd.detect(img) + self.assert_(600 <= len(keypoints) <= 700) + for kpt in keypoints: + self.assertNotEqual(kpt.response, 0) + if __name__ == '__main__': print "testing", cv.__version__ From 79e278c008da439160418f76546c7853de2ee692 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 31 Jan 2013 16:19:20 +0400 Subject: [PATCH 3/5] applied patch #2587 --- modules/python/src2/defs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/python/src2/defs b/modules/python/src2/defs index 38b5753c0..0298e5be0 100644 --- a/modules/python/src2/defs +++ b/modules/python/src2/defs @@ -323,6 +323,27 @@ #define CV_CAP_PROP_EXPOSURE 15 #define CV_CAP_PROP_CONVERT_RGB 16 #define CV_CAP_PROP_RECTIFICATION 18 +#define CV_CAP_OPENNI 900 +#define CV_CAP_OPENNI_DEPTH_GENERATOR 2147483648 +#define CV_CAP_OPENNI_IMAGE_GENERATOR 1073741824 +#define CV_CAP_OPENNI_DEPTH_MAP 0 +#define CV_CAP_OPENNI_POINT_CLOUD_MAP 1 +#define CV_CAP_OPENNI_DISPARITY_MAP 2 +#define CV_CAP_OPENNI_DISPARITY_MAP_32F 3 +#define CV_CAP_OPENNI_VALID_DEPTH_MASK 4 +#define CV_CAP_OPENNI_BGR_IMAGE 5 +#define CV_CAP_OPENNI_GRAY_IMAGE 6 +#define CV_CAP_PROP_OPENNI_OUTPUT_MODE 100 +#define CV_CAP_OPENNI_VGA_30HZ 0 +#define CV_CAP_OPENNI_SXGA_15HZ 1 +#define CV_CAP_PROP_OPENNI_REGISTRATION 104 +#define CV_CAP_PROP_OPENNI_FRAME_MAX_DEPTH 101 +#define CV_CAP_PROP_OPENNI_BASELINE 102 +#define CV_CAP_PROP_OPENNI_FOCAL_LENGTH 103 +#define CV_CAP_OPENNI_IMAGE_GENERATOR_OUTPUT_MODE 1073741924 +#define CV_CAP_OPENNI_DEPTH_GENERATOR_BASELINE 2147483750 +#define CV_CAP_OPENNI_DEPTH_GENERATOR_FOCAL_LENGTH 2147483751 +#define CV_CAP_OPENNI_DEPTH_GENERATOR_REGISTRATION 2147483752 #define CV_CN_SHIFT 3 #define CV_IMWRITE_JPEG_QUALITY 1 #define CV_IMWRITE_PNG_COMPRESSION 16 From 7ca38d63d94665d3c17539da2183da78af94e4ff Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 31 Jan 2013 19:44:16 +0400 Subject: [PATCH 4/5] fixed failure of the C++ test for estimateAffine3D --- modules/calib3d/src/modelest.cpp | 12 +++++++----- modules/core/src/matrix.cpp | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/modules/calib3d/src/modelest.cpp b/modules/calib3d/src/modelest.cpp index cecd708e7..d928caf3e 100644 --- a/modules/calib3d/src/modelest.cpp +++ b/modules/calib3d/src/modelest.cpp @@ -467,10 +467,8 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to, _out.create(3, 4, CV_64F); Mat out = _out.getMat(); - _inliers.create(count, 1, CV_8U); - Mat inliers = _inliers.getMat(); + Mat inliers(1, count, CV_8U); inliers = Scalar::all(1); - transpose(inliers, inliers); Mat dFrom, dTo; from.convertTo(dFrom, CV_64F); @@ -479,7 +477,7 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to, dTo = dTo.reshape(3, 1); CvMat F3x4 = out; - CvMat mask = inliers; + CvMat mask = inliers; CvMat m1 = dFrom; CvMat m2 = dTo; @@ -487,5 +485,9 @@ int cv::estimateAffine3D(InputArray _from, InputArray _to, param1 = param1 <= 0 ? 3 : param1; param2 = (param2 < epsilon) ? 0.99 : (param2 > 1 - epsilon) ? 0.99 : param2; - return Affine3DEstimator().runRANSAC(&m1, &m2, &F3x4, &mask, param1, param2 ); + int ok = Affine3DEstimator().runRANSAC(&m1, &m2, &F3x4, &mask, param1, param2 ); + if( _inliers.needed() ) + transpose(inliers, _inliers); + + return ok; } diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 21dfd6141..dd4518a80 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -1927,6 +1927,14 @@ void cv::transpose( InputArray _src, OutputArray _dst ) _dst.create(src.cols, src.rows, src.type()); Mat dst = _dst.getMat(); + // handle the case of single-column/single-row matrices, stored in STL vectors. + if( src.rows != dst.cols || src.cols != dst.rows ) + { + CV_Assert( src.cols == 1 || src.rows == 1 ); + src.copyTo(dst); + return; + } + if( dst.data == src.data ) { TransposeInplaceFunc func = transposeInplaceTab[esz]; From 54e0765d80b7c3b2b99473fa9db2d3d1ed5173b7 Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Thu, 31 Jan 2013 20:26:16 +0400 Subject: [PATCH 5/5] yet another minor fix in cv::transpose() --- modules/core/src/matrix.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index dd4518a80..54adb5db2 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -1930,7 +1930,7 @@ void cv::transpose( InputArray _src, OutputArray _dst ) // handle the case of single-column/single-row matrices, stored in STL vectors. if( src.rows != dst.cols || src.cols != dst.rows ) { - CV_Assert( src.cols == 1 || src.rows == 1 ); + CV_Assert( src.size() == dst.size() && (src.cols == 1 || src.rows == 1) ); src.copyTo(dst); return; }