The following issues were found

samples/java/tutorial_code/Histograms_Matching/histogram_calculation/CalcHistDemo.java
18 issues
System.err.println is used
Design

Line: 21

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

        //! [Separate the image in 3 places ( B, G and R )]

            

Reported by PMD.

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

Line: 20

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


            

Reported by PMD.

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

Line: 22

                      Mat src = Imgcodecs.imread(filename);
        if (src.empty()) {
            System.err.println("Cannot read image: " + filename);
            System.exit(0);
        }
        //! [Load image]

        //! [Separate the image in 3 places ( B, G and R )]
        List<Mat> bgrPlanes = new ArrayList<>();

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 73

                      rHist.get(0, 0, rHistData);

        for( int i = 1; i < histSize; i++ ) {
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 74

              
        for( int i = 1; i < histSize; i++ ) {
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 74

              
        for( int i = 1; i < histSize; i++ ) {
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 75

                      for( int i = 1; i < histSize; i++ ) {
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }
        //! [Draw for each channel]

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 76

                          Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }
        //! [Draw for each channel]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 76

                          Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(bHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }
        //! [Draw for each channel]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 77

                                  new Point(binW * (i), histH - Math.round(bHistData[i])), new Scalar(255, 0, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(gHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(gHistData[i])), new Scalar(0, 255, 0), 2);
            Imgproc.line(histImage, new Point(binW * (i - 1), histH - Math.round(rHistData[i - 1])),
                    new Point(binW * (i), histH - Math.round(rHistData[i])), new Scalar(0, 0, 255), 2);
        }
        //! [Draw for each channel]

        //! [Display]

            

Reported by PMD.

modules/features2d/misc/java/test/SIFTDescriptorExtractorTest.java
17 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 17

              
public class SIFTDescriptorExtractorTest extends OpenCVTestCase {

    Feature2D extractor;
    KeyPoint keypoint;
    int matSize;
    Mat truth;

    private Mat getTestImg() {

            

Reported by PMD.

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

Line: 18

              public class SIFTDescriptorExtractorTest extends OpenCVTestCase {

    Feature2D extractor;
    KeyPoint keypoint;
    int matSize;
    Mat truth;

    private Mat getTestImg() {
        Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));

            

Reported by PMD.

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

Line: 19

              
    Feature2D extractor;
    KeyPoint keypoint;
    int matSize;
    Mat truth;

    private Mat getTestImg() {
        Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
        Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);

            

Reported by PMD.

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

Line: 20

                  Feature2D extractor;
    KeyPoint keypoint;
    int matSize;
    Mat truth;

    private Mat getTestImg() {
        Mat cross = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
        Imgproc.line(cross, new Point(20, matSize / 2), new Point(matSize - 21, matSize / 2), new Scalar(100), 2);
        Imgproc.line(cross, new Point(matSize / 2, 20), new Point(matSize / 2, matSize - 21), new Scalar(100), 2);

            

Reported by PMD.

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

Line: 30

                      return cross;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        extractor = SIFT.create();
        keypoint = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
        matSize = 100;

            

Reported by PMD.

Double-brace initialization should be avoided
Design

Line: 37

                      keypoint = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
        matSize = 100;
        truth = new Mat(1, 128, CvType.CV_32FC1) {
            {
                put(0, 0,
                          0, 0, 0, 1, 3, 0, 0, 0, 15, 23, 22, 20, 24, 2, 0, 0, 7, 8, 2, 0,
                          0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 16, 13, 2, 0, 0, 117,
                          86, 79, 68, 117, 42, 5, 5, 79, 60, 117, 25, 9, 2, 28, 19, 11, 13,
                          20, 2, 0, 0, 5, 8, 0, 0, 76, 58, 34, 31, 97, 16, 95, 49, 117, 92,

            

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: 51

                      };
    }

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

    public void testComputeMatListOfKeyPointMat() {
        MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint);

            

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: 55

                      fail("Not yet implemented");
    }

    public void testComputeMatListOfKeyPointMat() {
        MatOfKeyPoint keypoints = new MatOfKeyPoint(keypoint);
        Mat img = getTestImg();
        Mat descriptors = new Mat();

        extractor.compute(img, keypoints, descriptors);

            

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: 65

                      assertMatEqual(truth, descriptors, EPS);
    }

    public void testCreate() {
        assertNotNull(extractor);
    }

    public void testDescriptorSize() {
        assertEquals(128, extractor.descriptorSize());

            

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: 69

                      assertNotNull(extractor);
    }

    public void testDescriptorSize() {
        assertEquals(128, extractor.descriptorSize());
    }

    public void testDescriptorType() {
        assertEquals(CvType.CV_32F, extractor.descriptorType());

            

Reported by PMD.

samples/python/browse.py
17 issues
Unable to import 'cv2'
Error

Line: 24 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv

# built-in modules
import sys

def main():

            

Reported by Pylint.

Reimport 'sys' (imported line 17)
Error

Line: 27 Column: 1

              import cv2 as cv

# built-in modules
import sys

def main():
    if len(sys.argv) > 1:
        fn = cv.samples.findFile(sys.argv[1])
        print('loading %s ...' % fn)

            

Reported by Pylint.

Unused argument 'param'
Error

Line: 51 Column: 37

                  for _i in xrange(3):
        small = cv.pyrDown(small)

    def onmouse(event, x, y, flags, param):
        h, _w = img.shape[:2]
        h1, _w1 = small.shape[:2]
        x, y = 1.0*x*h/h1, 1.0*y*h/h1
        zoom = cv.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
        cv.imshow('zoom', zoom)

            

Reported by Pylint.

Unused argument 'flags'
Error

Line: 51 Column: 30

                  for _i in xrange(3):
        small = cv.pyrDown(small)

    def onmouse(event, x, y, flags, param):
        h, _w = img.shape[:2]
        h1, _w1 = small.shape[:2]
        x, y = 1.0*x*h/h1, 1.0*y*h/h1
        zoom = cv.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
        cv.imshow('zoom', zoom)

            

Reported by Pylint.

Unused argument 'event'
Error

Line: 51 Column: 17

                  for _i in xrange(3):
        small = cv.pyrDown(small)

    def onmouse(event, x, y, flags, param):
        h, _w = img.shape[:2]
        h1, _w1 = small.shape[:2]
        x, y = 1.0*x*h/h1, 1.0*y*h/h1
        zoom = cv.getRectSubPix(img, (800, 600), (x+0.5, y+0.5))
        cv.imshow('zoom', zoom)

            

Reported by Pylint.

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

Line: 21 Column: 5

              PY3 = sys.version_info[0] == 3

if PY3:
    xrange = range

import numpy as np
import cv2 as cv

# built-in modules

            

Reported by Pylint.

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

Line: 23 Column: 1

              if PY3:
    xrange = range

import numpy as np
import cv2 as cv

# built-in modules
import sys


            

Reported by Pylint.

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

Line: 24 Column: 1

                  xrange = range

import numpy as np
import cv2 as cv

# built-in modules
import sys

def main():

            

Reported by Pylint.

Import "import sys" should be placed at the top of the module
Error

Line: 27 Column: 1

              import cv2 as cv

# built-in modules
import sys

def main():
    if len(sys.argv) > 1:
        fn = cv.samples.findFile(sys.argv[1])
        print('loading %s ...' % fn)

            

Reported by Pylint.

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

Line: 27 Column: 1

              import cv2 as cv

# built-in modules
import sys

def main():
    if len(sys.argv) > 1:
        fn = cv.samples.findFile(sys.argv[1])
        print('loading %s ...' % fn)

            

Reported by Pylint.

samples/java/tutorial_code/ShapeDescriptors/find_contours/FindContoursDemo.java
17 issues
System.err.println is used
Design

Line: 42

                      String filename = args.length > 0 ? args[0] : "../data/HappyFish.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.

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

Line: 29

              import org.opencv.imgproc.Imgproc;

class FindContours {
    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: 29

              import org.opencv.imgproc.Imgproc;

class FindContours {
    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: 30

              
class FindContours {
    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: 30

              
class FindContours {
    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: 31

              class FindContours {
    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: 31

              class FindContours {
    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: 32

                  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 FindContours(String[] args) {

            

Reported by PMD.

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

Line: 34

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

    public FindContours(String[] args) {
        /// Load source image
        String filename = args.length > 0 ? args[0] : "../data/HappyFish.jpg";

            

Reported by PMD.

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

Line: 35

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

    public FindContours(String[] args) {
        /// Load source image
        String filename = args.length > 0 ? args[0] : "../data/HappyFish.jpg";
        Mat src = Imgcodecs.imread(filename);

            

Reported by PMD.

modules/videoio/misc/java/test/VideoCaptureTest.java
17 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 13

              
public class VideoCaptureTest extends OpenCVTestCase {

    private VideoCapture capture;
    private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {

            

Reported by PMD.

Avoid unused private fields such as 'isOpened'.
Design

Line: 14

              public class VideoCaptureTest extends OpenCVTestCase {

    private VideoCapture capture;
    private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

            

Reported by PMD.

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

Line: 14

              public class VideoCaptureTest extends OpenCVTestCase {

    private VideoCapture capture;
    private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

            

Reported by PMD.

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

Line: 14

              public class VideoCaptureTest extends OpenCVTestCase {

    private VideoCapture capture;
    private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

            

Reported by PMD.

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

Line: 15

              
    private VideoCapture capture;
    private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {
        super.setUp();


            

Reported by PMD.

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

Line: 17

                  private boolean isOpened;
    private boolean isSucceed;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        capture = null;
        isTestCaseEnabled = false;

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 21

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

        capture = null;
        isTestCaseEnabled = false;
        isSucceed = false;
        isOpened = false;
    }


            

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

                      isOpened = false;
    }

    public void testGrab() {
        capture = new VideoCapture();
        isSucceed = capture.grab();
        assertFalse(isSucceed);
    }


            

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: 33

                      assertFalse(isSucceed);
    }

    public void testIsOpened() {
        capture = new VideoCapture();
        assertFalse(capture.isOpened());
    }

    public void testDefaultConstructor() {

            

Reported by PMD.

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

Line: 38

                      assertFalse(capture.isOpened());
    }

    public void testDefaultConstructor() {
        capture = new VideoCapture();
        assertNotNull(capture);
        assertFalse(capture.isOpened());
    }


            

Reported by PMD.

modules/video/misc/python/test/test_tracking.py
17 issues
Unable to import 'cv2'
Error

Line: 4 Column: 1

              #!/usr/bin/env python
import os
import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):


            

Reported by Pylint.

Unable to import 'tests_common'
Error

Line: 6 Column: 1

              import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):

    def test_createTracker(self):
        t = cv.TrackerMIL_create()

            

Reported by Pylint.

Unused import os
Error

Line: 2 Column: 1

              #!/usr/bin/env python
import os
import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):


            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 3 Column: 1

              #!/usr/bin/env python
import os
import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):


            

Reported by Pylint.

Unused unittest imported from tests_common
Error

Line: 6 Column: 1

              import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):

    def test_createTracker(self):
        t = cv.TrackerMIL_create()

            

Reported by Pylint.

Unused variable 't'
Error

Line: 11 Column: 9

              class tracking_test(NewOpenCVTests):

    def test_createTracker(self):
        t = cv.TrackerMIL_create()
        try:
            t = cv.TrackerGOTURN_create()
        except cv.error as e:
            pass  # may fail due to missing DL model files


            

Reported by Pylint.

Unused variable 'e'
Error

Line: 14 Column: 9

                      t = cv.TrackerMIL_create()
        try:
            t = cv.TrackerGOTURN_create()
        except cv.error as e:
            pass  # may fail due to missing DL model files


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

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python
import os
import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):


            

Reported by Pylint.

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

Line: 8 Column: 1

              
from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):

    def test_createTracker(self):
        t = cv.TrackerMIL_create()
        try:
            t = cv.TrackerGOTURN_create()

            

Reported by Pylint.

Missing class docstring
Error

Line: 8 Column: 1

              
from tests_common import NewOpenCVTests, unittest

class tracking_test(NewOpenCVTests):

    def test_createTracker(self):
        t = cv.TrackerMIL_create()
        try:
            t = cv.TrackerGOTURN_create()

            

Reported by Pylint.

samples/java/tutorial_code/features2D/feature_flann_matcher/SURFFLANNMatchingDemo.java
17 issues
System.err.println is used
Design

Line: 24

                      Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.IMREAD_GRAYSCALE);
        Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_GRAYSCALE);
        if (img1.empty() || img2.empty()) {
            System.err.println("Cannot read images!");
            System.exit(0);
        }

        //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
        double hessianThreshold = 400;

            

Reported by PMD.

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

Line: 23

                      String filename2 = args.length > 1 ? args[1] : "../data/box_in_scene.png";
        Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.IMREAD_GRAYSCALE);
        Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_GRAYSCALE);
        if (img1.empty() || img2.empty()) {
            System.err.println("Cannot read images!");
            System.exit(0);
        }

        //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors

            

Reported by PMD.

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

Line: 23

                      String filename2 = args.length > 1 ? args[1] : "../data/box_in_scene.png";
        Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.IMREAD_GRAYSCALE);
        Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_GRAYSCALE);
        if (img1.empty() || img2.empty()) {
            System.err.println("Cannot read images!");
            System.exit(0);
        }

        //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors

            

Reported by PMD.

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

Line: 25

                      Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_GRAYSCALE);
        if (img1.empty() || img2.empty()) {
            System.err.println("Cannot read images!");
            System.exit(0);
        }

        //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
        double hessianThreshold = 400;
        int nOctaves = 4, nOctaveLayers = 3;

            

Reported by PMD.

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

Line: 42

                      // Since SURF is a floating-point descriptor NORM_L2 is used
        DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
        List<MatOfDMatch> knnMatches = new ArrayList<>();
        matcher.knnMatch(descriptors1, descriptors2, knnMatches, 2);

        //-- Filter matches using the Lowe's ratio test
        float ratioThresh = 0.7f;
        List<DMatch> listOfGoodMatches = new ArrayList<>();
        for (int i = 0; i < knnMatches.size(); i++) {

            

Reported by PMD.

This for loop can be replaced by a foreach loop
Design

Line: 47

                      //-- Filter matches using the Lowe's ratio test
        float ratioThresh = 0.7f;
        List<DMatch> listOfGoodMatches = new ArrayList<>();
        for (int i = 0; i < knnMatches.size(); i++) {
            if (knnMatches.get(i).rows() > 1) {
                DMatch[] matches = knnMatches.get(i).toArray();
                if (matches[0].distance < ratioThresh * matches[1].distance) {
                    listOfGoodMatches.add(matches[0]);
                }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 48

                      float ratioThresh = 0.7f;
        List<DMatch> listOfGoodMatches = new ArrayList<>();
        for (int i = 0; i < knnMatches.size(); i++) {
            if (knnMatches.get(i).rows() > 1) {
                DMatch[] matches = knnMatches.get(i).toArray();
                if (matches[0].distance < ratioThresh * matches[1].distance) {
                    listOfGoodMatches.add(matches[0]);
                }
            }

            

Reported by PMD.

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

Line: 48

                      float ratioThresh = 0.7f;
        List<DMatch> listOfGoodMatches = new ArrayList<>();
        for (int i = 0; i < knnMatches.size(); i++) {
            if (knnMatches.get(i).rows() > 1) {
                DMatch[] matches = knnMatches.get(i).toArray();
                if (matches[0].distance < ratioThresh * matches[1].distance) {
                    listOfGoodMatches.add(matches[0]);
                }
            }

            

Reported by PMD.

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

Line: 49

                      List<DMatch> listOfGoodMatches = new ArrayList<>();
        for (int i = 0; i < knnMatches.size(); i++) {
            if (knnMatches.get(i).rows() > 1) {
                DMatch[] matches = knnMatches.get(i).toArray();
                if (matches[0].distance < ratioThresh * matches[1].distance) {
                    listOfGoodMatches.add(matches[0]);
                }
            }
        }

            

Reported by PMD.

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

Line: 67

                      HighGui.imshow("Good Matches", imgMatches);
        HighGui.waitKey(0);

        System.exit(0);
    }
}

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

            

Reported by PMD.

modules/calib3d/misc/python/test/test_calibration.py
17 issues
Unable to import 'cv2'
Error

Line: 12 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests

class calibration_test(NewOpenCVTests):


            

Reported by Pylint.

Unable to import 'tests_common'
Error

Line: 14 Column: 1

              import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests

class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []

            

Reported by Pylint.

Too few public methods (1/2)
Error

Line: 16 Column: 1

              
from tests_common import NewOpenCVTests

class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []
        for i in range(1, 15):
            if i < 10:

            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

              
from tests_common import NewOpenCVTests

class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []
        for i in range(1, 15):
            if i < 10:

            

Reported by Pylint.

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

Line: 16 Column: 1

              
from tests_common import NewOpenCVTests

class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []
        for i in range(1, 15):
            if i < 10:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 18 Column: 5

              
class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []
        for i in range(1, 15):
            if i < 10:
                img_names.append('samples/data/left0{}.jpg'.format(str(i)))
            elif i != 10:

            

Reported by Pylint.

Too many local variables (25/15)
Error

Line: 18 Column: 5

              
class calibration_test(NewOpenCVTests):

    def test_calibration(self):
        img_names = []
        for i in range(1, 15):
            if i < 10:
                img_names.append('samples/data/left0{}.jpg'.format(str(i)))
            elif i != 10:

            

Reported by Pylint.

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

Line: 34 Column: 12

              
        obj_points = []
        img_points = []
        h, w = 0, 0
        for fn in img_names:
            img = self.get_sample(fn, 0)
            if img is None:
                continue


            

Reported by Pylint.

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

Line: 34 Column: 9

              
        obj_points = []
        img_points = []
        h, w = 0, 0
        for fn in img_names:
            img = self.get_sample(fn, 0)
            if img is None:
                continue


            

Reported by Pylint.

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

Line: 35 Column: 13

                      obj_points = []
        img_points = []
        h, w = 0, 0
        for fn in img_names:
            img = self.get_sample(fn, 0)
            if img is None:
                continue

            h, w = img.shape[:2]

            

Reported by Pylint.

samples/java/tutorial_code/video/meanshift/CamshiftDemo.java
17 issues
System.out.println is used
Design

Line: 14

                      String filename = args[0];
        VideoCapture capture = new VideoCapture(filename);
        if (!capture.isOpened()) {
            System.out.println("Unable to open file!");
            System.exit(-1);
        }

        Mat frame = new Mat(), hsv_roi = new Mat(), mask = new Mat(), roi;


            

Reported by PMD.

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

Line: 15

                      VideoCapture capture = new VideoCapture(filename);
        if (!capture.isOpened()) {
            System.out.println("Unable to open file!");
            System.exit(-1);
        }

        Mat frame = new Mat(), hsv_roi = new Mat(), mask = new Mat(), roi;

        // take the first frame of the video

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 42

                      TermCriteria term_crit = new TermCriteria(TermCriteria.EPS | TermCriteria.COUNT, 10, 1);

        while (true) {
            Mat hsv = new Mat() , dst = new Mat();
            capture.read(frame);
            if (frame.empty()) {
                break;
            }
            Imgproc.cvtColor(frame, hsv, Imgproc.COLOR_BGR2HSV);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 42

                      TermCriteria term_crit = new TermCriteria(TermCriteria.EPS | TermCriteria.COUNT, 10, 1);

        while (true) {
            Mat hsv = new Mat() , dst = new Mat();
            capture.read(frame);
            if (frame.empty()) {
                break;
            }
            Imgproc.cvtColor(frame, hsv, Imgproc.COLOR_BGR2HSV);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 54

                          RotatedRect rot_rect = Video.CamShift(dst, track_window, term_crit);

            // Draw it on image
            Point[] points = new Point[4];
            rot_rect.points(points);
            for (int i = 0; i < 4 ;i++) {
                Imgproc.line(frame, points[i], points[(i+1)%4], new Scalar(255, 0, 0),2);
            }


            

Reported by PMD.

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

Line: 55

              
            // Draw it on image
            Point[] points = new Point[4];
            rot_rect.points(points);
            for (int i = 0; i < 4 ;i++) {
                Imgproc.line(frame, points[i], points[(i+1)%4], new Scalar(255, 0, 0),2);
            }

            HighGui.imshow("img2", frame);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 57

                          Point[] points = new Point[4];
            rot_rect.points(points);
            for (int i = 0; i < 4 ;i++) {
                Imgproc.line(frame, points[i], points[(i+1)%4], new Scalar(255, 0, 0),2);
            }

            HighGui.imshow("img2", frame);
            int keyboard = HighGui.waitKey(30);
            if (keyboard == 'q'|| keyboard == 27) {

            

Reported by PMD.

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

Line: 66

                              break;
            }
        }
        System.exit(0);
    }
}

public class CamshiftDemo {
    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: 70

                  }
}

public class CamshiftDemo {
    public static void main(String[] args) {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        new Camshift().run(args);
    }
}

            

Reported by PMD.

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

Line: 2

              import java.util.Arrays;
import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgproc.Imgproc;
import org.opencv.video.Video;
import org.opencv.videoio.VideoCapture;


class Camshift {

            

Reported by PMD.

modules/core/misc/java/test/KeyPointTest.java
17 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 9

              
public class KeyPointTest extends OpenCVTestCase {

    private float angle;
    private int classId;
    private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;

            

Reported by PMD.

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

Line: 10

              public class KeyPointTest extends OpenCVTestCase {

    private float angle;
    private int classId;
    private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;
    private float x;

            

Reported by PMD.

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

Line: 11

              
    private float angle;
    private int classId;
    private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;
    private float x;
    private float y;

            

Reported by PMD.

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

Line: 12

                  private float angle;
    private int classId;
    private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;
    private float x;
    private float y;


            

Reported by PMD.

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

Line: 13

                  private int classId;
    private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;
    private float x;
    private float y;

    @Override

            

Reported by PMD.

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

Line: 14

                  private KeyPoint keyPoint;
    private int octave;
    private float response;
    private float size;
    private float x;
    private float y;

    @Override
    protected void setUp() throws Exception {

            

Reported by PMD.

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

Line: 15

                  private int octave;
    private float response;
    private float size;
    private float x;
    private float y;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

            

Reported by PMD.

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

Line: 16

                  private float response;
    private float size;
    private float x;
    private float y;

    @Override
    protected void setUp() throws Exception {
        super.setUp();


            

Reported by PMD.

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

Line: 18

                  private float x;
    private float y;

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        keyPoint = null;
        x = 1.0f;

            

Reported by PMD.

Assigning an Object to null is a code smell. Consider refactoring.
Error

Line: 22

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

        keyPoint = null;
        x = 1.0f;
        y = 2.0f;
        size = 3.0f;
        angle = 30.0f;
        response = 2.0f;

            

Reported by PMD.