python(test): enable pylint checks for tests
authorAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sun, 3 Sep 2017 11:17:15 +0000 (11:17 +0000)
committerAlexander Alekhin <alexander.a.alekhin@gmail.com>
Sun, 3 Sep 2017 18:19:17 +0000 (18:19 +0000)
20 files changed:
CMakeLists.txt
modules/python/test/test.py
modules/python/test/test_calibration.py
modules/python/test/test_camshift.py
modules/python/test/test_digits.py
modules/python/test/test_facedetect.py
modules/python/test/test_feature_homography.py
modules/python/test/test_gaussian_mix.py
modules/python/test/test_goodfeatures.py
modules/python/test/test_houghcircles.py
modules/python/test/test_kmeans.py
modules/python/test/test_letter_recog.py
modules/python/test/test_lk_homography.py
modules/python/test/test_lk_track.py
modules/python/test/test_mser.py
modules/python/test/test_peopledetect.py
modules/python/test/test_shape.py
modules/python/test/test_squares.py
modules/python/test/test_stitching.py
modules/python/test/tests_common.py

index f2e28e5..2d288af 100644 (file)
@@ -853,6 +853,7 @@ if(ANDROID OR NOT UNIX)
 endif()
 
 if(COMMAND ocv_pylint_finalize)
+  ocv_pylint_add_directory(${CMAKE_CURRENT_LIST_DIR}/modules/python/test)
   ocv_pylint_add_directory(${CMAKE_CURRENT_LIST_DIR}/samples/python)
   ocv_pylint_add_directory(${CMAKE_CURRENT_LIST_DIR}/samples/dnn)
   ocv_pylint_add_directory_recurse(${CMAKE_CURRENT_LIST_DIR}/samples/python/tutorial_code)
index be3f821..222f321 100755 (executable)
@@ -75,7 +75,6 @@ class Hackathon244Tests(NewOpenCVTests):
         fd = cv2.FastFeatureDetector_create(30, True)
         img = self.get_sample("samples/data/right02.jpg", 0)
         img = cv2.medianBlur(img, 3)
-        imgc = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)
         keypoints = fd.detect(img)
         self.assertTrue(600 <= len(keypoints) <= 700)
         for kpt in keypoints:
@@ -99,7 +98,6 @@ class Hackathon244Tests(NewOpenCVTests):
         np.random.seed(244)
         a = np.random.randn(npt,2).astype('float32')*50 + 150
 
-        img = np.zeros((300, 300, 3), dtype='uint8')
         be = cv2.fitEllipse(a)
         br = cv2.minAreaRect(a)
         mc, mr = cv2.minEnclosingCircle(a)
@@ -138,10 +136,10 @@ class Hackathon244Tests(NewOpenCVTests):
 
     def test_umat_handle(self):
         a_um = cv2.UMat(256, 256, cv2.CV_32F)
-        ctx_handle = cv2.UMat.context()  # obtain context handle
-        queue_handle = cv2.UMat.queue()  # obtain queue handle
-        a_handle = a_um.handle(cv2.ACCESS_READ)  # obtain buffer handle
-        offset = a_um.offset  # obtain buffer offset
+        _ctx_handle = cv2.UMat.context()  # obtain context handle
+        _queue_handle = cv2.UMat.queue()  # obtain queue handle
+        _a_handle = a_um.handle(cv2.ACCESS_READ)  # obtain buffer handle
+        _offset = a_um.offset  # obtain buffer offset
 
     def test_umat_matching(self):
         img1 = self.get_sample("samples/data/right01.jpg")
@@ -186,11 +184,11 @@ class Hackathon244Tests(NewOpenCVTests):
         p0_umat = cv2.UMat(np.array(sorted(p0_umat.get(), key=lambda p: tuple(p[0]))))
         self.assertTrue(np.allclose(p0_umat.get(), p0))
 
-        p1_mask_err = cv2.calcOpticalFlowPyrLK(img1, img2, p0, None)
+        _p1_mask_err = cv2.calcOpticalFlowPyrLK(img1, img2, p0, None)
 
-        p1_mask_err_umat0 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(img1, img2, p0_umat, None))
-        p1_mask_err_umat1 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(cv2.UMat(img1), img2, p0_umat, None))
-        p1_mask_err_umat2 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(img1, cv2.UMat(img2), p0_umat, None))
+        _p1_mask_err_umat0 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(img1, img2, p0_umat, None))
+        _p1_mask_err_umat1 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(cv2.UMat(img1), img2, p0_umat, None))
+        _p1_mask_err_umat2 = map(cv2.UMat.get, cv2.calcOpticalFlowPyrLK(img1, cv2.UMat(img2), p0_umat, None))
 
         # # results of OCL optical flow differs from CPU implementation, so result can not be easily compared
         # for p1_mask_err_umat in [p1_mask_err_umat0, p1_mask_err_umat1, p1_mask_err_umat2]:
@@ -212,5 +210,5 @@ if __name__ == '__main__':
     except KeyError:
         print('Missing opencv extra repository. Some of tests may fail.')
     random.seed(0)
-    unit_argv = [sys.argv[0]] + other;
+    unit_argv = [sys.argv[0]] + other
     unittest.main(argv=unit_argv)
index 584c7e6..f946a5b 100644 (file)
@@ -16,8 +16,6 @@ from tests_common import NewOpenCVTests
 class calibration_test(NewOpenCVTests):
 
     def test_calibration(self):
-
-        from glob import glob
         img_names = []
         for i in range(1, 15):
             if i < 10:
@@ -34,7 +32,6 @@ class calibration_test(NewOpenCVTests):
         obj_points = []
         img_points = []
         h, w = 0, 0
-        img_names_undistort = []
         for fn in img_names:
             img = self.get_sample(fn, 0)
             if img is None:
@@ -53,7 +50,7 @@ class calibration_test(NewOpenCVTests):
             obj_points.append(pattern_points)
 
         # calculate camera distortion
-        rms, camera_matrix, dist_coefs, rvecs, tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h), None, None, flags = 0)
+        rms, camera_matrix, dist_coefs, _rvecs, _tvecs = cv2.calibrateCamera(obj_points, img_points, (w, h), None, None, flags = 0)
 
         eps = 0.01
         normCamEps = 10.0
index a824320..96ab58a 100644 (file)
@@ -73,7 +73,7 @@ class camshift_test(NewOpenCVTests):
                 prob = cv2.calcBackProject([hsv], [0], self.hist, [0, 180], 1)
                 prob &= mask
                 term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 )
-                track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)
+                _track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)
 
             trackingRect = np.array(self.track_window)
             trackingRect[2] += trackingRect[0]
index c7ac996..2643d05 100644 (file)
@@ -71,7 +71,7 @@ class KNearest(StatModel):
         self.model.train(samples, cv2.ml.ROW_SAMPLE, responses)
 
     def predict(self, samples):
-        retval, results, neigh_resp, dists = self.model.findNearest(samples, self.k)
+        _retval, results, _neigh_resp, _dists = self.model.findNearest(samples, self.k)
         return results.ravel()
 
 class SVM(StatModel):
@@ -147,7 +147,7 @@ class digits_test(NewOpenCVTests):
         samples = preprocess_hog(digits2)
 
         train_n = int(0.9*len(samples))
-        digits_train, digits_test = np.split(digits2, [train_n])
+        _digits_train, digits_test = np.split(digits2, [train_n])
         samples_train, samples_test = np.split(samples, [train_n])
         labels_train, labels_test = np.split(labels, [train_n])
         errors = list()
index 8d64fde..aa86a4f 100644 (file)
@@ -23,8 +23,6 @@ from tests_common import NewOpenCVTests, intersectionRate
 class facedetect_test(NewOpenCVTests):
 
     def test_facedetect(self):
-        import sys, getopt
-
         cascade_fn = self.repoPath + '/data/haarcascades/haarcascade_frontalface_alt.xml'
         nested_fn  = self.repoPath + '/data/haarcascades/haarcascade_eye.xml'
 
index 861ff92..c8c5dae 100644 (file)
@@ -28,7 +28,7 @@ def intersectionRate(s1, s2):
     x1, y1, x2, y2 = s1
     s1 = np.array([[x1, y1], [x2,y1], [x2, y2], [x1, y2]])
 
-    area, intersection = cv2.intersectConvexConvex(s1, np.array(s2))
+    area, _intersection = cv2.intersectConvexConvex(s1, np.array(s2))
     return 2 * area / (cv2.contourArea(s1) + cv2.contourArea(np.array(s2)))
 
 from tests_common import NewOpenCVTests
index 78a29ce..ac6ec43 100644 (file)
@@ -15,7 +15,7 @@ import cv2
 def make_gaussians(cluster_n, img_size):
     points = []
     ref_distrs = []
-    for i in xrange(cluster_n):
+    for _ in xrange(cluster_n):
         mean = (0.1 + 0.8*random.rand(2)) * img_size
         a = (random.rand(2, 2)-0.5)*img_size*0.1
         cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
@@ -44,7 +44,7 @@ class gaussian_mix_test(NewOpenCVTests):
         em.trainEM(points)
         means = em.getMeans()
         covs = em.getCovs()  # Known bug: https://github.com/opencv/opencv/pull/4232
-        found_distrs = zip(means, covs)
+        #found_distrs = zip(means, covs)
 
         matches_count = 0
 
index 5114ad8..5356eba 100644 (file)
@@ -27,10 +27,10 @@ class TestGoodFeaturesToTrack_test(NewOpenCVTests):
                     self.assertTrue(cv2.norm(results[t][i][0] - results2[t][i][0]) == 0)
 
         for t0,t1 in zip(threshes, threshes[1:]):
-             r0 = results[t0]
-             r1 = results[t1]
-             # Increasing thresh should make result list shorter
-             self.assertTrue(len(r0) > len(r1))
-             # Increasing thresh should monly truncate result list
-             for i in range(len(r1)):
+            r0 = results[t0]
+            r1 = results[t1]
+            # Increasing thresh should make result list shorter
+            self.assertTrue(len(r0) > len(r1))
+            # Increasing thresh should monly truncate result list
+            for i in range(len(r1)):
                 self.assertTrue(cv2.norm(r1[i][0] - r0[i][0])==0)
\ No newline at end of file
index 318153a..23900d4 100644 (file)
@@ -17,7 +17,6 @@ from tests_common import NewOpenCVTests
 def circleApproximation(circle):
 
     nPoints = 30
-    phi = 0
     dPhi = 2*pi / nPoints
     contour = []
     for i in range(nPoints):
index 4f886d9..512d535 100644 (file)
@@ -21,7 +21,7 @@ def make_gaussians(cluster_n, img_size):
     points = []
     ref_distrs = []
     sizes = []
-    for i in xrange(cluster_n):
+    for _ in xrange(cluster_n):
         mean = (0.1 + 0.8*random.rand(2)) * img_size
         a = (random.rand(2, 2)-0.5)*img_size*0.1
         cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
@@ -59,7 +59,7 @@ class kmeans_test(NewOpenCVTests):
         points, _, clusterSizes = make_gaussians(cluster_n, img_size)
 
         term_crit = (cv2.TERM_CRITERIA_EPS, 30, 0.1)
-        ret, labels, centers = cv2.kmeans(points, cluster_n, None, term_crit, 10, 0)
+        _ret, labels, centers = cv2.kmeans(points, cluster_n, None, term_crit, 10, 0)
 
         self.assertEqual(len(centers), cluster_n)
 
index 574741f..83657ec 100644 (file)
@@ -59,12 +59,12 @@ class RTrees(LetterStatModel):
         self.model = cv2.ml.RTrees_create()
 
     def train(self, samples, responses):
-        sample_n, var_n = samples.shape
+        #sample_n, var_n = samples.shape
         self.model.setMaxDepth(20)
         self.model.train(samples, cv2.ml.ROW_SAMPLE, responses.astype(int))
 
     def predict(self, samples):
-        ret, resp = self.model.predict(samples)
+        _ret, resp = self.model.predict(samples)
         return resp.ravel()
 
 
@@ -76,7 +76,7 @@ class KNearest(LetterStatModel):
         self.model.train(samples, cv2.ml.ROW_SAMPLE, responses)
 
     def predict(self, samples):
-        retval, results, neigh_resp, dists = self.model.findNearest(samples, k = 10)
+        _retval, results, _neigh_resp, _dists = self.model.findNearest(samples, k = 10)
         return results.ravel()
 
 
@@ -85,7 +85,7 @@ class Boost(LetterStatModel):
         self.model = cv2.ml.Boost_create()
 
     def train(self, samples, responses):
-        sample_n, var_n = samples.shape
+        _sample_n, var_n = samples.shape
         new_samples = self.unroll_samples(samples)
         new_responses = self.unroll_responses(responses)
         var_types = np.array([cv2.ml.VAR_NUMERICAL] * var_n + [cv2.ml.VAR_CATEGORICAL, cv2.ml.VAR_CATEGORICAL], np.uint8)
@@ -96,7 +96,7 @@ class Boost(LetterStatModel):
 
     def predict(self, samples):
         new_samples = self.unroll_samples(samples)
-        ret, resp = self.model.predict(new_samples)
+        _ret, resp = self.model.predict(new_samples)
 
         return resp.ravel().reshape(-1, self.class_n).argmax(1)
 
@@ -113,7 +113,7 @@ class SVM(LetterStatModel):
         self.model.train(samples, cv2.ml.ROW_SAMPLE, responses.astype(int))
 
     def predict(self, samples):
-        ret, resp = self.model.predict(samples)
+        _ret, resp = self.model.predict(samples)
         return resp.ravel()
 
 
@@ -122,7 +122,7 @@ class MLP(LetterStatModel):
         self.model = cv2.ml.ANN_MLP_create()
 
     def train(self, samples, responses):
-        sample_n, var_n = samples.shape
+        _sample_n, var_n = samples.shape
         new_responses = self.unroll_responses(responses).reshape(-1, self.class_n)
         layer_sizes = np.int32([var_n, 100, 100, self.class_n])
 
@@ -136,7 +136,7 @@ class MLP(LetterStatModel):
         self.model.train(samples, cv2.ml.ROW_SAMPLE, np.float32(new_responses))
 
     def predict(self, samples):
-        ret, resp = self.model.predict(samples)
+        _ret, resp = self.model.predict(samples)
         return resp.argmax(-1)
 
 from tests_common import NewOpenCVTests
index 8e526d0..4dbcb79 100644 (file)
@@ -27,8 +27,8 @@ feature_params = dict( maxCorners = 1000,
                        blockSize = 19 )
 
 def checkedTrace(img0, img1, p0, back_threshold = 1.0):
-    p1, st, err = cv2.calcOpticalFlowPyrLK(img0, img1, p0, None, **lk_params)
-    p0r, st, err = cv2.calcOpticalFlowPyrLK(img1, img0, p1, None, **lk_params)
+    p1, _st, _err = cv2.calcOpticalFlowPyrLK(img0, img1, p0, None, **lk_params)
+    p0r, _st, _err = cv2.calcOpticalFlowPyrLK(img1, img0, p1, None, **lk_params)
     d = abs(p0-p0r).reshape(-1, 2).max(-1)
     status = d < back_threshold
     return p1, status
@@ -77,11 +77,11 @@ class lk_homography_test(NewOpenCVTests):
                 if len(self.p0) < 4:
                     self.p0 = None
                     continue
-                H, status = cv2.findHomography(self.p0, self.p1, cv2.RANSAC, 5.0)
+                _H, status = cv2.findHomography(self.p0, self.p1, cv2.RANSAC, 5.0)
 
                 goodPointsInRect = 0
                 goodPointsOutsideRect = 0
-                for (x0, y0), (x1, y1), good in zip(self.p0[:,0], self.p1[:,0], status[:,0]):
+                for (_x0, _y0), (x1, y1), good in zip(self.p0[:,0], self.p1[:,0], status[:,0]):
                     if good:
                         if isPointInRect((x1,y1), self.render.getCurrentRect()):
                             goodPointsInRect += 1
@@ -91,6 +91,6 @@ class lk_homography_test(NewOpenCVTests):
                     isForegroundHomographyFound = True
                     self.assertGreater(float(goodPointsInRect) / (self.numFeaturesInRectOnStart + 1), 0.6)
             else:
-                p = cv2.goodFeaturesToTrack(frame_gray, **feature_params)
+                self.p0 = cv2.goodFeaturesToTrack(frame_gray, **feature_params)
 
-        self.assertEqual(isForegroundHomographyFound, True)
\ No newline at end of file
+        self.assertEqual(isForegroundHomographyFound, True)
index ccc67a5..655a92f 100644 (file)
@@ -63,8 +63,8 @@ class lk_track_test(NewOpenCVTests):
             if len(self.tracks) > 0:
                 img0, img1 = self.prev_gray, frame_gray
                 p0 = np.float32([tr[-1][0] for tr in self.tracks]).reshape(-1, 1, 2)
-                p1, st, err = cv2.calcOpticalFlowPyrLK(img0, img1, p0, None, **lk_params)
-                p0r, st, err = cv2.calcOpticalFlowPyrLK(img1, img0, p1, None, **lk_params)
+                p1, _st, _err = cv2.calcOpticalFlowPyrLK(img0, img1, p0, None, **lk_params)
+                p0r, _st, _err = cv2.calcOpticalFlowPyrLK(img1, img0, p1, None, **lk_params)
                 d = abs(p0-p0r).reshape(-1, 2).max(-1)
                 good = d < 1
                 new_tracks = []
index f66582e..a95f7ee 100644 (file)
@@ -37,7 +37,7 @@ class mser_test(NewOpenCVTests):
         mserExtractor.setDelta(kDelta)
         np.random.seed(10)
 
-        for i in range(100):
+        for _i in range(100):
 
             use_big_image = int(np.random.rand(1,1)*7) != 0
             invert = int(np.random.rand(1,1)*2) != 0
index fb0a9e9..cd70dc2 100644 (file)
@@ -38,7 +38,7 @@ class peopledetect_test(NewOpenCVTests):
 
             img = self.get_sample(dirPath + sample, 0)
 
-            found, w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
+            found, _w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
             found_filtered = []
             for ri, r in enumerate(found):
                 for qi, q in enumerate(found):
index ad0f0be..218b8e0 100644 (file)
@@ -7,8 +7,8 @@ class shape_test(NewOpenCVTests):
 
     def test_computeDistance(self):
 
-        a = self.get_sample('samples/data/shape_sample/1.png', cv2.IMREAD_GRAYSCALE);
-        b = self.get_sample('samples/data/shape_sample/2.png', cv2.IMREAD_GRAYSCALE);
+        a = self.get_sample('samples/data/shape_sample/1.png', cv2.IMREAD_GRAYSCALE)
+        b = self.get_sample('samples/data/shape_sample/2.png', cv2.IMREAD_GRAYSCALE)
 
         _, ca, _ = cv2.findContours(a, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS)
         _, cb, _ = cv2.findContours(b, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS)
index 214c64b..a6921ef 100644 (file)
@@ -30,8 +30,8 @@ def find_squares(img):
                 bin = cv2.Canny(gray, 0, 50, apertureSize=5)
                 bin = cv2.dilate(bin, None)
             else:
-                retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
-            bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
+                _retval, bin = cv2.threshold(gray, thrs, 255, cv2.THRESH_BINARY)
+            bin, contours, _hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
             for cnt in contours:
                 cnt_len = cv2.arcLength(cnt, True)
                 cnt = cv2.approxPolyDP(cnt, 0.02*cnt_len, True)
@@ -44,7 +44,7 @@ def find_squares(img):
     return squares
 
 def intersectionRate(s1, s2):
-    area, intersection = cv2.intersectConvexConvex(np.array(s1), np.array(s2))
+    area, _intersection = cv2.intersectConvexConvex(np.array(s1), np.array(s2))
     return 2 * area / (cv2.contourArea(np.array(s1)) + cv2.contourArea(np.array(s2)))
 
 def filterSquares(squares, square):
index 9a35357..d8faaec 100644 (file)
@@ -11,7 +11,7 @@ class stitching_test(NewOpenCVTests):
         img2 = self.get_sample('stitching/a2.png')
 
         stitcher = cv2.createStitcher(False)
-        (result, pano) = stitcher.stitch((img1, img2))
+        (_result, pano) = stitcher.stitch((img1, img2))
 
         #cv2.imshow("pano", pano)
         #cv2.waitKey()
index 17ef0dc..7a7e3ba 100644 (file)
@@ -70,7 +70,7 @@ def intersectionRate(s1, s2):
     x1, y1, x2, y2 = s2
     s2 = np.array([[x1, y1], [x2,y1], [x2, y2], [x1, y2]])
 
-    area, intersection = cv2.intersectConvexConvex(s1, s2)
+    area, _intersection = cv2.intersectConvexConvex(s1, s2)
     return 2 * area / (cv2.contourArea(s1) + cv2.contourArea(s2))
 
 def isPointInRect(p, rect):