The following issues were found

modules/highgui/misc/java/src/java/highgui+ImageWindow.java
19 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 19

                  public final static int WINDOW_NORMAL = 0;
    public final static int WINDOW_AUTOSIZE = 1;

    public String name;
    public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;

            

Reported by PMD.

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

Line: 20

                  public final static int WINDOW_AUTOSIZE = 1;

    public String name;
    public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;

            

Reported by PMD.

Avoid using redundant field initializer for 'img'
Performance

Line: 20

                  public final static int WINDOW_AUTOSIZE = 1;

    public String name;
    public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;

            

Reported by PMD.

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

Line: 21

              
    public String name;
    public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;

            

Reported by PMD.

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

Line: 22

                  public String name;
    public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;

            

Reported by PMD.

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

Line: 23

                  public Mat img = null;
    public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;
    public int x = -1;

            

Reported by PMD.

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

Line: 24

                  public Boolean alreadyUsed = false;
    public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;
    public int x = -1;
    public int y = -1;

            

Reported by PMD.

Avoid using redundant field initializer for 'frame'
Performance

Line: 25

                  public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;
    public int x = -1;
    public int y = -1;
    public int width = -1;

            

Reported by PMD.

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

Line: 25

                  public Boolean imgToBeResized = false;
    public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;
    public int x = -1;
    public int y = -1;
    public int width = -1;

            

Reported by PMD.

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

Line: 26

                  public Boolean windowToBeResized = false;
    public Boolean positionToBeChanged = false;
    public JFrame frame = null;
    public JLabel lbl = null;
    public int flag;
    public int x = -1;
    public int y = -1;
    public int width = -1;
    public int height = -1;

            

Reported by PMD.

samples/dnn/action_recognition.py
19 issues
Unable to import 'cv2'
Error

Line: 3 Column: 1

              import os
import numpy as np
import cv2 as cv
import argparse
from common import findFile

parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')

            

Reported by Pylint.

Unused import os
Error

Line: 1 Column: 1

              import os
import numpy as np
import cv2 as cv
import argparse
from common import findFile

parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os
import numpy as np
import cv2 as cv
import argparse
from common import findFile

parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')

            

Reported by Pylint.

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

Line: 4 Column: 1

              import os
import numpy as np
import cv2 as cv
import argparse
from common import findFile

parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')

            

Reported by Pylint.

Line too long (107/100)
Error

Line: 7 Column: 1

              import argparse
from common import findFile

parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')
parser.add_argument('--model', required=True, help='Path to model.')
parser.add_argument('--classes', default=findFile('action_recongnition_kinetics.txt'), help='Path to classes list.')


            

Reported by Pylint.

Line too long (122/100)
Error

Line: 9 Column: 1

              
parser = argparse.ArgumentParser(description='Use this script to run action recognition using 3D ResNet34',
                                 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')
parser.add_argument('--model', required=True, help='Path to model.')
parser.add_argument('--classes', default=findFile('action_recongnition_kinetics.txt'), help='Path to classes list.')

# To get net download original repository https://github.com/kenshohara/video-classification-3d-cnn-pytorch
# For correct ONNX export modify file: video-classification-3d-cnn-pytorch/models/resnet.py

            

Reported by Pylint.

Line too long (116/100)
Error

Line: 11 Column: 1

                                               formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--input', '-i', help='Path to input video file. Skip this argument to capture frames from a camera.')
parser.add_argument('--model', required=True, help='Path to model.')
parser.add_argument('--classes', default=findFile('action_recongnition_kinetics.txt'), help='Path to classes list.')

# To get net download original repository https://github.com/kenshohara/video-classification-3d-cnn-pytorch
# For correct ONNX export modify file: video-classification-3d-cnn-pytorch/models/resnet.py
# change
# - def downsample_basic_block(x, planes, stride):

            

Reported by Pylint.

Line too long (107/100)
Error

Line: 13 Column: 1

              parser.add_argument('--model', required=True, help='Path to model.')
parser.add_argument('--classes', default=findFile('action_recongnition_kinetics.txt'), help='Path to classes list.')

# To get net download original repository https://github.com/kenshohara/video-classification-3d-cnn-pytorch
# For correct ONNX export modify file: video-classification-3d-cnn-pytorch/models/resnet.py
# change
# - def downsample_basic_block(x, planes, stride):
# -     out = F.avg_pool3d(x, kernel_size=1, stride=stride)
# -     zero_pads = torch.Tensor(out.size(0), planes - out.size(1),

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 35 Column: 1

              
# To ONNX export use torch.onnx.export(model, inputs, model_name)

def get_class_names(path):
    class_names = []
    with open(path) as f:
        for row in f:
            class_names.append(row[:-1])
    return class_names

            

Reported by Pylint.

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

Line: 37 Column: 24

              
def get_class_names(path):
    class_names = []
    with open(path) as f:
        for row in f:
            class_names.append(row[:-1])
    return class_names

def classify_video(video_path, net_path):

            

Reported by Pylint.

samples/dnn/edge_detection.py
18 issues
Unable to import 'cv2'
Error

Line: 1 Column: 1

              import cv2 as cv
import argparse

parser = argparse.ArgumentParser(
        description='This sample shows how to define custom OpenCV deep learning layers in Python. '
                    'Holistically-Nested Edge Detection (https://arxiv.org/abs/1504.06375) neural network '
                    'is used as an example model. Find a pre-trained model at https://github.com/s9xie/hed.')
parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)

            

Reported by Pylint.

Unused argument 'blobs'
Error

Line: 17 Column: 32

              
#! [CropLayer]
class CropLayer(object):
    def __init__(self, params, blobs):
        self.xstart = 0
        self.xend = 0
        self.ystart = 0
        self.yend = 0


            

Reported by Pylint.

Unused argument 'params'
Error

Line: 17 Column: 24

              
#! [CropLayer]
class CropLayer(object):
    def __init__(self, params, blobs):
        self.xstart = 0
        self.xend = 0
        self.ystart = 0
        self.yend = 0


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import cv2 as cv
import argparse

parser = argparse.ArgumentParser(
        description='This sample shows how to define custom OpenCV deep learning layers in Python. '
                    'Holistically-Nested Edge Detection (https://arxiv.org/abs/1504.06375) neural network '
                    'is used as an example model. Find a pre-trained model at https://github.com/s9xie/hed.')
parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)

            

Reported by Pylint.

standard import "import argparse" should be placed before "import cv2 as cv"
Error

Line: 2 Column: 1

              import cv2 as cv
import argparse

parser = argparse.ArgumentParser(
        description='This sample shows how to define custom OpenCV deep learning layers in Python. '
                    'Holistically-Nested Edge Detection (https://arxiv.org/abs/1504.06375) neural network '
                    'is used as an example model. Find a pre-trained model at https://github.com/s9xie/hed.')
parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)

            

Reported by Pylint.

Line too long (107/100)
Error

Line: 6 Column: 1

              
parser = argparse.ArgumentParser(
        description='This sample shows how to define custom OpenCV deep learning layers in Python. '
                    'Holistically-Nested Edge Detection (https://arxiv.org/abs/1504.06375) neural network '
                    'is used as an example model. Find a pre-trained model at https://github.com/s9xie/hed.')
parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)
parser.add_argument('--caffemodel', help='Path to hed_pretrained_bsds.caffemodel', required=True)
parser.add_argument('--width', help='Resize input image to a specific width', default=500, type=int)

            

Reported by Pylint.

Line too long (109/100)
Error

Line: 7 Column: 1

              parser = argparse.ArgumentParser(
        description='This sample shows how to define custom OpenCV deep learning layers in Python. '
                    'Holistically-Nested Edge Detection (https://arxiv.org/abs/1504.06375) neural network '
                    'is used as an example model. Find a pre-trained model at https://github.com/s9xie/hed.')
parser.add_argument('--input', help='Path to image or video. Skip to capture frames from camera')
parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)
parser.add_argument('--caffemodel', help='Path to hed_pretrained_bsds.caffemodel', required=True)
parser.add_argument('--width', help='Resize input image to a specific width', default=500, type=int)
parser.add_argument('--height', help='Resize input image to a specific height', default=500, type=int)

            

Reported by Pylint.

Line too long (102/100)
Error

Line: 12 Column: 1

              parser.add_argument('--prototxt', help='Path to deploy.prototxt', required=True)
parser.add_argument('--caffemodel', help='Path to hed_pretrained_bsds.caffemodel', required=True)
parser.add_argument('--width', help='Resize input image to a specific width', default=500, type=int)
parser.add_argument('--height', help='Resize input image to a specific height', default=500, type=int)
args = parser.parse_args()

#! [CropLayer]
class CropLayer(object):
    def __init__(self, params, blobs):

            

Reported by Pylint.

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

Line: 16 Column: 1

              args = parser.parse_args()

#! [CropLayer]
class CropLayer(object):
    def __init__(self, params, blobs):
        self.xstart = 0
        self.xend = 0
        self.ystart = 0
        self.yend = 0

            

Reported by Pylint.

Missing class docstring
Error

Line: 16 Column: 1

              args = parser.parse_args()

#! [CropLayer]
class CropLayer(object):
    def __init__(self, params, blobs):
        self.xstart = 0
        self.xend = 0
        self.ystart = 0
        self.yend = 0

            

Reported by Pylint.

samples/java/tutorial_code/ImgTrans/HoughLine/HoughLines.java
18 issues
System.out.println is used
Design

Line: 27

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

            

Reported by PMD.

System.out.println is used
Design

Line: 28

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


            

Reported by PMD.

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

Line: 26

                      Mat src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);

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

            

Reported by PMD.

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

Line: 30

                          System.out.println("Error opening image!");
            System.out.println("Program Arguments: [image_name -- default "
                    + default_file +"] \n");
            System.exit(-1);
        }
        //! [load]

        //! [edge_detection]
        // Edge detection

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 56

              
            double a = Math.cos(theta), b = Math.sin(theta);
            double x0 = a*rho, y0 = b*rho;
            Point pt1 = new Point(Math.round(x0 + 1000*(-b)), Math.round(y0 + 1000*(a)));
            Point pt2 = new Point(Math.round(x0 - 1000*(-b)), Math.round(y0 - 1000*(a)));
            Imgproc.line(cdst, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 57

                          double a = Math.cos(theta), b = Math.sin(theta);
            double x0 = a*rho, y0 = b*rho;
            Point pt1 = new Point(Math.round(x0 + 1000*(-b)), Math.round(y0 + 1000*(a)));
            Point pt2 = new Point(Math.round(x0 - 1000*(-b)), Math.round(y0 - 1000*(a)));
            Imgproc.line(cdst, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines]

        //! [hough_lines_p]

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 58

                          double x0 = a*rho, y0 = b*rho;
            Point pt1 = new Point(Math.round(x0 + 1000*(-b)), Math.round(y0 + 1000*(a)));
            Point pt2 = new Point(Math.round(x0 - 1000*(-b)), Math.round(y0 - 1000*(a)));
            Imgproc.line(cdst, pt1, pt2, new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines]

        //! [hough_lines_p]
        // Probabilistic Line Transform

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 71

                      // Draw the lines
        for (int x = 0; x < linesP.rows(); x++) {
            double[] l = linesP.get(x, 0);
            Imgproc.line(cdstP, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines_p]

        //! [imshow]
        // Show results

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 71

                      // Draw the lines
        for (int x = 0; x < linesP.rows(); x++) {
            double[] l = linesP.get(x, 0);
            Imgproc.line(cdstP, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines_p]

        //! [imshow]
        // Show results

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 71

                      // Draw the lines
        for (int x = 0; x < linesP.rows(); x++) {
            double[] l = linesP.get(x, 0);
            Imgproc.line(cdstP, new Point(l[0], l[1]), new Point(l[2], l[3]), new Scalar(0, 0, 255), 3, Imgproc.LINE_AA, 0);
        }
        //! [draw_lines_p]

        //! [imshow]
        // Show results

            

Reported by PMD.

modules/python/test/test_gaussian_mix.py
18 issues
Unable to import 'cv2'
Error

Line: 13 Column: 1

              
import numpy as np
from numpy import random
import cv2 as cv

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []
    for _ in xrange(cluster_n):

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python

# Python 2/3 compatibility
from __future__ import print_function
import sys
PY3 = sys.version_info[0] == 3

if PY3:
    xrange = range

            

Reported by Pylint.

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

Line: 9 Column: 5

              PY3 = sys.version_info[0] == 3

if PY3:
    xrange = range

import numpy as np
from numpy import random
import cv2 as cv


            

Reported by Pylint.

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

Line: 11 Column: 1

              if PY3:
    xrange = range

import numpy as np
from numpy import random
import cv2 as cv

def make_gaussians(cluster_n, img_size):
    points = []

            

Reported by Pylint.

Import "from numpy import random" should be placed at the top of the module
Error

Line: 12 Column: 1

                  xrange = range

import numpy as np
from numpy import random
import cv2 as cv

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []

            

Reported by Pylint.

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

Line: 13 Column: 1

              
import numpy as np
from numpy import random
import cv2 as cv

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []
    for _ in xrange(cluster_n):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 1

              from numpy import random
import cv2 as cv

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []
    for _ in xrange(cluster_n):
        mean = (0.1 + 0.8*random.rand(2)) * img_size
        a = (random.rand(2, 2)-0.5)*img_size*0.1

            

Reported by Pylint.

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

Line: 20 Column: 9

                  ref_distrs = []
    for _ in xrange(cluster_n):
        mean = (0.1 + 0.8*random.rand(2)) * img_size
        a = (random.rand(2, 2)-0.5)*img_size*0.1
        cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
        n = 100 + random.randint(900)
        pts = random.multivariate_normal(mean, cov, n)
        points.append( pts )
        ref_distrs.append( (mean, cov) )

            

Reported by Pylint.

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

Line: 22 Column: 9

                      mean = (0.1 + 0.8*random.rand(2)) * img_size
        a = (random.rand(2, 2)-0.5)*img_size*0.1
        cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
        n = 100 + random.randint(900)
        pts = random.multivariate_normal(mean, cov, n)
        points.append( pts )
        ref_distrs.append( (mean, cov) )
    points = np.float32( np.vstack(points) )
    return points, ref_distrs

            

Reported by Pylint.

Import "from tests_common import NewOpenCVTests" should be placed at the top of the module
Error

Line: 29 Column: 1

                  points = np.float32( np.vstack(points) )
    return points, ref_distrs

from tests_common import NewOpenCVTests

class gaussian_mix_test(NewOpenCVTests):

    def test_gaussian_mix(self):


            

Reported by Pylint.

samples/java/tutorial_code/video/background_subtraction/BackgroundSubtractionDemo.java
18 issues
System.err.println is used
Design

Line: 29

                      //! [capture]
        VideoCapture capture = new VideoCapture(input);
        if (!capture.isOpened()) {
            System.err.println("Unable to open: " + input);
            System.exit(0);
        }
        //! [capture]

        Mat frame = new Mat(), fgMask = new Mat();

            

Reported by PMD.

Ternary operators that can be simplified with || or &&
Design

Line: 15

              class BackgroundSubtraction {
    public void run(String[] args) {
        String input = args.length > 0 ? args[0] : "../data/vtest.avi";
        boolean useMOG2 = args.length > 1 ? args[1] == "MOG2" : true;

        //! [create]
        BackgroundSubtractor backSub;
        if (useMOG2) {
            backSub = Video.createBackgroundSubtractorMOG2();

            

Reported by PMD.

Use equals() to compare object references.
Error

Line: 15

              class BackgroundSubtraction {
    public void run(String[] args) {
        String input = args.length > 0 ? args[0] : "../data/vtest.avi";
        boolean useMOG2 = args.length > 1 ? args[1] == "MOG2" : true;

        //! [create]
        BackgroundSubtractor backSub;
        if (useMOG2) {
            backSub = Video.createBackgroundSubtractorMOG2();

            

Reported by PMD.

Use equals() to compare strings instead of '==' or '!='
Error

Line: 15

              class BackgroundSubtraction {
    public void run(String[] args) {
        String input = args.length > 0 ? args[0] : "../data/vtest.avi";
        boolean useMOG2 = args.length > 1 ? args[1] == "MOG2" : true;

        //! [create]
        BackgroundSubtractor backSub;
        if (useMOG2) {
            backSub = Video.createBackgroundSubtractorMOG2();

            

Reported by PMD.

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

Line: 30

                      VideoCapture capture = new VideoCapture(input);
        if (!capture.isOpened()) {
            System.err.println("Unable to open: " + input);
            System.exit(0);
        }
        //! [capture]

        Mat frame = new Mat(), fgMask = new Mat();
        while (true) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

              
            //! [display_frame_number]
            // get the frame number and write it on the current frame
            Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            //! [display_frame_number]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

              
            //! [display_frame_number]
            // get the frame number and write it on the current frame
            Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            //! [display_frame_number]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 48

              
            //! [display_frame_number]
            // get the frame number and write it on the current frame
            Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            //! [display_frame_number]


            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 50

                          // get the frame number and write it on the current frame
            Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            //! [display_frame_number]

            //! [show]
            // show the current frame and the fg masks

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 51

                          Imgproc.rectangle(frame, new Point(10, 2), new Point(100, 20), new Scalar(255, 255, 255), -1);
            String frameNumberString = String.format("%d", (int)capture.get(Videoio.CAP_PROP_POS_FRAMES));
            Imgproc.putText(frame, frameNumberString, new Point(15, 15), Core.FONT_HERSHEY_SIMPLEX, 0.5,
                    new Scalar(0, 0, 0));
            //! [display_frame_number]

            //! [show]
            // show the current frame and the fg masks
            HighGui.imshow("Frame", frame);

            

Reported by PMD.

samples/java/tutorial_code/highgui/trackbar/AddingImagesTrackbar.java
18 issues
System.out.println is used
Design

Line: 40

                      matImgSrc2 = Imgcodecs.imread(imagePath2);
        //! [load]
        if (matImgSrc1.empty()) {
            System.out.println("Empty image: " + imagePath1);
            System.exit(0);
        }
        if (matImgSrc2.empty()) {
            System.out.println("Empty image: " + imagePath2);
            System.exit(0);

            

Reported by PMD.

System.out.println is used
Design

Line: 44

                          System.exit(0);
        }
        if (matImgSrc2.empty()) {
            System.out.println("Empty image: " + imagePath2);
            System.exit(0);
        }

        //! [window]
        // Create and set up the window.

            

Reported by PMD.

Avoid using redundant field initializer for 'alphaVal'
Performance

Line: 21

              
public class AddingImagesTrackbar {
    private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

            

Reported by PMD.

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

Line: 21

              
public class AddingImagesTrackbar {
    private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

            

Reported by PMD.

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

Line: 22

              public class AddingImagesTrackbar {
    private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;


            

Reported by PMD.

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

Line: 22

              public class AddingImagesTrackbar {
    private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;


            

Reported by PMD.

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

Line: 23

                  private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public AddingImagesTrackbar(String[] args) {

            

Reported by PMD.

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

Line: 23

                  private static final int ALPHA_SLIDER_MAX = 100;
    private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public AddingImagesTrackbar(String[] args) {

            

Reported by PMD.

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

Line: 24

                  private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public AddingImagesTrackbar(String[] args) {
        //! [load]

            

Reported by PMD.

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

Line: 24

                  private int alphaVal = 0;
    private Mat matImgSrc1;
    private Mat matImgSrc2;
    private Mat matImgDst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public AddingImagesTrackbar(String[] args) {
        //! [load]

            

Reported by PMD.

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.

samples/java/tutorial_code/ImgProc/threshold/Threshold.java
18 issues
System.out.println is used
Design

Line: 46

                      // Load an image
        src = Imgcodecs.imread(imagePath);
        if (src.empty()) {
            System.out.println("Empty image: " + imagePath);
            System.exit(0);
        }
        // Convert the image to Gray
        Imgproc.cvtColor(src, srcGray, Imgproc.COLOR_BGR2GRAY);
        //! [load]

            

Reported by PMD.

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

Line: 29

                          + "1: Binary Inverted <br> 2: Truncate <br> "
            + "3: To Zero <br> 4: To Zero Inverted</body></html>";
    private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;

            

Reported by PMD.

Avoid using redundant field initializer for 'thresholdValue'
Performance

Line: 29

                          + "1: Binary Inverted <br> 2: Truncate <br> "
            + "3: To Zero <br> 4: To Zero Inverted</body></html>";
    private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;

            

Reported by PMD.

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

Line: 30

                          + "3: To Zero <br> 4: To Zero Inverted</body></html>";
    private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

            

Reported by PMD.

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

Line: 31

                  private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;


            

Reported by PMD.

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

Line: 31

                  private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;


            

Reported by PMD.

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

Line: 31

                  private static final String TRACKBAR_VALUE = "Value";
    private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;


            

Reported by PMD.

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

Line: 32

                  private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public Threshold(String[] args) {

            

Reported by PMD.

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

Line: 32

                  private int thresholdValue = 0;
    private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public Threshold(String[] args) {

            

Reported by PMD.

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

Line: 33

                  private int thresholdType = 3;
    private Mat src;
    private Mat srcGray = new Mat();
    private Mat dst = new Mat();
    private JFrame frame;
    private JLabel imgLabel;

    public Threshold(String[] args) {
        //! [load]

            

Reported by PMD.

modules/python/test/test_kmeans.py
18 issues
Unable to import 'cv2'
Error

Line: 11 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv
from numpy import random
import sys
PY3 = sys.version_info[0] == 3
if PY3:
    xrange = range

            

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
from numpy import random
import sys
PY3 = sys.version_info[0] == 3
if PY3:
    xrange = range

from tests_common import NewOpenCVTests

            

Reported by Pylint.

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

Line: 16 Column: 5

              import sys
PY3 = sys.version_info[0] == 3
if PY3:
    xrange = range

from tests_common import NewOpenCVTests

def make_gaussians(cluster_n, img_size):
    points = []

            

Reported by Pylint.

Import "from tests_common import NewOpenCVTests" should be placed at the top of the module
Error

Line: 18 Column: 1

              if PY3:
    xrange = range

from tests_common import NewOpenCVTests

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []
    sizes = []

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 20 Column: 1

              
from tests_common import NewOpenCVTests

def make_gaussians(cluster_n, img_size):
    points = []
    ref_distrs = []
    sizes = []
    for _ in xrange(cluster_n):
        mean = (0.1 + 0.8*random.rand(2)) * img_size

            

Reported by Pylint.

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

Line: 26 Column: 9

                  sizes = []
    for _ in xrange(cluster_n):
        mean = (0.1 + 0.8*random.rand(2)) * img_size
        a = (random.rand(2, 2)-0.5)*img_size*0.1
        cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
        n = 100 + random.randint(900)
        pts = random.multivariate_normal(mean, cov, n)
        points.append( pts )
        ref_distrs.append( (mean, cov) )

            

Reported by Pylint.

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

Line: 28 Column: 9

                      mean = (0.1 + 0.8*random.rand(2)) * img_size
        a = (random.rand(2, 2)-0.5)*img_size*0.1
        cov = np.dot(a.T, a) + img_size*0.05*np.eye(2)
        n = 100 + random.randint(900)
        pts = random.multivariate_normal(mean, cov, n)
        points.append( pts )
        ref_distrs.append( (mean, cov) )
        sizes.append(n)
    points = np.float32( np.vstack(points) )

            

Reported by Pylint.

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

Line: 36 Column: 1

                  points = np.float32( np.vstack(points) )
    return points, ref_distrs, sizes

def getMainLabelConfidence(labels, nLabels):

    n = len(labels)
    labelsDict = dict.fromkeys(range(nLabels), 0)
    labelsConfDict = dict.fromkeys(range(nLabels))


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 36 Column: 1

                  points = np.float32( np.vstack(points) )
    return points, ref_distrs, sizes

def getMainLabelConfidence(labels, nLabels):

    n = len(labels)
    labelsDict = dict.fromkeys(range(nLabels), 0)
    labelsConfDict = dict.fromkeys(range(nLabels))


            

Reported by Pylint.

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

Line: 36 Column: 1

                  points = np.float32( np.vstack(points) )
    return points, ref_distrs, sizes

def getMainLabelConfidence(labels, nLabels):

    n = len(labels)
    labelsDict = dict.fromkeys(range(nLabels), 0)
    labelsConfDict = dict.fromkeys(range(nLabels))


            

Reported by Pylint.