The following issues were found

modules/objdetect/misc/python/test/test_peopledetect.py
29 issues
Unable to import 'cv2'
Error

Line: 11 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q

            

Reported by Pylint.

Unable to import 'tests_common'
Error

Line: 19 Column: 1

                  qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate

class peopledetect_test(NewOpenCVTests):
    def test_peopledetect(self):

        hog = cv.HOGDescriptor()

            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 10 Column: 1

              # Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 14 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate

            

Reported by Pylint.

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

Line: 14 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate

            

Reported by Pylint.

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

Line: 14 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate

            

Reported by Pylint.

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

Line: 15 Column: 13

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate


            

Reported by Pylint.

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

Line: 15 Column: 17

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate


            

Reported by Pylint.

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

Line: 15 Column: 9

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate


            

Reported by Pylint.

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

Line: 15 Column: 5

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh

from tests_common import NewOpenCVTests, intersectionRate


            

Reported by Pylint.

samples/python/peopledetect.py
29 issues
Unable to import 'cv2'
Error

Line: 16 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q

            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 15 Column: 1

              # Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 50 Column: 9

                          if img is None:
                print('Failed to load image file:', fn)
                continue
        except:
            print('loading error')
            continue

        found, _w = hog.detectMultiScale(img, winStride=(8,8), padding=(32,32), scale=1.05)
        found_filtered = []

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 19 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh



            

Reported by Pylint.

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

Line: 19 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh



            

Reported by Pylint.

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

Line: 19 Column: 1

              import cv2 as cv


def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh



            

Reported by Pylint.

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

Line: 20 Column: 5

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh


def draw_detections(img, rects, thickness = 1):

            

Reported by Pylint.

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

Line: 20 Column: 17

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh


def draw_detections(img, rects, thickness = 1):

            

Reported by Pylint.

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

Line: 20 Column: 13

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh


def draw_detections(img, rects, thickness = 1):

            

Reported by Pylint.

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

Line: 20 Column: 9

              

def inside(r, q):
    rx, ry, rw, rh = r
    qx, qy, qw, qh = q
    return rx > qx and ry > qy and rx + rw < qx + qw and ry + rh < qy + qh


def draw_detections(img, rects, thickness = 1):

            

Reported by Pylint.

samples/dnn/tf_text_graph_mask_rcnn.py
29 issues
Wildcard import tf_text_graph_common
Error

Line: 3 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Unused import GraphDef from wildcard import
Error

Line: 3 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Unused import listToTensor from wildcard import
Error

Line: 3 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Unused import parseMessage from wildcard import
Error

Line: 3 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Unused import tokenize from wildcard import
Error

Line: 3 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Redefining name 'name' from outer scope (line 290)
Error

Line: 59 Column: 15

              removeIdentity(graph_def)

nodesToKeep = []
def to_remove(name, op):
    if name in nodesToKeep:
        return False
    return op == 'Const' or name.startswith(scopesToIgnore) or not name.startswith(scopesToKeep) or \
           (name.startswith('CropAndResize') and op != 'CropAndResize')


            

Reported by Pylint.

Redefining name 'node' from outer scope (line 67)
Error

Line: 278 Column: 9

              
def getUnconnectedNodes():
    unconnected = [node.name for node in graph_def.node]
    for node in graph_def.node:
        for inp in node.input:
            if inp in unconnected:
                unconnected.remove(inp)
    return unconnected


            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import argparse
import numpy as np
from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')

            

Reported by Pylint.

Line too long (101/100)
Error

Line: 6 Column: 1

              from tf_text_graph_common import *

parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')
parser.add_argument('--config', required=True, help='Path to a *.config file is used for training.')
args = parser.parse_args()

            

Reported by Pylint.

Line too long (118/100)
Error

Line: 7 Column: 1

              
parser = argparse.ArgumentParser(description='Run this script to get a text graph of '
                                             'Mask-RCNN model from TensorFlow Object Detection API. '
                                             'Then pass it with .pb file to cv::dnn::readNetFromTensorflow function.')
parser.add_argument('--input', required=True, help='Path to frozen TensorFlow graph.')
parser.add_argument('--output', required=True, help='Path to output text graph.')
parser.add_argument('--config', required=True, help='Path to a *.config file is used for training.')
args = parser.parse_args()


            

Reported by Pylint.

modules/python/test/test_mser.py
29 issues
Unable to import 'cv2'
Error

Line: 10 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

from tests_common import NewOpenCVTests

class mser_test(NewOpenCVTests):
    def test_mser(self):

            

Reported by Pylint.

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

Line: 14 Column: 1

              
from tests_common import NewOpenCVTests

class mser_test(NewOpenCVTests):
    def test_mser(self):

        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],

            

Reported by Pylint.

Missing class docstring
Error

Line: 14 Column: 1

              
from tests_common import NewOpenCVTests

class mser_test(NewOpenCVTests):
    def test_mser(self):

        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 15 Column: 5

              from tests_common import NewOpenCVTests

class mser_test(NewOpenCVTests):
    def test_mser(self):

        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],

            

Reported by Pylint.

Too many local variables (22/15)
Error

Line: 15 Column: 5

              from tests_common import NewOpenCVTests

class mser_test(NewOpenCVTests):
    def test_mser(self):

        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],

            

Reported by Pylint.

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

Line: 18 Column: 9

                  def test_mser(self):

        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],

            

Reported by Pylint.

Line too long (140/100)
Error

Line: 19 Column: 1

              
        img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],

            

Reported by Pylint.

Line too long (140/100)
Error

Line: 20 Column: 1

                      img = self.get_sample('cv/mser/puzzle.png', 0)
        smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],

            

Reported by Pylint.

Line too long (140/100)
Error

Line: 21 Column: 1

                      smallImg = [
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],

            

Reported by Pylint.

Line too long (140/100)
Error

Line: 22 Column: 1

                       [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],
         [255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255, 255, 255, 255, 255, 255,   0,   0,   0,   0, 255, 255, 255, 255],

            

Reported by Pylint.

samples/android/mobilenet-objdetect/src/org/opencv/samples/opencv_mobilenet/MainActivity.java
29 issues
Avoid instantiating FileInputStream, FileOutputStream, FileReader, or FileWriter
Performance

Line: 143

              
            // Create copy file in storage.
            File outFile = new File(context.getFilesDir(), file);
            FileOutputStream os = new FileOutputStream(outFile);
            os.write(data);
            os.close();
            // Return a path to file which may be read in common way.
            return outFile.getAbsolutePath();
        } catch (IOException ex) {

            

Reported by PMD.

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

Line: 32

              public class MainActivity extends AppCompatActivity implements CvCameraViewListener2 {

    // Initialize OpenCV manager.
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");

            

Reported by PMD.

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

Line: 32

              public class MainActivity extends AppCompatActivity implements CvCameraViewListener2 {

    // Initialize OpenCV manager.
    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");

            

Reported by PMD.

A switch with less than three branches is inefficient, use a if statement instead.
Performance

Line: 35

                  private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS: {
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                    break;
                }

            

Reported by PMD.

Avoid unused local variables such as 'WH_RATIO'.
Design

Line: 77

                  public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        final int IN_WIDTH = 300;
        final int IN_HEIGHT = 300;
        final float WH_RATIO = (float)IN_WIDTH / IN_HEIGHT;
        final double IN_SCALE_FACTOR = 0.007843;
        final double MEAN_VAL = 127.5;
        final double THRESHOLD = 0.2;

        // Get a new frame

            

Reported by PMD.

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

Line: 93

                      net.setInput(blob);
        Mat detections = net.forward();

        int cols = frame.cols();
        int rows = frame.rows();

        detections = detections.reshape(1, (int)detections.total() / 7);

        for (int i = 0; i < detections.rows(); ++i) {

            

Reported by PMD.

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

Line: 94

                      Mat detections = net.forward();

        int cols = frame.cols();
        int rows = frame.rows();

        detections = detections.reshape(1, (int)detections.total() / 7);

        for (int i = 0; i < detections.rows(); ++i) {
            double confidence = detections.get(i, 2)[0];

            

Reported by PMD.

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

Line: 96

                      int cols = frame.cols();
        int rows = frame.rows();

        detections = detections.reshape(1, (int)detections.total() / 7);

        for (int i = 0; i < detections.rows(); ++i) {
            double confidence = detections.get(i, 2)[0];
            if (confidence > THRESHOLD) {
                int classId = (int)detections.get(i, 1)[0];

            

Reported by PMD.

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

Line: 96

                      int cols = frame.cols();
        int rows = frame.rows();

        detections = detections.reshape(1, (int)detections.total() / 7);

        for (int i = 0; i < detections.rows(); ++i) {
            double confidence = detections.get(i, 2)[0];
            if (confidence > THRESHOLD) {
                int classId = (int)detections.get(i, 1)[0];

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 109

                              int bottom = (int)(detections.get(i, 6)[0] * rows);

                // Draw rectangle around detected object.
                Imgproc.rectangle(frame, new Point(left, top), new Point(right, bottom),
                                  new Scalar(0, 255, 0));
                String label = classNames[classId] + ": " + confidence;
                int[] baseLine = new int[1];
                Size labelSize = Imgproc.getTextSize(label, Imgproc.FONT_HERSHEY_SIMPLEX, 0.5, 1, baseLine);


            

Reported by PMD.

samples/java/tutorial_code/ml/introduction_to_svm/IntroductionToSVMDemo.java
29 issues
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: 13

              import org.opencv.ml.Ml;
import org.opencv.ml.SVM;

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

        // Set up training data

            

Reported by PMD.

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

Line: 33

                      // Train the SVM
        //! [init]
        SVM svm = SVM.create();
        svm.setType(SVM.C_SVC);
        svm.setKernel(SVM.LINEAR);
        svm.setTermCriteria(new TermCriteria(TermCriteria.MAX_ITER, 100, 1e-6));
        //! [init]
        //! [train]
        svm.train(trainingDataMat, Ml.ROW_SAMPLE, labelsMat);

            

Reported by PMD.

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

Line: 34

                      //! [init]
        SVM svm = SVM.create();
        svm.setType(SVM.C_SVC);
        svm.setKernel(SVM.LINEAR);
        svm.setTermCriteria(new TermCriteria(TermCriteria.MAX_ITER, 100, 1e-6));
        //! [init]
        //! [train]
        svm.train(trainingDataMat, Ml.ROW_SAMPLE, labelsMat);
        //! [train]

            

Reported by PMD.

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

Line: 38

                      svm.setTermCriteria(new TermCriteria(TermCriteria.MAX_ITER, 100, 1e-6));
        //! [init]
        //! [train]
        svm.train(trainingDataMat, Ml.ROW_SAMPLE, labelsMat);
        //! [train]

        // Data for visual representation
        int width = 512, height = 512;
        Mat image = Mat.zeros(height, width, CvType.CV_8UC3);

            

Reported by PMD.

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

Line: 47

              
        // Show the decision regions given by the SVM
        //! [show]
        byte[] imageData = new byte[(int) (image.total() * image.channels())];
        Mat sampleMat = new Mat(1, 2, CvType.CV_32F);
        float[] sampleMatData = new float[(int) (sampleMat.total() * sampleMat.channels())];
        for (int i = 0; i < image.rows(); i++) {
            for (int j = 0; j < image.cols(); j++) {
                sampleMatData[0] = j;

            

Reported by PMD.

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

Line: 47

              
        // Show the decision regions given by the SVM
        //! [show]
        byte[] imageData = new byte[(int) (image.total() * image.channels())];
        Mat sampleMat = new Mat(1, 2, CvType.CV_32F);
        float[] sampleMatData = new float[(int) (sampleMat.total() * sampleMat.channels())];
        for (int i = 0; i < image.rows(); i++) {
            for (int j = 0; j < image.cols(); j++) {
                sampleMatData[0] = j;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 57

                              sampleMat.put(0, 0, sampleMatData);
                float response = svm.predict(sampleMat);

                if (response == 1) {
                    imageData[(i * image.cols() + j) * image.channels()] = 0;
                    imageData[(i * image.cols() + j) * image.channels() + 1] = (byte) 255;
                    imageData[(i * image.cols() + j) * image.channels() + 2] = 0;
                } else if (response == -1) {
                    imageData[(i * image.cols() + j) * image.channels()] = (byte) 255;

            

Reported by PMD.

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

Line: 68

                              }
            }
        }
        image.put(0, 0, imageData);
        //! [show]

        // Show the training data
        //! [show_data]
        int thickness = -1;

            

Reported by PMD.

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

Line: 84

                      // Show support vectors
        //! [show_vectors]
        thickness = 2;
        Mat sv = svm.getUncompressedSupportVectors();
        float[] svData = new float[(int) (sv.total() * sv.channels())];
        sv.get(0, 0, svData);
        for (int i = 0; i < sv.rows(); ++i) {
            Imgproc.circle(image, new Point(svData[i * sv.cols()], svData[i * sv.cols() + 1]), 6,
                    new Scalar(128, 128, 128), thickness, lineType, 0);

            

Reported by PMD.

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

Line: 85

                      //! [show_vectors]
        thickness = 2;
        Mat sv = svm.getUncompressedSupportVectors();
        float[] svData = new float[(int) (sv.total() * sv.channels())];
        sv.get(0, 0, svData);
        for (int i = 0; i < sv.rows(); ++i) {
            Imgproc.circle(image, new Point(svData[i * sv.cols()], svData[i * sv.cols() + 1]), 6,
                    new Scalar(128, 128, 128), thickness, lineType, 0);
        }

            

Reported by PMD.

samples/java/tutorial_code/ImgProc/Smoothing/Smoothing.java
29 issues
System.out.println is used
Design

Line: 22

              
        src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
        if( src.empty() ) {
            System.out.println("Error opening image");
            System.out.println("Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }

        if( displayCaption( "Original Image" ) != 0 ) { System.exit(0); }

            

Reported by PMD.

System.out.println is used
Design

Line: 23

                      src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
        if( src.empty() ) {
            System.out.println("Error opening image");
            System.out.println("Usage: ./Smoothing [image_name -- default ../data/lena.jpg] \n");
            System.exit(-1);
        }

        if( displayCaption( "Original Image" ) != 0 ) { System.exit(0); }


            

Reported by PMD.

The class 'SmoothingRun' has a Standard Cyclomatic Complexity of 6 (Highest = 13).
Design

Line: 6

              import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

class SmoothingRun {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

            

Reported by PMD.

The class 'SmoothingRun' has a Modified Cyclomatic Complexity of 6 (Highest = 13).
Design

Line: 6

              import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

class SmoothingRun {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

            

Reported by PMD.

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

Line: 9

              class SmoothingRun {

    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

            

Reported by PMD.

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

Line: 10

              
    ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";


            

Reported by PMD.

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

Line: 11

                  ///  Global Variables
    int DELAY_CAPTION = 1500;
    int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

            

Reported by PMD.

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

Line: 13

                  int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

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

            

Reported by PMD.

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

Line: 13

                  int DELAY_BLUR = 100;
    int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

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

            

Reported by PMD.

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

Line: 14

                  int MAX_KERNEL_LENGTH = 31;

    Mat src = new Mat(), dst = new Mat();
    String windowName = "Filter Demo 1";

    public void run(String[] args) {

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


            

Reported by PMD.

modules/core/src/opencl/runtime/generator/parser_clblas.py
29 issues
Unnecessary semicolon
Error

Line: 5 Column: 1

              # usage:
#     cat clBLAS.h | $0
from __future__ import print_function
import sys, re;

from common import remove_comments, getTokens, getParameters, postProcessParameters

try:
    if len(sys.argv) > 1:

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 14 Column: 1

                      f = open(sys.argv[1], "r")
    else:
        f = sys.stdin
except:
    sys.exit("ERROR. Can't open input file")

fns = []

while True:

            

Reported by Pylint.

Unnecessary semicolon
Error

Line: 25 Column: 1

                      break
    assert isinstance(line, str)
    line = line.strip()
    parts = line.split();
    if (line.startswith('clblas') or line.startswith('cl_') or line == 'void') and len(line.split()) == 1 and line.find('(') == -1:
        fn = {}
        modifiers = []
        ret = []
        calling = []

            

Reported by Pylint.

Unnecessary semicolon
Error

Line: 62 Column: 1

                          nl = nl.strip()
            nl = re.sub(r'\n', r'', nl)
            if len(nl) == 0:
                break;
            line += ' ' + nl

        line = remove_comments(line)

        parts = getTokens(line)

            

Reported by Pylint.

Unnecessary semicolon
Error

Line: 69 Column: 1

              
        parts = getTokens(line)

        i = 0;

        name = parts[i]; i += 1;
        fn['name'] = name
        print('name=' + name)


            

Reported by Pylint.

Unnecessary semicolon
Error

Line: 71 Column: 1

              
        i = 0;

        name = parts[i]; i += 1;
        fn['name'] = name
        print('name=' + name)

        params = getParameters(i, parts)


            

Reported by Pylint.

Unused import generateInlineWrappers from wildcard import
Error

Line: 91 Column: 1

              from pprint import pprint
pprint(fns)

from common import *

filterFileName='./filter/opencl_clblas_functions.list'
numEnabled = readFunctionFilter(fns, filterFileName)

functionsFilter = generateFilterNames(fns)

            

Reported by Pylint.

Unused import generateStaticDefinitions from wildcard import
Error

Line: 91 Column: 1

              from pprint import pprint
pprint(fns)

from common import *

filterFileName='./filter/opencl_clblas_functions.list'
numEnabled = readFunctionFilter(fns, filterFileName)

functionsFilter = generateFilterNames(fns)

            

Reported by Pylint.

Unused import getTypeWithParam from wildcard import
Error

Line: 91 Column: 1

              from pprint import pprint
pprint(fns)

from common import *

filterFileName='./filter/opencl_clblas_functions.list'
numEnabled = readFunctionFilter(fns, filterFileName)

functionsFilter = generateFilterNames(fns)

            

Reported by Pylint.

Unused import callback_check from wildcard import
Error

Line: 91 Column: 1

              from pprint import pprint
pprint(fns)

from common import *

filterFileName='./filter/opencl_clblas_functions.list'
numEnabled = readFunctionFilter(fns, filterFileName)

functionsFilter = generateFilterNames(fns)

            

Reported by Pylint.

samples/python/floodfill.py
28 issues
Unable to import 'cv2'
Error

Line: 21 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

import sys

class App():


            

Reported by Pylint.

Unused argument 'dummy'
Error

Line: 27 Column: 22

              
class App():

    def update(self, dummy=None):
        if self.seed_pt is None:
            cv.imshow('floodfill', self.img)
            return
        flooded = self.img.copy()
        self.mask[:] = 0

            

Reported by Pylint.

Unused argument 'param'
Error

Line: 42 Column: 43

                      cv.circle(flooded, self.seed_pt, 2, (0, 0, 255), -1)
        cv.imshow('floodfill', flooded)

    def onmouse(self, event, x, y, flags, param):
        if flags & cv.EVENT_FLAG_LBUTTON:
            self.seed_pt = x, y
            self.update()

    def run(self):

            

Reported by Pylint.

Unused argument 'event'
Error

Line: 42 Column: 23

                      cv.circle(flooded, self.seed_pt, 2, (0, 0, 255), -1)
        cv.imshow('floodfill', flooded)

    def onmouse(self, event, x, y, flags, param):
        if flags & cv.EVENT_FLAG_LBUTTON:
            self.seed_pt = x, y
            self.update()

    def run(self):

            

Reported by Pylint.

Attribute 'seed_pt' defined outside __init__
Error

Line: 44 Column: 13

              
    def onmouse(self, event, x, y, flags, param):
        if flags & cv.EVENT_FLAG_LBUTTON:
            self.seed_pt = x, y
            self.update()

    def run(self):
        try:
            fn = sys.argv[1]

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 50 Column: 9

                  def run(self):
        try:
            fn = sys.argv[1]
        except:
            fn = 'fruits.jpg'

        self.img = cv.imread(cv.samples.findFile(fn))
        if self.img is None:
            print('Failed to load image file:', fn)

            

Reported by Pylint.

Attribute 'img' defined outside __init__
Error

Line: 53 Column: 9

                      except:
            fn = 'fruits.jpg'

        self.img = cv.imread(cv.samples.findFile(fn))
        if self.img is None:
            print('Failed to load image file:', fn)
            sys.exit(1)

        h, w = self.img.shape[:2]

            

Reported by Pylint.

Attribute 'mask' defined outside __init__
Error

Line: 59 Column: 9

                          sys.exit(1)

        h, w = self.img.shape[:2]
        self.mask = np.zeros((h+2, w+2), np.uint8)
        self.seed_pt = None
        self.fixed_range = True
        self.connectivity = 4

        self.update()

            

Reported by Pylint.

Attribute 'seed_pt' defined outside __init__
Error

Line: 60 Column: 9

              
        h, w = self.img.shape[:2]
        self.mask = np.zeros((h+2, w+2), np.uint8)
        self.seed_pt = None
        self.fixed_range = True
        self.connectivity = 4

        self.update()
        cv.setMouseCallback('floodfill', self.onmouse)

            

Reported by Pylint.

Attribute 'fixed_range' defined outside __init__
Error

Line: 61 Column: 9

                      h, w = self.img.shape[:2]
        self.mask = np.zeros((h+2, w+2), np.uint8)
        self.seed_pt = None
        self.fixed_range = True
        self.connectivity = 4

        self.update()
        cv.setMouseCallback('floodfill', self.onmouse)
        cv.createTrackbar('lo', 'floodfill', 20, 255, self.update)

            

Reported by Pylint.

samples/java/tutorial_code/ImgProc/changing_contrast_brightness_image/ChangingContrastBrightnessImageDemo.java
28 issues
System.out.println is used
Design

Line: 49

                      String imagePath = args.length > 0 ? args[0] : "../data/lena.jpg";
        matImgSrc = Imgcodecs.imread(imagePath);
        if (matImgSrc.empty()) {
            System.out.println("Empty image: " + imagePath);
            System.exit(0);
        }

        // Create and set up the window.
        frame = new JFrame(WINDOW_NAME);

            

Reported by PMD.

Too many fields
Design

Line: 23

              import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;

class ChangingContrastBrightnessImage {
    private static int MAX_VALUE_ALPHA = 500;
    private static int MAX_VALUE_BETA_GAMMA = 200;
    private static final String WINDOW_NAME = "Changing the contrast and brightness of an image demo";
    private static final String ALPHA_NAME = "Alpha gain (contrast)";
    private static final String BETA_NAME = "Beta bias (brightness)";

            

Reported by PMD.

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

Line: 30

                  private static final String ALPHA_NAME = "Alpha gain (contrast)";
    private static final String BETA_NAME = "Beta bias (brightness)";
    private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;

            

Reported by PMD.

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

Line: 30

                  private static final String ALPHA_NAME = "Alpha gain (contrast)";
    private static final String BETA_NAME = "Beta bias (brightness)";
    private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;

            

Reported by PMD.

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

Line: 31

                  private static final String BETA_NAME = "Beta bias (brightness)";
    private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;

            

Reported by PMD.

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

Line: 31

                  private static final String BETA_NAME = "Beta bias (brightness)";
    private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;

            

Reported by PMD.

The field initializer for 'matImgSrc' is never used (overwritten on line 47)
Design

Line: 31

                  private static final String BETA_NAME = "Beta bias (brightness)";
    private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;

            

Reported by PMD.

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

Line: 32

                  private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;
    private double alphaValue = 1.0;

            

Reported by PMD.

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

Line: 32

                  private static final String GAMMA_NAME = "Gamma correction";
    private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;
    private double alphaValue = 1.0;

            

Reported by PMD.

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

Line: 33

                  private JFrame frame;
    private Mat matImgSrc = new Mat();
    private JLabel imgSrcLabel;
    private JLabel imgModifLabel;
    private JPanel controlPanel;
    private JPanel alphaBetaPanel;
    private JPanel gammaPanel;
    private double alphaValue = 1.0;
    private double betaValue = 0.0;

            

Reported by PMD.