The following issues were found

samples/java/tutorial_code/ImgTrans/Filter2D/Filter2D_Demo.java
20 issues
System.out.println is used
Design

Line: 33

              
        // Check if image is loaded fine
        if( src.empty() ) {
            System.out.println("Error opening image!");
            System.out.println("Program Arguments: [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }
        //! [load]


            

Reported by PMD.

System.out.println is used
Design

Line: 34

                      // Check if image is loaded fine
        if( src.empty() ) {
            System.out.println("Error opening image!");
            System.out.println("Program Arguments: [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }
        //! [load]

        //! [init_arguments]

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 32

                      src = Imgcodecs.imread(imageName, Imgcodecs.IMREAD_COLOR);

        // Check if image is loaded fine
        if( src.empty() ) {
            System.out.println("Error opening image!");
            System.out.println("Program Arguments: [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }
        //! [load]

            

Reported by PMD.

System.exit() should not be used in J2EE/JEE apps
Error

Line: 35

                      if( src.empty() ) {
            System.out.println("Error opening image!");
            System.out.println("Program Arguments: [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }
        //! [load]

        //! [init_arguments]
        // Initialize arguments for the filter

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 54

                          // Update kernel size for a normalized box filter
            kernel_size = 3 + 2*( ind%5 );
            Mat ones = Mat.ones( kernel_size, kernel_size, CvType.CV_32F );
            Core.multiply(ones, new Scalar(1/(double)(kernel_size*kernel_size)), kernel);
            //! [update_kernel]

            //! [apply_filter]
            // Apply filter
            Imgproc.filter2D(src, dst, ddepth , kernel, anchor, delta, Core.BORDER_DEFAULT );

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 65

              
            int c = HighGui.waitKey(500);
            // Press 'ESC' to exit the program
            if( c == 27 )
            { break; }

            ind++;
        }


            

Reported by PMD.

System.exit() should not be used in J2EE/JEE apps
Error

Line: 71

                          ind++;
        }

        System.exit(0);
    }
}

public class Filter2D_Demo {
    public static void main(String[] args) {

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 75

                  }
}

public class Filter2D_Demo {
    public static void main(String[] args) {
        // Load the native library.
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        new Filter2D_DemoRun().run(args);
    }

            

Reported by PMD.

Avoid unused imports such as 'org.opencv.core'
Design

Line: 6

               * @brief Sample code that shows how to implement your own linear filters by using filter2D function
 */

import org.opencv.core.*;
import org.opencv.core.Point;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;


            

Reported by PMD.

Consider using varargs for methods or constructors which take an array the last parameter.
Design

Line: 14

              
class Filter2D_DemoRun {

    public void run(String[] args) {
        // Declare variables
        Mat src, dst = new Mat();

        Mat kernel = new Mat();
        Point anchor;

            

Reported by PMD.

modules/ts/misc/run_long.py
20 issues
Redefining name 'module' from outer scope (line 112)
Error

Line: 75 Column: 26

              ]


def longTestFilter(data, module=None):
    res = ['*', '-'] + [v for m, v, _time in data if module is None or m == module]
    return '--gtest_filter={}'.format(':'.join(res))


# Parse one xml file, filter out tests which took less than 'timeLimit' seconds

            

Reported by Pylint.

Redefining name 'res' from outer scope (line 108)
Error

Line: 76 Column: 5

              

def longTestFilter(data, module=None):
    res = ['*', '-'] + [v for m, v, _time in data if module is None or m == module]
    return '--gtest_filter={}'.format(':'.join(res))


# Parse one xml file, filter out tests which took less than 'timeLimit' seconds
# Returns tuple: ( <module_name>, [ (<module_name>, <test_name>, <test_time>), ... ] )

            

Reported by Pylint.

Using xml.etree.ElementTree.parse to parse untrusted XML data is known to be vulnerable to XML attacks. Replace xml.etree.ElementTree.parse with its defusedxml equivalent function or make sure defusedxml.defuse_stdlib() is called
Security blacklist

Line: 83
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_calls.html#b313-b320-xml-bad-elementtree

              # Parse one xml file, filter out tests which took less than 'timeLimit' seconds
# Returns tuple: ( <module_name>, [ (<module_name>, <test_name>, <test_time>), ... ] )
def parseOneFile(filename, timeLimit):
    tree = ET.parse(filename)
    root = tree.getroot()

    def guess(s, delims):
        for delim in delims:
            tmp = s.partition(delim)

            

Reported by Bandit.

Redefining name 'module' from outer scope (line 112)
Error

Line: 92 Column: 5

                          if len(tmp[1]) != 0:
                return tmp[0]
        return None
    module = guess(filename, ['_posix_', '_nt_', '__']) or root.get('cv_module_name')
    if not module:
        return (None, None)
    res = []
    for elem in root.findall('.//testcase'):
        key = '{}.{}'.format(elem.get('classname'), elem.get('name'))

            

Reported by Pylint.

Redefining name 'res' from outer scope (line 108)
Error

Line: 95 Column: 5

                  module = guess(filename, ['_posix_', '_nt_', '__']) or root.get('cv_module_name')
    if not module:
        return (None, None)
    res = []
    for elem in root.findall('.//testcase'):
        key = '{}.{}'.format(elem.get('classname'), elem.get('name'))
        val = elem.get('time')
        if float(val) >= timeLimit:
            res.append((module, key, float(val)))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python
from __future__ import print_function
import xml.etree.ElementTree as ET
from glob import glob
from pprint import PrettyPrinter as PP

LONG_TESTS_DEBUG_VALGRIND = [
    ('calib3d', 'Calib3d_InitUndistortRectifyMap.accuracy', 2017.22),
    ('dnn', 'Reproducibility*', 1000),  # large DNN models

            

Reported by Pylint.

Using xml.etree.ElementTree to parse untrusted XML data is known to be vulnerable to XML attacks. Replace xml.etree.ElementTree with the equivalent defusedxml package, or make sure defusedxml.defuse_stdlib() is called.
Security blacklist

Line: 3
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b405-import-xml-etree

              #!/usr/bin/env python
from __future__ import print_function
import xml.etree.ElementTree as ET
from glob import glob
from pprint import PrettyPrinter as PP

LONG_TESTS_DEBUG_VALGRIND = [
    ('calib3d', 'Calib3d_InitUndistortRectifyMap.accuracy', 2017.22),
    ('dnn', 'Reproducibility*', 1000),  # large DNN models

            

Reported by Bandit.

Line too long (114/100)
Error

Line: 21 Column: 1

                  ('dnn', '*eccv16*', 1000),  # very large DNN models
    ('dnn', '*OpenPose*', 1000),  # very large DNN models
    ('dnn', '*SSD/*', 1000),  # very large DNN models
    ('gapi', 'Fluid.MemoryConsumptionDoesNotGrowOnReshape', 1000000),  # test doesn't work properly under valgrind
    ('face', 'CV_Face_FacemarkLBF.test_workflow', 10000.0), # >40min on i7
    ('features2d', 'Features2d/DescriptorImage.no_crash/3', 1000),
    ('features2d', 'Features2d/DescriptorImage.no_crash/4', 1000),
    ('features2d', 'Features2d/DescriptorImage.no_crash/5', 1000),
    ('features2d', 'Features2d/DescriptorImage.no_crash/6', 1000),

            

Reported by Pylint.

Line too long (147/100)
Error

Line: 49 Column: 1

                  ('tracking', '*DistanceAndOverlap*/2', 1000.0), # faceocc2
    ('videoio', 'videoio/videoio_ffmpeg.write_big*', 1000),
    ('videoio', 'videoio_ffmpeg.parallel', 1000),
    ('videoio', '*videocapture_acceleration*', 1000), # valgrind can't track HW buffers: Conditional jump or move depends on uninitialised value(s)
    ('videoio', '*videowriter_acceleration*', 1000), # valgrind crash: set_mempolicy: Operation not permitted
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_BoostDesc_LBGM.regression', 1124.51),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG120.regression', 2198.1),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG48.regression', 1958.52),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG64.regression', 2113.12),

            

Reported by Pylint.

Line too long (109/100)
Error

Line: 50 Column: 1

                  ('videoio', 'videoio/videoio_ffmpeg.write_big*', 1000),
    ('videoio', 'videoio_ffmpeg.parallel', 1000),
    ('videoio', '*videocapture_acceleration*', 1000), # valgrind can't track HW buffers: Conditional jump or move depends on uninitialised value(s)
    ('videoio', '*videowriter_acceleration*', 1000), # valgrind crash: set_mempolicy: Operation not permitted
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_BoostDesc_LBGM.regression', 1124.51),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG120.regression', 2198.1),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG48.regression', 1958.52),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG64.regression', 2113.12),
    ('xfeatures2d', 'Features2d_RotationInvariance_Descriptor_VGG80.regression', 2167.16),

            

Reported by Pylint.

samples/python/facedetect.py
20 issues
Unable to import 'cv2'
Error

Line: 14 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

# local modules
from video import create_capture
from common import clock, draw_str


            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 13 Column: 1

              # Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv

# local modules
from video import create_capture
from common import clock, draw_str

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 39 Column: 5

                  args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
    try:
        video_src = video_src[0]
    except:
        video_src = 0
    args = dict(args)
    cascade_fn = args.get('--cascade', "data/haarcascades/haarcascade_frontalface_alt.xml")
    nested_fn  = args.get('--nested-cascade', "data/haarcascades/haarcascade_eye.xml")


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 1

              from common import clock, draw_str


def detect(img, cascade):
    rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30),
                                     flags=cv.CASCADE_SCALE_IMAGE)
    if len(rects) == 0:
        return []
    rects[:,2:] += rects[:,:2]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 29 Column: 1

                  rects[:,2:] += rects[:,:2]
    return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt

            

Reported by Pylint.

Variable name "y1" doesn't conform to snake_case naming style
Error

Line: 30 Column: 13

                  return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt


            

Reported by Pylint.

Variable name "x2" doesn't conform to snake_case naming style
Error

Line: 30 Column: 17

                  return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt


            

Reported by Pylint.

Variable name "y2" doesn't conform to snake_case naming style
Error

Line: 30 Column: 21

                  return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt


            

Reported by Pylint.

Variable name "x1" doesn't conform to snake_case naming style
Error

Line: 30 Column: 9

                  return rects

def draw_rects(img, rects, color):
    for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 33 Column: 1

                  for x1, y1, x2, y2 in rects:
        cv.rectangle(img, (x1, y1), (x2, y2), color, 2)

def main():
    import sys, getopt

    args, video_src = getopt.getopt(sys.argv[1:], '', ['cascade=', 'nested-cascade='])
    try:
        video_src = video_src[0]

            

Reported by Pylint.

samples/python/coherence.py
20 issues
Unable to import 'cv2'
Error

Line: 21 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
    h, w = img.shape[:2]

    for i in xrange(iter_n):

            

Reported by Pylint.

Reimport 'sys' (imported line 14)
Error

Line: 50 Column: 5

              

def main():
    import sys
    try:
        fn = sys.argv[1]
    except:
        fn = 'baboon.jpg'


            

Reported by Pylint.

Redefining name 'sys' from outer scope (line 14)
Error

Line: 50 Column: 5

              

def main():
    import sys
    try:
        fn = sys.argv[1]
    except:
        fn = 'baboon.jpg'


            

Reported by Pylint.

No exception type(s) specified
Error

Line: 53 Column: 5

                  import sys
    try:
        fn = sys.argv[1]
    except:
        fn = 'baboon.jpg'

    src = cv.imread(cv.samples.findFile(fn))

    def nothing(*argv):

            

Reported by Pylint.

Unused argument 'argv'
Error

Line: 58 Column: 1

              
    src = cv.imread(cv.samples.findFile(fn))

    def nothing(*argv):
        pass

    def update():
        sigma = cv.getTrackbarPos('sigma', 'control')*2+1
        str_sigma = cv.getTrackbarPos('str_sigma', 'control')*2+1

            

Reported by Pylint.

Class name "xrange" doesn't conform to PascalCase naming style
Error

Line: 18 Column: 5

              PY3 = sys.version_info[0] == 3

if PY3:
    xrange = range

import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):

            

Reported by Pylint.

Import "import numpy as np" should be placed at the top of the module
Error

Line: 20 Column: 1

              if PY3:
    xrange = range

import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
    h, w = img.shape[:2]


            

Reported by Pylint.

Import "import cv2 as cv" should be placed at the top of the module
Error

Line: 21 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
    h, w = img.shape[:2]

    for i in xrange(iter_n):

            

Reported by Pylint.

Too many local variables (20/15)
Error

Line: 23 Column: 1

              import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
    h, w = img.shape[:2]

    for i in xrange(iter_n):
        print(i)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 23 Column: 1

              import numpy as np
import cv2 as cv

def coherence_filter(img, sigma = 11, str_sigma = 11, blend = 0.5, iter_n = 4):
    h, w = img.shape[:2]

    for i in xrange(iter_n):
        print(i)


            

Reported by Pylint.

modules/python/test/test_grabcut.py
20 issues
Unable to import 'cv2'
Error

Line: 12 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests

class grabcut_test(NewOpenCVTests):

            

Reported by Pylint.

Unused import sys
Error

Line: 13 Column: 1

              
import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests

class grabcut_test(NewOpenCVTests):


            

Reported by Pylint.

Redundant use of assertTrue with constant value False
Error

Line: 39 Column: 13

                      exp_mask2 = self.get_sample("cv/grabcut/exp_mask2py.png", 0)

        if img is None:
            self.assertTrue(False, 'Missing test data')

        rect = (24, 126, 459, 168)
        mask = np.zeros(img.shape[:2], dtype = np.uint8)
        bgdModel = np.zeros((1,65),np.float64)
        fgdModel = np.zeros((1,65),np.float64)

            

Reported by Pylint.

standard import "import sys" should be placed before "import numpy as np"
Error

Line: 13 Column: 1

              
import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests

class grabcut_test(NewOpenCVTests):


            

Reported by Pylint.

Missing class docstring
Error

Line: 17 Column: 1

              
from tests_common import NewOpenCVTests

class grabcut_test(NewOpenCVTests):

    def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)

            

Reported by Pylint.

Class name "grabcut_test" doesn't conform to PascalCase naming style
Error

Line: 17 Column: 1

              
from tests_common import NewOpenCVTests

class grabcut_test(NewOpenCVTests):

    def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)

            

Reported by Pylint.

Method could be a function
Error

Line: 19 Column: 5

              
class grabcut_test(NewOpenCVTests):

    def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)
        nonIntersectArea = np.count_nonzero(mask != exp)
        curRatio = float(nonIntersectArea) / expArea

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 5

              
class grabcut_test(NewOpenCVTests):

    def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)
        nonIntersectArea = np.count_nonzero(mask != exp)
        curRatio = float(nonIntersectArea) / expArea

            

Reported by Pylint.

Variable name "maxDiffRatio" doesn't conform to snake_case naming style
Error

Line: 21 Column: 9

              
    def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)
        nonIntersectArea = np.count_nonzero(mask != exp)
        curRatio = float(nonIntersectArea) / expArea
        return curRatio < maxDiffRatio


            

Reported by Pylint.

Variable name "expArea" doesn't conform to snake_case naming style
Error

Line: 22 Column: 9

                  def verify(self, mask, exp):

        maxDiffRatio = 0.02
        expArea = np.count_nonzero(exp)
        nonIntersectArea = np.count_nonzero(mask != exp)
        curRatio = float(nonIntersectArea) / expArea
        return curRatio < maxDiffRatio

    def scaleMask(self, mask):

            

Reported by Pylint.

samples/java/tutorial_code/features2D/Homography/PanoramaStitchingRotatingCamera.java
20 issues
System.out.println is used
Design

Line: 58

                      Core.gemm(tmp, cameraMatrix.inv(), 1, new Mat(), 0, H);
        Scalar s = new Scalar(H.get(2, 2)[0]);
        Core.divide(H, s, H);
        System.out.println(H.dump());
        //! [compute-homography]

        //! [stitch]
        Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );

            

Reported by PMD.

The initializer for variable 'img2' is never used (overwritten on line 16)
Design

Line: 14

              class PanoramaStitchingRotatingCameraRun {
    void basicPanoramaStitching (String[] args) {
        String img1path = args[0], img2path = args[1];
        Mat img1 = new Mat(), img2 = new Mat();
        img1 = Imgcodecs.imread(img1path);
        img2 = Imgcodecs.imread(img2path);

        //! [camera-pose-from-Blender-at-location-1]
        Mat c1Mo = new Mat( 4, 4, CvType.CV_64FC1 );

            

Reported by PMD.

The initializer for variable 'img1' is never used (overwritten on line 15)
Design

Line: 14

              class PanoramaStitchingRotatingCameraRun {
    void basicPanoramaStitching (String[] args) {
        String img1path = args[0], img2path = args[1];
        Mat img1 = new Mat(), img2 = new Mat();
        img1 = Imgcodecs.imread(img1path);
        img2 = Imgcodecs.imread(img2path);

        //! [camera-pose-from-Blender-at-location-1]
        Mat c1Mo = new Mat( 4, 4, CvType.CV_64FC1 );

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 63

              
        //! [stitch]
        Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 63

              
        //! [stitch]
        Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]


            

Reported by PMD.

The initializer for variable 'half' is never used (overwritten on line 65)
Design

Line: 64

                      //! [stitch]
        Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]

        Mat img_compare = new Mat();

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 65

                      Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]

        Mat img_compare = new Mat();
        Mat img_space = Mat.zeros(new Size(50, img1.rows()), CvType.CV_8UC3);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 65

                      Mat img_stitch = new Mat();
        Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]

        Mat img_compare = new Mat();
        Mat img_space = Mat.zeros(new Size(50, img1.rows()), CvType.CV_8UC3);

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 66

                      Imgproc.warpPerspective(img2, img_stitch, H, new Size(img2.cols()*2, img2.rows()) );
        Mat half = new Mat();
        half =  new Mat(img_stitch, new Rect(0, 0, img1.cols(), img1.rows()));
        img1.copyTo(half);
        //! [stitch]

        Mat img_compare = new Mat();
        Mat img_space = Mat.zeros(new Size(50, img1.rows()), CvType.CV_8UC3);
        List<Mat>list = new ArrayList<>();

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 70

                      //! [stitch]

        Mat img_compare = new Mat();
        Mat img_space = Mat.zeros(new Size(50, img1.rows()), CvType.CV_8UC3);
        List<Mat>list = new ArrayList<>();
        list.add(img1);
        list.add(img_space);
        list.add(img2);
        Core.hconcat(list, img_compare);

            

Reported by PMD.

doc/tools/scan_tutorials.py
20 issues
Redefining name 'f' from outer scope (line 82)
Error

Line: 18 Column: 34

                      self.children = [] # ordered titles
        self.prev = None
        self.next = None
        with open(path, "rt") as f:
            self.parse(f)

    def parse(self, f):
        rx_title = re.compile(r"\{#(\w+)\}")
        rx_subpage = re.compile(r"@subpage\s+(\w+)")

            

Reported by Pylint.

Redefining name 'f' from outer scope (line 82)
Error

Line: 21 Column: 21

                      with open(path, "rt") as f:
            self.parse(f)

    def parse(self, f):
        rx_title = re.compile(r"\{#(\w+)\}")
        rx_subpage = re.compile(r"@subpage\s+(\w+)")
        rx_prev = re.compile(r"@prev_tutorial\{(\w+)\}")
        rx_next = re.compile(r"@next_tutorial\{(\w+)\}")
        for line in f:

            

Reported by Pylint.

Redefining name 'res' from outer scope (line 87)
Error

Line: 48 Column: 9

                              continue

    def verify_prev_next(self, storage):
        res = True

        if self.title is None:
            print("[W] No title")
            res = False


            

Reported by Pylint.

Redefining built-in 'next'
Error

Line: 62 Column: 9

                              res = False
            prev = c.title

        next = None
        for one in reversed(self.children):
            c = storage[one]
            if c.next is not None and c.next != next:
                print("[W] Wrong next_tutorial: expected {} / actual {}".format(c.next, next))
                res = False

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python

from pathlib import Path
import re

# Tasks
# 1. Find all tutorials
# 2. Generate tree (@subpage)
# 3. Check prev/next nodes

            

Reported by Pylint.

Class 'Tutorial' inherits from object, can be safely removed from bases in python3
Error

Line: 11 Column: 1

              # 2. Generate tree (@subpage)
# 3. Check prev/next nodes

class Tutorial(object):
    def __init__(self, path):
        self.path = path
        self.title = None # doxygen title
        self.children = [] # ordered titles
        self.prev = None

            

Reported by Pylint.

Missing class docstring
Error

Line: 11 Column: 1

              # 2. Generate tree (@subpage)
# 3. Check prev/next nodes

class Tutorial(object):
    def __init__(self, path):
        self.path = path
        self.title = None # doxygen title
        self.children = [] # ordered titles
        self.prev = None

            

Reported by Pylint.

Variable name "f" doesn't conform to snake_case naming style
Error

Line: 18 Column: 34

                      self.children = [] # ordered titles
        self.prev = None
        self.next = None
        with open(path, "rt") as f:
            self.parse(f)

    def parse(self, f):
        rx_title = re.compile(r"\{#(\w+)\}")
        rx_subpage = re.compile(r"@subpage\s+(\w+)")

            

Reported by Pylint.

Argument name "f" doesn't conform to snake_case naming style
Error

Line: 21 Column: 5

                      with open(path, "rt") as f:
            self.parse(f)

    def parse(self, f):
        rx_title = re.compile(r"\{#(\w+)\}")
        rx_subpage = re.compile(r"@subpage\s+(\w+)")
        rx_prev = re.compile(r"@prev_tutorial\{(\w+)\}")
        rx_next = re.compile(r"@next_tutorial\{(\w+)\}")
        for line in f:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 21 Column: 5

                      with open(path, "rt") as f:
            self.parse(f)

    def parse(self, f):
        rx_title = re.compile(r"\{#(\w+)\}")
        rx_subpage = re.compile(r"@subpage\s+(\w+)")
        rx_prev = re.compile(r"@prev_tutorial\{(\w+)\}")
        rx_next = re.compile(r"@next_tutorial\{(\w+)\}")
        for line in f:

            

Reported by Pylint.

samples/android/color-blob-detection/src/org/opencv/samples/colorblobdetect/ColorBlobDetectionActivity.java
20 issues
Avoid using redundant field initializer for 'mIsColorSelected'
Performance

Line: 35

              public class ColorBlobDetectionActivity extends CameraActivity implements OnTouchListener, CvCameraViewListener2 {
    private static final String  TAG              = "OCVSample::Activity";

    private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 35

              public class ColorBlobDetectionActivity extends CameraActivity implements OnTouchListener, CvCameraViewListener2 {
    private static final String  TAG              = "OCVSample::Activity";

    private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 36

                  private static final String  TAG              = "OCVSample::Activity";

    private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 37

              
    private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 38

                  private boolean              mIsColorSelected = false;
    private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 39

                  private Mat                  mRgba;
    private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 40

                  private Scalar               mBlobColorRgba;
    private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;


            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 41

                  private Scalar               mBlobColorHsv;
    private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 42

                  private ColorBlobDetector    mDetector;
    private Mat                  mSpectrum;
    private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
        @Override

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 44

                  private Size                 SPECTRUM_SIZE;
    private Scalar               CONTOUR_COLOR;

    private CameraBridgeViewBase mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {

            

Reported by PMD.

samples/python/tutorial_code/features2D/Homography/perspective_correction.py
20 issues
Unable to import 'cv2'
Error

Line: 8 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv
import sys


def randomColor():
    color = np.random.randint(0, 255,(1, 3))

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python
# -*- coding: utf-8 -*-

# Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv
import sys

            

Reported by Pylint.

standard import "import sys" should be placed before "import numpy as np"
Error

Line: 9 Column: 1

              
import numpy as np
import cv2 as cv
import sys


def randomColor():
    color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

            

Reported by Pylint.

Function name "randomColor" doesn't conform to snake_case naming style
Error

Line: 12 Column: 1

              import sys


def randomColor():
    color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              import sys


def randomColor():
    color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))

            

Reported by Pylint.

Argument name "img2Path" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

                  color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))
    img2 = cv.imread(cv.samples.findFile(img2Path))

    # [find-corners]
    ret1, corners1 = cv.findChessboardCorners(img1, patternSize)

            

Reported by Pylint.

Argument name "patternSize" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

                  color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))
    img2 = cv.imread(cv.samples.findFile(img2Path))

    # [find-corners]
    ret1, corners1 = cv.findChessboardCorners(img1, patternSize)

            

Reported by Pylint.

Argument name "img1Path" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

                  color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))
    img2 = cv.imread(cv.samples.findFile(img2Path))

    # [find-corners]
    ret1, corners1 = cv.findChessboardCorners(img1, patternSize)

            

Reported by Pylint.

Function name "perspectiveCorrection" doesn't conform to snake_case naming style
Error

Line: 16 Column: 1

                  color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))
    img2 = cv.imread(cv.samples.findFile(img2Path))

    # [find-corners]
    ret1, corners1 = cv.findChessboardCorners(img1, patternSize)

            

Reported by Pylint.

Too many local variables (18/15)
Error

Line: 16 Column: 1

                  color = np.random.randint(0, 255,(1, 3))
    return color[0].tolist()

def  perspectiveCorrection(img1Path, img2Path ,patternSize ):
    img1 = cv.imread(cv.samples.findFile(img1Path))
    img2 = cv.imread(cv.samples.findFile(img2Path))

    # [find-corners]
    ret1, corners1 = cv.findChessboardCorners(img1, patternSize)

            

Reported by Pylint.

modules/gapi/misc/python/test/test_gapi_types.py
20 issues
Unable to import 'cv2'
Error

Line: 4 Column: 1

              #!/usr/bin/env python

import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests

            

Reported by Pylint.

Unable to import 'tests_common'
Error

Line: 9 Column: 1

              import sys
import unittest

from tests_common import NewOpenCVTests


try:

    if sys.version_info[:2] < (3, 0):

            

Reported by Pylint.

Method has no argument
Error

Line: 47 Column: 9

                      def setUp(self):
            self.skipTest('Skip tests: ' + message)

        def test_skip():
            pass

    pass



            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 3 Column: 1

              #!/usr/bin/env python

import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests

            

Reported by Pylint.

Unused import os
Error

Line: 5 Column: 1

              
import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests


            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 50 Column: 5

                      def test_skip():
            pass

    pass


if __name__ == '__main__':
    NewOpenCVTests.bootstrap()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python

import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests

            

Reported by Pylint.

standard import "import os" should be placed before "import numpy as np"
Error

Line: 5 Column: 1

              
import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests


            

Reported by Pylint.

standard import "import sys" should be placed before "import numpy as np"
Error

Line: 6 Column: 1

              import numpy as np
import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests



            

Reported by Pylint.

standard import "import unittest" should be placed before "import numpy as np"
Error

Line: 7 Column: 1

              import cv2 as cv
import os
import sys
import unittest

from tests_common import NewOpenCVTests


try:

            

Reported by Pylint.