The following issues were found

samples/java/tutorial_code/core/discrete_fourier_transform/DiscreteFourierTransform.java
15 issues
System.out.println is used
Design

Line: 10

              
class DiscreteFourierTransformRun{
    private void help() {
        System.out.println("" +
                "This program demonstrated the use of the discrete Fourier transform (DFT). \n" +
                "The dft of an image is taken and it's power spectrum is displayed.\n" +
                "Usage:\n" +
                "./DiscreteFourierTransform [image_name -- default ../data/lena.jpg]");
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 25

              
        Mat I = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
        if( I.empty() ) {
            System.out.println("Error opening image");
            System.exit(-1);
        }

        //! [expand]
        Mat padded = new Mat();                     //expand input image to optimal size

            

Reported by PMD.

Do not add empty strings
Performance

Line: 10

              
class DiscreteFourierTransformRun{
    private void help() {
        System.out.println("" +
                "This program demonstrated the use of the discrete Fourier transform (DFT). \n" +
                "The dft of an image is taken and it's power spectrum is displayed.\n" +
                "Usage:\n" +
                "./DiscreteFourierTransform [image_name -- default ../data/lena.jpg]");
    }

            

Reported by PMD.

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

Line: 24

                      String filename = ((args.length > 0) ? args[0] : "../data/lena.jpg");

        Mat I = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
        if( I.empty() ) {
            System.out.println("Error opening image");
            System.exit(-1);
        }

        //! [expand]

            

Reported by PMD.

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

Line: 26

                      Mat I = Imgcodecs.imread(filename, Imgcodecs.IMREAD_GRAYSCALE);
        if( I.empty() ) {
            System.out.println("Error opening image");
            System.exit(-1);
        }

        //! [expand]
        Mat padded = new Mat();                     //expand input image to optimal size
        int m = Core.getOptimalDFTSize( I.rows() );

            

Reported by PMD.

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

Line: 31

              
        //! [expand]
        Mat padded = new Mat();                     //expand input image to optimal size
        int m = Core.getOptimalDFTSize( I.rows() );
        int n = Core.getOptimalDFTSize( I.cols() ); // on the border add zero values
        Core.copyMakeBorder(I, padded, 0, m - I.rows(), 0, n - I.cols(), Core.BORDER_CONSTANT, Scalar.all(0));
        //! [expand]

        //! [complex_and_real]

            

Reported by PMD.

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

Line: 32

                      //! [expand]
        Mat padded = new Mat();                     //expand input image to optimal size
        int m = Core.getOptimalDFTSize( I.rows() );
        int n = Core.getOptimalDFTSize( I.cols() ); // on the border add zero values
        Core.copyMakeBorder(I, padded, 0, m - I.rows(), 0, n - I.cols(), Core.BORDER_CONSTANT, Scalar.all(0));
        //! [expand]

        //! [complex_and_real]
        List<Mat> planes = new ArrayList<Mat>();

            

Reported by PMD.

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

Line: 33

                      Mat padded = new Mat();                     //expand input image to optimal size
        int m = Core.getOptimalDFTSize( I.rows() );
        int n = Core.getOptimalDFTSize( I.cols() ); // on the border add zero values
        Core.copyMakeBorder(I, padded, 0, m - I.rows(), 0, n - I.cols(), Core.BORDER_CONSTANT, Scalar.all(0));
        //! [expand]

        //! [complex_and_real]
        List<Mat> planes = new ArrayList<Mat>();
        padded.convertTo(padded, CvType.CV_32F);

            

Reported by PMD.

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

Line: 33

                      Mat padded = new Mat();                     //expand input image to optimal size
        int m = Core.getOptimalDFTSize( I.rows() );
        int n = Core.getOptimalDFTSize( I.cols() ); // on the border add zero values
        Core.copyMakeBorder(I, padded, 0, m - I.rows(), 0, n - I.cols(), Core.BORDER_CONSTANT, Scalar.all(0));
        //! [expand]

        //! [complex_and_real]
        List<Mat> planes = new ArrayList<Mat>();
        padded.convertTo(padded, CvType.CV_32F);

            

Reported by PMD.

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

Line: 59

                      //! [magnitude]

        //! [log]
        Mat matOfOnes = Mat.ones(magI.size(), magI.type());
        Core.add(matOfOnes, magI, magI);         // switch to logarithmic scale
        Core.log(magI, magI);
        //! [log]

        //! [crop_rearrange]

            

Reported by PMD.

samples/dnn/dnn_model_runner/dnn_conversion/tf/classification/py_to_py_mobilenet.py
14 issues
Unable to import 'cv2'
Error

Line: 3 Column: 1

              import os

import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env

            

Reported by Pylint.

Unable to import 'tensorflow'
Error

Line: 5 Column: 1

              
import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env


            

Reported by Pylint.

Unable to import 'tensorflow.keras.applications'
Error

Line: 6 Column: 1

              import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env



            

Reported by Pylint.

Unable to import 'tensorflow.python.framework.convert_to_constants'
Error

Line: 7 Column: 1

              import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env


def get_tf_model_proto(tf_model):

            

Reported by Pylint.

Attempted relative import beyond top-level package
Error

Line: 9 Column: 1

              from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env


def get_tf_model_proto(tf_model):
    # define the directory for .pb model
    pb_model_path = "models"

            

Reported by Pylint.

Lambda may not be necessary
Error

Line: 23 Column: 34

                  os.makedirs(pb_model_path, exist_ok=True)

    # get model TF graph
    tf_model_graph = tf.function(lambda x: tf_model(x))

    # get concrete function
    tf_model_graph = tf_model_graph.get_concrete_function(
        tf.TensorSpec(tf_model.inputs[0].shape, tf_model.inputs[0].dtype))


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os

import cv2
import numpy as np
import tensorflow as tf
from tensorflow.keras.applications import MobileNet
from tensorflow.python.framework.convert_to_constants import convert_variables_to_constants_v2

from ...common.utils import set_tf_env

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 12 Column: 1

              from ...common.utils import set_tf_env


def get_tf_model_proto(tf_model):
    # define the directory for .pb model
    pb_model_path = "models"

    # define the name of .pb model
    pb_model_name = "mobilenet.pb"

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 43 Column: 1

                  return os.path.join(pb_model_path, pb_model_name)


def get_preprocessed_img(img_path):
    # read the image
    input_img = cv2.imread(img_path, cv2.IMREAD_COLOR)
    input_img = input_img.astype(np.float32)

    # define preprocess parameters

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 68 Column: 1

                  return input_blob


def get_imagenet_labels(labels_path):
    with open(labels_path) as f:
        imagenet_labels = [line.strip() for line in f.readlines()]
    return imagenet_labels



            

Reported by Pylint.

samples/java/tutorial_code/ml/introduction_to_pca/IntroductionToPCADemo.java
14 issues
System.err.println is used
Design

Line: 94

              
        // Check if image is loaded successfully
        if (src.empty()) {
            System.err.println("Cannot read image: " + filename);
            System.exit(0);
        }

        Mat srcOriginal = src.clone();
        HighGui.imshow("src", srcOriginal);

            

Reported by PMD.

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

Line: 43

                      List<Point> pts = ptsMat.toList();
        //! [pca]
        // Construct a buffer used by the pca analysis
        int sz = pts.size();
        Mat dataPts = new Mat(sz, 2, CvType.CV_64F);
        double[] dataPtsData = new double[(int) (dataPts.total() * dataPts.channels())];
        for (int i = 0; i < dataPts.rows(); i++) {
            dataPtsData[i * dataPts.cols()] = pts.get(i).x;
            dataPtsData[i * dataPts.cols() + 1] = pts.get(i).y;

            

Reported by PMD.

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

Line: 47

                      Mat dataPts = new Mat(sz, 2, CvType.CV_64F);
        double[] dataPtsData = new double[(int) (dataPts.total() * dataPts.channels())];
        for (int i = 0; i < dataPts.rows(); i++) {
            dataPtsData[i * dataPts.cols()] = pts.get(i).x;
            dataPtsData[i * dataPts.cols() + 1] = pts.get(i).y;
        }
        dataPts.put(0, 0, dataPtsData);

        // Perform PCA analysis

            

Reported by PMD.

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

Line: 48

                      double[] dataPtsData = new double[(int) (dataPts.total() * dataPts.channels())];
        for (int i = 0; i < dataPts.rows(); i++) {
            dataPtsData[i * dataPts.cols()] = pts.get(i).x;
            dataPtsData[i * dataPts.cols() + 1] = pts.get(i).y;
        }
        dataPts.put(0, 0, dataPtsData);

        // Perform PCA analysis
        Mat mean = new Mat();

            

Reported by PMD.

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

Line: 93

                      Mat src = Imgcodecs.imread(filename);

        // Check if image is loaded successfully
        if (src.empty()) {
            System.err.println("Cannot read image: " + filename);
            System.exit(0);
        }

        Mat srcOriginal = src.clone();

            

Reported by PMD.

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

Line: 95

                      // Check if image is loaded successfully
        if (src.empty()) {
            System.err.println("Cannot read image: " + filename);
            System.exit(0);
        }

        Mat srcOriginal = src.clone();
        HighGui.imshow("src", srcOriginal);


            

Reported by PMD.

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

Line: 98

                          System.exit(0);
        }

        Mat srcOriginal = src.clone();
        HighGui.imshow("src", srcOriginal);

        // Convert image to grayscale
        Mat gray = new Mat();
        Imgproc.cvtColor(src, gray, Imgproc.COLOR_BGR2GRAY);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 124

                              continue;

            // Draw each contour only for visualisation purposes
            Imgproc.drawContours(src, contours, i, new Scalar(0, 0, 255), 2);
            // Find the orientation of each shape
            getOrientation(contours.get(i), src);
        }
        //! [contours]


            

Reported by PMD.

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

Line: 133

                      HighGui.imshow("output", src);

        HighGui.waitKey();
        System.exit(0);
    }
}

public class IntroductionToPCADemo {
    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: 137

                  }
}

public class IntroductionToPCADemo {
    public static void main(String[] args) {
        // Load the native OpenCV library
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        new IntroductionToPCA().run(args);

            

Reported by PMD.

samples/dnn/dnn_model_runner/dnn_conversion/common/evaluation/classification/cls_accuracy_evaluator.py
14 issues
Attempted relative import beyond top-level package
Error

Line: 6 Column: 1

              
import numpy as np

from ...utils import get_final_summary_info


class ClsAccEvaluation:
    log = sys.stdout
    img_classes = {}

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import sys
import time

import numpy as np

from ...utils import get_final_summary_info


class ClsAccEvaluation:

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from ...utils import get_final_summary_info


class ClsAccEvaluation:
    log = sys.stdout
    img_classes = {}
    batch_size = 0

    def __init__(self, log_path, img_classes_file, batch_size):

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 24 Column: 5

                      self.general_inference_time = []

    @staticmethod
    def read_classes(img_classes_file):
        result = {}
        with open(img_classes_file) as file:
            for l in file.readlines():
                result[l.split()[0]] = int(l.split()[1])
        return result

            

Reported by Pylint.

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

Line: 27 Column: 17

                  def read_classes(img_classes_file):
        result = {}
        with open(img_classes_file) as file:
            for l in file.readlines():
                result[l.split()[0]] = int(l.split()[1])
        return result

    def get_correct_answers(self, img_list, net_output_blob):
        correct_answers = 0

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 31 Column: 5

                              result[l.split()[0]] = int(l.split()[1])
        return result

    def get_correct_answers(self, img_list, net_output_blob):
        correct_answers = 0
        for i in range(len(img_list)):
            indexes = np.argsort(net_output_blob[i])[-5:]
            correct_index = self.img_classes[img_list[i]]
            if correct_index in indexes:

            

Reported by Pylint.

Consider using enumerate instead of iterating with range and len
Error

Line: 33 Column: 9

              
    def get_correct_answers(self, img_list, net_output_blob):
        correct_answers = 0
        for i in range(len(img_list)):
            indexes = np.argsort(net_output_blob[i])[-5:]
            correct_index = self.img_classes[img_list[i]]
            if correct_index in indexes:
                correct_answers += 1
        return correct_answers

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 40 Column: 5

                              correct_answers += 1
        return correct_answers

    def process(self, frameworks, data_fetcher):
        sorted_imgs_names = sorted(self.img_classes.keys())
        correct_answers = [0] * len(frameworks)
        samples_handled = 0
        blobs_l1_diff = [0] * len(frameworks)
        blobs_l1_diff_count = [0] * len(frameworks)

            

Reported by Pylint.

Too many local variables (23/15)
Error

Line: 40 Column: 5

                              correct_answers += 1
        return correct_answers

    def process(self, frameworks, data_fetcher):
        sorted_imgs_names = sorted(self.img_classes.keys())
        correct_answers = [0] * len(frameworks)
        samples_handled = 0
        blobs_l1_diff = [0] * len(frameworks)
        blobs_l1_diff_count = [0] * len(frameworks)

            

Reported by Pylint.

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

Line: 49 Column: 13

                      blobs_l_inf_diff = [sys.float_info.min] * len(frameworks)
        inference_time = [0.0] * len(frameworks)

        for x in range(0, len(sorted_imgs_names), self.batch_size):
            sublist = sorted_imgs_names[x:x + self.batch_size]
            batch = data_fetcher.get_batch(sublist)

            samples_handled += len(sublist)
            fw_accuracy = []

            

Reported by Pylint.

samples/python/tutorial_code/imgProc/threshold/threshold.py
14 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              from __future__ import print_function
import cv2 as cv
import argparse

max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'

            

Reported by Pylint.

Unused argument 'val'
Error

Line: 13 Column: 20

              window_name = 'Threshold Demo'

## [Threshold_Demo]
def Threshold_Demo(val):
    #0: Binary
    #1: Binary Inverted
    #2: Threshold Truncated
    #3: Threshold to Zero
    #4: Threshold to Zero Inverted

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import print_function
import cv2 as cv
import argparse

max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'

            

Reported by Pylint.

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

Line: 3 Column: 1

              from __future__ import print_function
import cv2 as cv
import argparse

max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'

            

Reported by Pylint.

Constant name "max_value" doesn't conform to UPPER_CASE naming style
Error

Line: 5 Column: 1

              import cv2 as cv
import argparse

max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'

            

Reported by Pylint.

Constant name "max_type" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              import argparse

max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'


            

Reported by Pylint.

Constant name "max_binary_value" doesn't conform to UPPER_CASE naming style
Error

Line: 7 Column: 1

              
max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'

## [Threshold_Demo]

            

Reported by Pylint.

Line too long (110/100)
Error

Line: 8 Column: 1

              max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'

## [Threshold_Demo]
def Threshold_Demo(val):

            

Reported by Pylint.

Constant name "trackbar_type" doesn't conform to UPPER_CASE naming style
Error

Line: 8 Column: 1

              max_value = 255
max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'

## [Threshold_Demo]
def Threshold_Demo(val):

            

Reported by Pylint.

Constant name "trackbar_value" doesn't conform to UPPER_CASE naming style
Error

Line: 9 Column: 1

              max_type = 4
max_binary_value = 255
trackbar_type = 'Type: \n 0: Binary \n 1: Binary Inverted \n 2: Truncate \n 3: To Zero \n 4: To Zero Inverted'
trackbar_value = 'Value'
window_name = 'Threshold Demo'

## [Threshold_Demo]
def Threshold_Demo(val):
    #0: Binary

            

Reported by Pylint.

samples/android/tutorial-2-mixedprocessing/src/org/opencv/samples/tutorial2/Tutorial2Activity.java
14 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 31

                  private static final int       VIEW_MODE_CANNY    = 2;
    private static final int       VIEW_MODE_FEATURES = 5;

    private int                    mViewMode;
    private Mat                    mRgba;
    private Mat                    mIntermediateMat;
    private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;

            

Reported by PMD.

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

Line: 32

                  private static final int       VIEW_MODE_FEATURES = 5;

    private int                    mViewMode;
    private Mat                    mRgba;
    private Mat                    mIntermediateMat;
    private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;

            

Reported by PMD.

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

Line: 33

              
    private int                    mViewMode;
    private Mat                    mRgba;
    private Mat                    mIntermediateMat;
    private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;

            

Reported by PMD.

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

Line: 34

                  private int                    mViewMode;
    private Mat                    mRgba;
    private Mat                    mIntermediateMat;
    private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

            

Reported by PMD.

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

Line: 36

                  private Mat                    mIntermediateMat;
    private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

    private CameraBridgeViewBase   mOpenCvCameraView;

            

Reported by PMD.

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

Line: 37

                  private Mat                    mGray;

    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

    private CameraBridgeViewBase   mOpenCvCameraView;


            

Reported by PMD.

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

Line: 38

              
    private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

    private CameraBridgeViewBase   mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {

            

Reported by PMD.

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

Line: 39

                  private MenuItem               mItemPreviewRGBA;
    private MenuItem               mItemPreviewGray;
    private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

    private CameraBridgeViewBase   mOpenCvCameraView;

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

            

Reported by PMD.

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

Line: 41

                  private MenuItem               mItemPreviewCanny;
    private MenuItem               mItemPreviewFeatures;

    private CameraBridgeViewBase   mOpenCvCameraView;

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

            

Reported by PMD.

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

Line: 43

              
    private CameraBridgeViewBase   mOpenCvCameraView;

    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                {

            

Reported by PMD.

samples/java/tutorial_code/Histograms_Matching/histogram_comparison/CompareHistDemo.java
14 issues
System.err.println is used
Design

Line: 16

                  public void run(String[] args) {
        //! [Load three images with different environment settings]
        if (args.length != 3) {
            System.err.println("You must supply 3 arguments that correspond to the paths to 3 images.");
            System.exit(0);
        }
        Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);

            

Reported by PMD.

System.err.println is used
Design

Line: 23

                      Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {
            System.err.println("Cannot read the images");
            System.exit(0);
        }
        //! [Load three images with different environment settings]

        //! [Convert to HSV]

            

Reported by PMD.

System.out.println is used
Design

Line: 77

                          double baseTest1 = Imgproc.compareHist( histBase, histTest1, compareMethod );
            double baseTest2 = Imgproc.compareHist( histBase, histTest2, compareMethod );

            System.out.println("Method " + compareMethod + " Perfect, Base-Half, Base-Test(1), Base-Test(2) : " + baseBase + " / " + baseHalf
                    + " / " + baseTest1 + " / " + baseTest2);
        }
        //! [Apply the histogram comparison methods]
    }
}

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 15

              class CompareHist {
    public void run(String[] args) {
        //! [Load three images with different environment settings]
        if (args.length != 3) {
            System.err.println("You must supply 3 arguments that correspond to the paths to 3 images.");
            System.exit(0);
        }
        Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);

            

Reported by PMD.

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

Line: 17

                      //! [Load three images with different environment settings]
        if (args.length != 3) {
            System.err.println("You must supply 3 arguments that correspond to the paths to 3 images.");
            System.exit(0);
        }
        Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {

            

Reported by PMD.

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

Line: 22

                      Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {
            System.err.println("Cannot read the images");
            System.exit(0);
        }
        //! [Load three images with different environment settings]


            

Reported by PMD.

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

Line: 22

                      Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {
            System.err.println("Cannot read the images");
            System.exit(0);
        }
        //! [Load three images with different environment settings]


            

Reported by PMD.

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

Line: 22

                      Mat srcBase = Imgcodecs.imread(args[0]);
        Mat srcTest1 = Imgcodecs.imread(args[1]);
        Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {
            System.err.println("Cannot read the images");
            System.exit(0);
        }
        //! [Load three images with different environment settings]


            

Reported by PMD.

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

Line: 24

                      Mat srcTest2 = Imgcodecs.imread(args[2]);
        if (srcBase.empty() || srcTest1.empty() || srcTest2.empty()) {
            System.err.println("Cannot read the images");
            System.exit(0);
        }
        //! [Load three images with different environment settings]

        //! [Convert to HSV]
        Mat hsvBase = new Mat(), hsvTest1 = new Mat(), hsvTest2 = new Mat();

            

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

                  }
}

public class CompareHistDemo {
    public static void main(String[] args) {
        // Load the native OpenCV library
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        new CompareHist().run(args);

            

Reported by PMD.

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

Line: 18

              
public class STARFeatureDetectorTest extends OpenCVTestCase {

    Feature2D detector;
    int matSize;
    KeyPoint[] truth;

    private Mat getMaskImg() {
        Mat mask = 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

              public class STARFeatureDetectorTest extends OpenCVTestCase {

    Feature2D detector;
    int matSize;
    KeyPoint[] truth;

    private Mat getMaskImg() {
        Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
        Mat right = mask.submat(0, matSize, matSize / 2, matSize);

            

Reported by PMD.

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

Line: 20

              
    Feature2D detector;
    int matSize;
    KeyPoint[] truth;

    private Mat getMaskImg() {
        Mat mask = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
        Mat right = mask.submat(0, matSize, matSize / 2, matSize);
        right.setTo(new Scalar(0));

            

Reported by PMD.

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

Line: 44

                      return img;
    }

    protected void setUp() throws Exception {
        super.setUp();
        detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null);
        matSize = 200;
        truth = new KeyPoint[] {
                new KeyPoint( 95,  80, 22, -1, 31.5957f, 0, -1),

            

Reported by PMD.

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

Line: 44

                      return img;
    }

    protected void setUp() throws Exception {
        super.setUp();
        detector = createClassInstance(XFEATURES2D+"StarDetector", DEFAULT_FACTORY, null, null);
        matSize = 200;
        truth = new KeyPoint[] {
                new KeyPoint( 95,  80, 22, -1, 31.5957f, 0, -1),

            

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

                          };
    }

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

    public void testDetectListOfMatListOfListOfKeyPoint() {
        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: 65

                      assertNotNull(detector);
    }

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

    public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
        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: 69

                      fail("Not yet implemented");
    }

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

    public void testDetectMatListOfKeyPoint() {
        Mat img = getTestImg();

            

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

                      fail("Not yet implemented");
    }

    public void testDetectMatListOfKeyPoint() {
        Mat img = getTestImg();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();

        detector.detect(img, keypoints);


            

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

                      assertListKeyPointEquals(Arrays.asList(truth), keypoints.toList(), EPS);
    }

    public void testDetectMatListOfKeyPointMat() {
        Mat img = getTestImg();
        Mat mask = getMaskImg();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();

        detector.detect(img, keypoints, mask);

            

Reported by PMD.

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

Line: 20

              
public class FASTFeatureDetectorTest extends OpenCVTestCase {

    Feature2D detector;
    KeyPoint[] truth;

    private Mat getMaskImg() {
        Mat mask = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
        Mat right = mask.submat(0, 100, 50, 100);

            

Reported by PMD.

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

Line: 21

              public class FASTFeatureDetectorTest extends OpenCVTestCase {

    Feature2D detector;
    KeyPoint[] truth;

    private Mat getMaskImg() {
        Mat mask = new Mat(100, 100, CvType.CV_8U, new Scalar(255));
        Mat right = mask.submat(0, 100, 50, 100);
        right.setTo(new Scalar(0));

            

Reported by PMD.

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

Line: 36

                      return img;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        detector = FastFeatureDetector.create();
        truth = new KeyPoint[] { new KeyPoint(32, 27, 7, -1, 254, 0, -1), new KeyPoint(27, 32, 7, -1, 254, 0, -1), new KeyPoint(73, 68, 7, -1, 254, 0, -1),
                new KeyPoint(68, 73, 7, -1, 254, 0, -1) };

            

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

                              new KeyPoint(68, 73, 7, -1, 254, 0, -1) };
    }

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

    public void testDetectListOfMatListOfListOfKeyPoint() {
        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: 48

                      assertNotNull(detector);
    }

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

    public void testDetectListOfMatListOfListOfKeyPointListOfMat() {
        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: 52

                      fail("Not yet implemented");
    }

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

    public void testDetectMatListOfKeyPoint() {
        Mat img = getTestImg();

            

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

                      fail("Not yet implemented");
    }

    public void testDetectMatListOfKeyPoint() {
        Mat img = getTestImg();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();

        detector.detect(img, keypoints);


            

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

                      // OpenCVTestRunner.Log(kp.toString());
    }

    public void testDetectMatListOfKeyPointMat() {
        Mat img = getTestImg();
        Mat mask = getMaskImg();
        MatOfKeyPoint keypoints = new MatOfKeyPoint();

        detector.detect(img, keypoints, mask);

            

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

                      assertListKeyPointEquals(Arrays.asList(truth[0], truth[1]), keypoints.toList(), EPS);
    }

    public void testEmpty() {
//        assertFalse(detector.empty());
        fail("Not yet implemented"); //FAST does not override empty() method
    }

    public void testRead() {

            

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

                      fail("Not yet implemented"); //FAST does not override empty() method
    }

    public void testRead() {
        String filename = OpenCVTestRunner.getTempFileName("yml");

        writeFile(filename, "%YAML:1.0\n---\nthreshold: 130\nnonmaxSuppression: 1\n");
        detector.read(filename);


            

Reported by PMD.

samples/python/tutorial_code/TrackingMotion/harris_detector/cornerHarris_Demo.py
14 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255


            

Reported by Pylint.

Redefining name 'thresh' from outer scope (line 50)
Error

Line: 11 Column: 5

              max_thresh = 255

def cornerHarris_demo(val):
    thresh = val

    # Detector parameters
    blockSize = 2
    apertureSize = 3
    k = 0.04

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255


            

Reported by Pylint.

Module name "cornerHarris_Demo" doesn't conform to snake_case naming style
Error

Line: 1 Column: 1

              from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255


            

Reported by Pylint.

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

Line: 4 Column: 1

              from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255


            

Reported by Pylint.

Constant name "source_window" doesn't conform to UPPER_CASE naming style
Error

Line: 6 Column: 1

              import numpy as np
import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255

def cornerHarris_demo(val):
    thresh = val

            

Reported by Pylint.

Constant name "corners_window" doesn't conform to UPPER_CASE naming style
Error

Line: 7 Column: 1

              import argparse

source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255

def cornerHarris_demo(val):
    thresh = val


            

Reported by Pylint.

Constant name "max_thresh" doesn't conform to UPPER_CASE naming style
Error

Line: 8 Column: 1

              
source_window = 'Source image'
corners_window = 'Corners detected'
max_thresh = 255

def cornerHarris_demo(val):
    thresh = val

    # Detector parameters

            

Reported by Pylint.

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

Line: 10 Column: 1

              corners_window = 'Corners detected'
max_thresh = 255

def cornerHarris_demo(val):
    thresh = val

    # Detector parameters
    blockSize = 2
    apertureSize = 3

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 1

              corners_window = 'Corners detected'
max_thresh = 255

def cornerHarris_demo(val):
    thresh = val

    # Detector parameters
    blockSize = 2
    apertureSize = 3

            

Reported by Pylint.