The following issues were found

modules/core/misc/java/test/MatOfByteTest.java
27 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 16

              
public class MatOfByteTest extends OpenCVTestCase {

    public void testMatOfSubByteArray() {
        byte[] inputBytes = { 1,2,3,4,5 };

        MatOfByte m0 = new MatOfByte(inputBytes);
        MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
        MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 16

              
public class MatOfByteTest extends OpenCVTestCase {

    public void testMatOfSubByteArray() {
        byte[] inputBytes = { 1,2,3,4,5 };

        MatOfByte m0 = new MatOfByte(inputBytes);
        MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
        MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 23

                      MatOfByte m1 = new MatOfByte(0, inputBytes.length, inputBytes);
        MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);

        assertEquals(5.0, m0.size().height);
        assertEquals(1.0, m0.size().width);

        assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
        assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);


            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 24

                      MatOfByte m2 = new MatOfByte(1, inputBytes.length - 2, inputBytes);

        assertEquals(5.0, m0.size().height);
        assertEquals(1.0, m0.size().width);

        assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
        assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);

        assertEquals(3.0, m2.size().height);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 27

                      assertEquals(1.0, m0.size().width);

        assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
        assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);

        assertEquals(3.0, m2.size().height);
        assertEquals(1.0, m2.size().width);

        assertEquals(2.0, m2.get(0, 0)[0]);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 27

                      assertEquals(1.0, m0.size().width);

        assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
        assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);

        assertEquals(3.0, m2.size().height);
        assertEquals(1.0, m2.size().width);

        assertEquals(2.0, m2.get(0, 0)[0]);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 29

                      assertEquals(m0.get(0, 0)[0], m1.get(0, 0)[0]);
        assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);

        assertEquals(3.0, m2.size().height);
        assertEquals(1.0, m2.size().width);

        assertEquals(2.0, m2.get(0, 0)[0]);
        assertEquals(3.0, m2.get(1, 0)[0]);
        assertEquals(4.0, m2.get(2, 0)[0]);

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 30

                      assertEquals(m0.get((int) m0.size().height - 1, 0)[0], m1.get((int) m1.size().height - 1, 0)[0]);

        assertEquals(3.0, m2.size().height);
        assertEquals(1.0, m2.size().width);

        assertEquals(2.0, m2.get(0, 0)[0]);
        assertEquals(3.0, m2.get(1, 0)[0]);
        assertEquals(4.0, m2.get(2, 0)[0]);
    }

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 38

                  }


    public void testMatOfSubByteArray_BadArg() {
        byte[] inputBytes = { 1,2,3,4,5 };

        try {
            MatOfByte m1 = new MatOfByte(-1, inputBytes.length, inputBytes);
            fail("Missing check: offset < 0");

            

Reported by PMD.

Avoid unused local variables such as 'm1'.
Design

Line: 42

                      byte[] inputBytes = { 1,2,3,4,5 };

        try {
            MatOfByte m1 = new MatOfByte(-1, inputBytes.length, inputBytes);
            fail("Missing check: offset < 0");
        } catch (IllegalArgumentException e) {
            // pass
        }


            

Reported by PMD.

samples/java/tutorial_code/ShapeDescriptors/moments/MomentsDemo.java
27 issues
System.err.println is used
Design

Line: 45

                      String filename = args.length > 0 ? args[0] : "../data/stuff.jpg";
        Mat src = Imgcodecs.imread(filename);
        if (src.empty()) {
            System.err.println("Cannot read image: " + filename);
            System.exit(0);
        }

        /// Convert image to gray and blur it
        Imgproc.cvtColor(src, srcGray, Imgproc.COLOR_BGR2GRAY);

            

Reported by PMD.

System.out.println is used
Design

Line: 155

                      //! [showDrawings]

        /// Calculate the area with the moments 00 and compare with the result of the OpenCV function
        System.out.println("\t Info: Area and Contour Length \n");
        for (int i = 0; i < contours.size(); i++) {
            System.out.format(" * Contour[%d] - Area (M_00) = %.2f - Area OpenCV: %.2f - Length: %.2f\n", i,
                    mu.get(i).m00, Imgproc.contourArea(contours.get(i)),
                    Imgproc.arcLength(new MatOfPoint2f(contours.get(i).toArray()), true));
        }

            

Reported by PMD.

Private field 'srcGray' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 31

              import org.opencv.imgproc.Moments;

class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;

            

Reported by PMD.

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

Line: 31

              import org.opencv.imgproc.Moments;

class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;

            

Reported by PMD.

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

Line: 32

              
class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);

            

Reported by PMD.

Private field 'frame' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 32

              
class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);

            

Reported by PMD.

Perhaps 'imgSrcLabel' could be replaced by a local variable.
Design

Line: 33

              class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);


            

Reported by PMD.

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

Line: 33

              class MomentsClass {
    private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);


            

Reported by PMD.

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

Line: 34

                  private Mat srcGray = new Mat();
    private JFrame frame;
    private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);

    public MomentsClass(String[] args) {

            

Reported by PMD.

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

Line: 36

                  private JLabel imgSrcLabel;
    private JLabel imgContoursLabel;
    private static final int MAX_THRESHOLD = 255;
    private int threshold = 100;
    private Random rng = new Random(12345);

    public MomentsClass(String[] args) {
        //! [setup]
        /// Load source image

            

Reported by PMD.

samples/java/tutorial_code/ImgProc/tutorial_template_matching/MatchTemplateDemo.java
27 issues
System.out.println is used
Design

Line: 36

              
    public void run(String[] args) {
        if (args.length < 2) {
            System.out.println("Not enough parameters");
            System.out.println("Program arguments:\n<image_name> <template_name> [<mask_name>]");
            System.exit(-1);
        }

        //! [load_image]

            

Reported by PMD.

System.out.println is used
Design

Line: 37

                  public void run(String[] args) {
        if (args.length < 2) {
            System.out.println("Not enough parameters");
            System.out.println("Program arguments:\n<image_name> <template_name> [<mask_name>]");
            System.exit(-1);
        }

        //! [load_image]
        /// Load image and template

            

Reported by PMD.

System.out.println is used
Design

Line: 53

                      }

        if (img.empty() || templ.empty() || (use_mask && mask.empty())) {
            System.out.println("Can't read one of the images");
            System.exit(-1);
        }

        matchingMethod();
        createJFrame();

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 155

              
        // Customizing the labels
        Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
        labelTable.put(new Integer(0), new JLabel("0 - SQDIFF"));
        labelTable.put(new Integer(1), new JLabel("1 - SQDIFF NORMED"));
        labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 156

                      // Customizing the labels
        Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
        labelTable.put(new Integer(0), new JLabel("0 - SQDIFF"));
        labelTable.put(new Integer(1), new JLabel("1 - SQDIFF NORMED"));
        labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));
        slider.setLabelTable(labelTable);

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 157

                      Hashtable<Integer, JLabel> labelTable = new Hashtable<>();
        labelTable.put(new Integer(0), new JLabel("0 - SQDIFF"));
        labelTable.put(new Integer(1), new JLabel("1 - SQDIFF NORMED"));
        labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));
        slider.setLabelTable(labelTable);


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 158

                      labelTable.put(new Integer(0), new JLabel("0 - SQDIFF"));
        labelTable.put(new Integer(1), new JLabel("1 - SQDIFF NORMED"));
        labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));
        slider.setLabelTable(labelTable);

        slider.addChangeListener(this);

            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 159

                      labelTable.put(new Integer(1), new JLabel("1 - SQDIFF NORMED"));
        labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));
        slider.setLabelTable(labelTable);

        slider.addChangeListener(this);


            

Reported by PMD.

Avoid instantiating Integer objects. Call Integer.valueOf() instead.
Performance

Line: 160

                      labelTable.put(new Integer(2), new JLabel("2 - TM CCORR"));
        labelTable.put(new Integer(3), new JLabel("3 - TM CCORR NORMED"));
        labelTable.put(new Integer(4), new JLabel("4 - TM COEFF"));
        labelTable.put(new Integer(5), new JLabel("5 - TM COEFF NORMED : (Method)"));
        slider.setLabelTable(labelTable);

        slider.addChangeListener(this);

        frame.add(slider);

            

Reported by PMD.

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

Line: 25

              
    //! [declare]
    /// Global Variables
    Boolean use_mask = false;
    Mat img = new Mat(), templ = new Mat();
    Mat mask = new Mat();

    int match_method;


            

Reported by PMD.

modules/python/test/test_squares.py
27 issues
Unable to import 'cv2'
Error

Line: 17 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

            

Reported by Pylint.

Redefining built-in 'bin'
Error

Line: 30 Column: 17

                  for gray in cv.split(img):
        for thrs in xrange(0, 255, 26):
            if thrs == 0:
                bin = cv.Canny(gray, 0, 50, apertureSize=5)
                bin = cv.dilate(bin, None)
            else:
                _retval, bin = cv.threshold(gray, thrs, 255, cv.THRESH_BINARY)
            contours, _hierarchy = cv.findContours(bin, cv.RETR_LIST, cv.CHAIN_APPROX_SIMPLE)
            for cnt in contours:

            

Reported by Pylint.

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

Line: 14 Column: 5

              PY3 = sys.version_info[0] == 3

if PY3:
    xrange = range

import numpy as np
import cv2 as cv



            

Reported by Pylint.

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

Line: 16 Column: 1

              if PY3:
    xrange = range

import numpy as np
import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')

            

Reported by Pylint.

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

Line: 17 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

            

Reported by Pylint.

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

Line: 20 Column: 1

              import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

def find_squares(img):
    img = cv.GaussianBlur(img, (5, 5), 0)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

              import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

def find_squares(img):
    img = cv.GaussianBlur(img, (5, 5), 0)

            

Reported by Pylint.

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

Line: 20 Column: 1

              import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

def find_squares(img):
    img = cv.GaussianBlur(img, (5, 5), 0)

            

Reported by Pylint.

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

Line: 20 Column: 1

              import cv2 as cv


def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

def find_squares(img):
    img = cv.GaussianBlur(img, (5, 5), 0)

            

Reported by Pylint.

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

Line: 21 Column: 5

              

def angle_cos(p0, p1, p2):
    d1, d2 = (p0-p1).astype('float'), (p2-p1).astype('float')
    return abs( np.dot(d1, d2) / np.sqrt( np.dot(d1, d1)*np.dot(d2, d2) ) )

def find_squares(img):
    img = cv.GaussianBlur(img, (5, 5), 0)
    squares = []

            

Reported by Pylint.

modules/gapi/misc/python/test/test_gapi_imgproc.py
27 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: 120 Column: 9

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

        def test_skip():
            pass

    pass



            

Reported by Pylint.

TODO: Extend to use any type and size here
Error

Line: 29 Column: 3

                  class gapi_imgproc_test(NewOpenCVTests):

        def test_good_features_to_track(self):
            # TODO: Extend to use any type and size here
            img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
            in1 = cv.cvtColor(cv.imread(img_path), cv.COLOR_RGB2GRAY)

            # NB: goodFeaturesToTrack configuration
            max_corners         = 50

            

Reported by Pylint.

TODO: Extend to use any type and size here
Error

Line: 67 Column: 3

              

        def test_rgb2gray(self):
            # TODO: Extend to use any type and size here
            img_path = self.find_file('cv/face/david2.jpg', [os.environ.get('OPENCV_TEST_DATA_PATH')])
            in1 = cv.imread(img_path)

            # OpenCV
            expected = cv.cvtColor(in1, cv.COLOR_RGB2GRAY)

            

Reported by Pylint.

Unused variable 'sz'
Error

Line: 88 Column: 13

              

        def test_bounding_rect(self):
            sz = 1280
            fscale = 256

            def sample_value(fscale):
                return np.random.uniform(0, 255 * fscale) / fscale


            

Reported by Pylint.

Unnecessary pass statement
Error

Line: 123 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.

samples/dnn/common.py
27 issues
Unable to import 'cv2'
Error

Line: 3 Column: 1

              import sys
import os
import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return


            

Reported by Pylint.

Redefining built-in 'type'
Error

Line: 6 Column: 73

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

Redefining built-in 'help'
Error

Line: 6 Column: 37

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import sys
import os
import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 6 Column: 1

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

Too many branches (15/12)
Error

Line: 6 Column: 1

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

Too many arguments (9/5)
Error

Line: 6 Column: 1

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

Line too long (108/100)
Error

Line: 6 Column: 1

              import cv2 as cv


def add_argument(zoo, parser, name, help, required=False, default=None, type=None, action=None, nargs=None):
    if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]


            

Reported by Pylint.

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

Line: 10 Column: 5

                  if len(sys.argv) <= 1:
        return

    modelName = sys.argv[1]

    if os.path.isfile(zoo):
        fs = cv.FileStorage(zoo, cv.FILE_STORAGE_READ)
        node = fs.getNode(modelName)
        if not node.empty():

            

Reported by Pylint.

Too many nested blocks (6/5)
Error

Line: 12 Column: 5

              
    modelName = sys.argv[1]

    if os.path.isfile(zoo):
        fs = cv.FileStorage(zoo, cv.FILE_STORAGE_READ)
        node = fs.getNode(modelName)
        if not node.empty():
            value = node.getNode(name)
            if not value.empty():

            

Reported by Pylint.

samples/python/essential_mat_reconstr.py
27 issues
Unable to import 'cv2'
Error

Line: 1 Column: 1

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

Sequence index is not an int, slice, or instance with __index__
Error

Line: 97 Column: 19

              
    best_cam_idx = np.array([len(obj_pts_per_cam[0]),len(obj_pts_per_cam[1]),
                             len(obj_pts_per_cam[2]),len(obj_pts_per_cam[3])]).argmax()
    max_pts = len(obj_pts_per_cam[best_cam_idx])
    print('Number of object points', max_pts)

    # filter object points to have reasonable depth
    MAX_DEPTH = 6.
    obj_pts = []

            

Reported by Pylint.

Sequence index is not an int, slice, or instance with __index__
Error

Line: 103 Column: 15

                  # filter object points to have reasonable depth
    MAX_DEPTH = 6.
    obj_pts = []
    for pt in obj_pts_per_cam[best_cam_idx]:
        if pt[2] < MAX_DEPTH:
            obj_pts.append(pt)
    obj_pts = np.array(obj_pts).reshape(len(obj_pts), 3)

    # visualize image points

            

Reported by Pylint.

Unused axes3d imported from mpl_toolkits.mplot3d
Error

Line: 2 Column: 1

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

Unused Axes3D imported from mpl_toolkits.mplot3d
Error

Line: 2 Column: 1

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

Redefining name 'inliers' from outer scope (line 64)
Error

Line: 4 Column: 39

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

Redefining name 'pts1' from outer scope (line 53)
Error

Line: 5 Column: 5

              from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)

    return np.median((np.abs(np.sum(pts1 * lines1, axis=0)) / np.sqrt(lines1[0,:]**2 + lines1[1,:]**2) +

            

Reported by Pylint.

Redefining name 'pts2' from outer scope (line 53)
Error

Line: 6 Column: 5

              
def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)

    return np.median((np.abs(np.sum(pts1 * lines1, axis=0)) / np.sqrt(lines1[0,:]**2 + lines1[1,:]**2) +
                      np.abs(np.sum(pts2 * lines2, axis=0)) / np.sqrt(lines2[0,:]**2 + lines2[1,:]**2))/2)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

standard import "import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os" should be placed before "import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os"
Error

Line: 1 Column: 1

              import numpy as np, cv2 as cv, matplotlib.pyplot as plt, time, sys, os
from mpl_toolkits.mplot3d import axes3d, Axes3D

def getEpipolarError(F, pts1_, pts2_, inliers):
    pts1 = np.concatenate((pts1_.T, np.ones((1, pts1_.shape[0]))))[:,inliers]
    pts2 = np.concatenate((pts2_.T, np.ones((1, pts2_.shape[0]))))[:,inliers]
    lines2 = np.dot(F  , pts1)
    lines1 = np.dot(F.T, pts2)


            

Reported by Pylint.

modules/imgproc/misc/java/test/Subdiv2DTest.java
26 issues
This class has too many methods, consider refactoring it.
Design

Line: 9

              import org.opencv.imgproc.Subdiv2D;
import org.opencv.test.OpenCVTestCase;

public class Subdiv2DTest extends OpenCVTestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }


            

Reported by PMD.

Overriding method merely calls super
Design

Line: 11

              
public class Subdiv2DTest extends OpenCVTestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testEdgeDstInt() {
        fail("Not yet implemented");

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 11

              
public class Subdiv2DTest extends OpenCVTestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testEdgeDstInt() {
        fail("Not yet implemented");

            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 11

              
public class Subdiv2DTest extends OpenCVTestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testEdgeDstInt() {
        fail("Not yet implemented");

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 15

                      super.setUp();
    }

    public void testEdgeDstInt() {
        fail("Not yet implemented");
    }

    public void testEdgeDstIntPoint() {
        fail("Not yet implemented");

            

Reported by PMD.

The String literal 'Not yet implemented' appears 20 times in this file; the first occurrence is on line 16
Error

Line: 16

                  }

    public void testEdgeDstInt() {
        fail("Not yet implemented");
    }

    public void testEdgeDstIntPoint() {
        fail("Not yet implemented");
    }

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 19

                      fail("Not yet implemented");
    }

    public void testEdgeDstIntPoint() {
        fail("Not yet implemented");
    }

    public void testEdgeOrgInt() {
        fail("Not yet implemented");

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 23

                      fail("Not yet implemented");
    }

    public void testEdgeOrgInt() {
        fail("Not yet implemented");
    }

    public void testEdgeOrgIntPoint() {
        fail("Not yet implemented");

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 27

                      fail("Not yet implemented");
    }

    public void testEdgeOrgIntPoint() {
        fail("Not yet implemented");
    }

    public void testFindNearestPoint() {
        fail("Not yet implemented");

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 31

                      fail("Not yet implemented");
    }

    public void testFindNearestPoint() {
        fail("Not yet implemented");
    }

    public void testFindNearestPointPoint() {
        fail("Not yet implemented");

            

Reported by PMD.

modules/gapi/scripts/measure_privacy_masking.py
26 issues
Anomalous backslash in string: '\.'. String constant might be missing an r prefix.
Error

Line: 74 Column: 69

                                    , ("--noshow=%s" % fmt_bool(u[1]))    # UI mode (show/no show)
                      ]
                out = str(subprocess.check_output(cmd))
                match = re.search('Processed [0-9]+ frames \(([0-9]+\.[0-9]+) FPS\)', out)
                fps = float(match.group(1))
                print(cmd, fps, "FPS")
                table[m[0],u[0],f,p] = fps

# Write the performance summary

            

Reported by Pylint.

Anomalous backslash in string: '\('. String constant might be missing an r prefix.
Error

Line: 74 Column: 60

                                    , ("--noshow=%s" % fmt_bool(u[1]))    # UI mode (show/no show)
                      ]
                out = str(subprocess.check_output(cmd))
                match = re.search('Processed [0-9]+ frames \(([0-9]+\.[0-9]+) FPS\)', out)
                fps = float(match.group(1))
                print(cmd, fps, "FPS")
                table[m[0],u[0],f,p] = fps

# Write the performance summary

            

Reported by Pylint.

Anomalous backslash in string: '\)'. String constant might be missing an r prefix.
Error

Line: 74 Column: 82

                                    , ("--noshow=%s" % fmt_bool(u[1]))    # UI mode (show/no show)
                      ]
                out = str(subprocess.check_output(cmd))
                match = re.search('Processed [0-9]+ frames \(([0-9]+\.[0-9]+) FPS\)', out)
                fps = float(match.group(1))
                print(cmd, fps, "FPS")
                table[m[0],u[0],f,p] = fps

# Write the performance summary

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python3

import sys
import subprocess
import re
from enum import Enum

## Helper functions ##################################################
##

            

Reported by Pylint.

Consider possible security implications associated with subprocess module.
Security blacklist

Line: 4
Suggestion: https://bandit.readthedocs.io/en/latest/blacklists/blacklist_imports.html#b404-import-subprocess

              #!/usr/bin/env python3

import sys
import subprocess
import re
from enum import Enum

## Helper functions ##################################################
##

            

Reported by Bandit.

Missing function or method docstring
Error

Line: 10 Column: 1

              
## Helper functions ##################################################
##
def fmt_bool(x):
    return ("true" if x else "false")

def fmt_bin(base, prec, model):
    return "%s/%s/%s/%s.xml" % (base, model, prec, model)


            

Reported by Pylint.

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

Line: 10 Column: 1

              
## Helper functions ##################################################
##
def fmt_bool(x):
    return ("true" if x else "false")

def fmt_bin(base, prec, model):
    return "%s/%s/%s/%s.xml" % (base, model, prec, model)


            

Reported by Pylint.

Unnecessary parens after 'return' keyword
Error

Line: 11 Column: 1

              ## Helper functions ##################################################
##
def fmt_bool(x):
    return ("true" if x else "false")

def fmt_bin(base, prec, model):
    return "%s/%s/%s/%s.xml" % (base, model, prec, model)

## The script itself #################################################

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              def fmt_bool(x):
    return ("true" if x else "false")

def fmt_bin(base, prec, model):
    return "%s/%s/%s/%s.xml" % (base, model, prec, model)

## The script itself #################################################
##
if len(sys.argv) != 3:

            

Reported by Pylint.

Consider using sys.exit()
Error

Line: 20 Column: 5

              ##
if len(sys.argv) != 3:
    print("Usage: %s /path/to/input/video /path/to/models" % sys.argv[0])
    exit(1)

input_file_path   = sys.argv[1]
intel_models_path = sys.argv[2]

app             = "bin/example_gapi_privacy_masking_camera"

            

Reported by Pylint.

samples/python/calibrate.py
26 issues
Unable to import 'cv2'
Error

Line: 20 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

# local modules
from common import splitfn

# built-in modules

            

Reported by Pylint.

TODO: use imquery call to retrieve results
Error

Line: 56 Column: 3

              
    obj_points = []
    img_points = []
    h, w = cv.imread(img_names[0], cv.IMREAD_GRAYSCALE).shape[:2]  # TODO: use imquery call to retrieve results

    def processImage(fn):
        print('processing %s... ' % fn)
        img = cv.imread(fn, 0)
        if img is None:

            

Reported by Pylint.

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

Line: 26 Column: 1

              from common import splitfn

# built-in modules
import os

def main():
    import sys
    import getopt
    from glob import glob

            

Reported by Pylint.

Too many local variables (37/15)
Error

Line: 28 Column: 1

              # built-in modules
import os

def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 28 Column: 1

              # built-in modules
import os

def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])

            

Reported by Pylint.

Too many statements (73/50)
Error

Line: 28 Column: 1

              # built-in modules
import os

def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])

            

Reported by Pylint.

Import outside toplevel (sys)
Error

Line: 29 Column: 5

              import os

def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])
    args = dict(args)

            

Reported by Pylint.

Import outside toplevel (getopt)
Error

Line: 30 Column: 5

              
def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])
    args = dict(args)
    args.setdefault('--debug', './output/')

            

Reported by Pylint.

Import outside toplevel (glob.glob)
Error

Line: 31 Column: 5

              def main():
    import sys
    import getopt
    from glob import glob

    args, img_mask = getopt.getopt(sys.argv[1:], '', ['debug=', 'square_size=', 'threads='])
    args = dict(args)
    args.setdefault('--debug', './output/')
    args.setdefault('--square_size', 1.0)

            

Reported by Pylint.

Line too long (111/100)
Error

Line: 56 Column: 1

              
    obj_points = []
    img_points = []
    h, w = cv.imread(img_names[0], cv.IMREAD_GRAYSCALE).shape[:2]  # TODO: use imquery call to retrieve results

    def processImage(fn):
        print('processing %s... ' % fn)
        img = cv.imread(fn, 0)
        if img is None:

            

Reported by Pylint.