The following issues were found

modules/python/test/test_algorithm_rw.py
6 issues
Unable to import 'cv2'
Error

Line: 5 Column: 1

              """Algorithm serialization test."""
import tempfile
import os
import cv2 as cv
from tests_common import NewOpenCVTests


class algorithm_rw_test(NewOpenCVTests):
    def test_algorithm_rw(self):

            

Reported by Pylint.

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

Line: 9 Column: 1

              from tests_common import NewOpenCVTests


class algorithm_rw_test(NewOpenCVTests):
    def test_algorithm_rw(self):
        fd, fname = tempfile.mkstemp(prefix="opencv_python_algorithm_", suffix=".yml")
        os.close(fd)

        # some arbitrary non-default parameters

            

Reported by Pylint.

Missing class docstring
Error

Line: 9 Column: 1

              from tests_common import NewOpenCVTests


class algorithm_rw_test(NewOpenCVTests):
    def test_algorithm_rw(self):
        fd, fname = tempfile.mkstemp(prefix="opencv_python_algorithm_", suffix=".yml")
        os.close(fd)

        # some arbitrary non-default parameters

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 10 Column: 5

              

class algorithm_rw_test(NewOpenCVTests):
    def test_algorithm_rw(self):
        fd, fname = tempfile.mkstemp(prefix="opencv_python_algorithm_", suffix=".yml")
        os.close(fd)

        # some arbitrary non-default parameters
        gold = cv.AKAZE_create(descriptor_size=1, descriptor_channels=2, nOctaves=3, threshold=4.0)

            

Reported by Pylint.

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

Line: 11 Column: 9

              
class algorithm_rw_test(NewOpenCVTests):
    def test_algorithm_rw(self):
        fd, fname = tempfile.mkstemp(prefix="opencv_python_algorithm_", suffix=".yml")
        os.close(fd)

        # some arbitrary non-default parameters
        gold = cv.AKAZE_create(descriptor_size=1, descriptor_channels=2, nOctaves=3, threshold=4.0)
        gold.write(cv.FileStorage(fname, cv.FILE_STORAGE_WRITE), "AKAZE")

            

Reported by Pylint.

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

Line: 18 Column: 9

                      gold = cv.AKAZE_create(descriptor_size=1, descriptor_channels=2, nOctaves=3, threshold=4.0)
        gold.write(cv.FileStorage(fname, cv.FILE_STORAGE_WRITE), "AKAZE")

        fs = cv.FileStorage(fname, cv.FILE_STORAGE_READ)
        algorithm = cv.AKAZE_create()
        algorithm.read(fs.getNode("AKAZE"))

        self.assertEqual(algorithm.getDescriptorSize(), 1)
        self.assertEqual(algorithm.getDescriptorChannels(), 2)

            

Reported by Pylint.

modules/python/package/setup.py
6 issues
Unused import sys
Error

Line: 2 Column: 1

              import os
import sys
import platform
import setuptools

SCRIPT_DIR=os.path.dirname(os.path.abspath(__file__))

def main():
    os.chdir(SCRIPT_DIR)

            

Reported by Pylint.

Unused import platform
Error

Line: 3 Column: 1

              import os
import sys
import platform
import setuptools

SCRIPT_DIR=os.path.dirname(os.path.abspath(__file__))

def main():
    os.chdir(SCRIPT_DIR)

            

Reported by Pylint.

TODO
Error

Line: 12 Column: 3

                  os.chdir(SCRIPT_DIR)

    package_name = 'opencv'
    package_version = os.environ.get('OPENCV_VERSION', '4.5.3')  # TODO

    long_description = 'Open Source Computer Vision Library Python bindings'  # TODO

    setuptools.setup(
        name=package_name,

            

Reported by Pylint.

TODO
Error

Line: 14 Column: 3

                  package_name = 'opencv'
    package_version = os.environ.get('OPENCV_VERSION', '4.5.3')  # TODO

    long_description = 'Open Source Computer Vision Library Python bindings'  # TODO

    setuptools.setup(
        name=package_name,
        version=package_version,
        url='https://github.com/opencv/opencv',

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import os
import sys
import platform
import setuptools

SCRIPT_DIR=os.path.dirname(os.path.abspath(__file__))

def main():
    os.chdir(SCRIPT_DIR)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 8 Column: 1

              
SCRIPT_DIR=os.path.dirname(os.path.abspath(__file__))

def main():
    os.chdir(SCRIPT_DIR)

    package_name = 'opencv'
    package_version = os.environ.get('OPENCV_VERSION', '4.5.3')  # TODO


            

Reported by Pylint.

modules/core/misc/java/src/java/core+MatOfInt.java
6 issues
Avoid throwing raw exception types.
Design

Line: 55

                  public int[] toArray() {
        int num = checkVector(_channels, _depth);
        if(num < 0)
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
        int[] a = new int[num * _channels];
        if(num == 0)
            return a;
        get(0, 0, a); //TODO: check ret val!
        return a;

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 64

                  }

    public void fromList(List<Integer> lb) {
        if(lb==null || lb.size()==0)
            return;
        Integer ab[] = lb.toArray(new Integer[0]);
        int a[] = new int[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '67'-'69').
Error

Line: 67

                      if(lb==null || lb.size()==0)
            return;
        Integer ab[] = lb.toArray(new Integer[0]);
        int a[] = new int[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '69'-'69').
Error

Line: 69

                      Integer ab[] = lb.toArray(new Integer[0]);
        int a[] = new int[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }

    public List<Integer> toList() {
        int[] a = toArray();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '75'-'77').
Error

Line: 75

              
    public List<Integer> toList() {
        int[] a = toArray();
        Integer ab[] = new Integer[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '77'-'77').
Error

Line: 77

                      int[] a = toArray();
        Integer ab[] = new Integer[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

modules/core/misc/java/src/java/core+MatOfFloat6.java
6 issues
Avoid throwing raw exception types.
Design

Line: 54

                  public float[] toArray() {
        int num = checkVector(_channels, _depth);
        if(num < 0)
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
        float[] a = new float[num * _channels];
        if(num == 0)
            return a;
        get(0, 0, a); //TODO: check ret val!
        return a;

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 63

                  }

    public void fromList(List<Float> lb) {
        if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '66'-'68').
Error

Line: 66

                      if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '68'-'68').
Error

Line: 68

                      Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }

    public List<Float> toList() {
        float[] a = toArray();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '74'-'76').
Error

Line: 74

              
    public List<Float> toList() {
        float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '76'-'76').
Error

Line: 76

                      float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

modules/core/misc/java/src/java/core+MatOfFloat4.java
6 issues
Avoid throwing raw exception types.
Design

Line: 54

                  public float[] toArray() {
        int num = checkVector(_channels, _depth);
        if(num < 0)
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
        float[] a = new float[num * _channels];
        if(num == 0)
            return a;
        get(0, 0, a); //TODO: check ret val!
        return a;

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 63

                  }

    public void fromList(List<Float> lb) {
        if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '66'-'68').
Error

Line: 66

                      if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '68'-'68').
Error

Line: 68

                      Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }

    public List<Float> toList() {
        float[] a = toArray();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '74'-'76').
Error

Line: 74

              
    public List<Float> toList() {
        float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '76'-'76').
Error

Line: 76

                      float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

modules/core/misc/java/src/java/core+MatOfFloat.java
6 issues
Avoid throwing raw exception types.
Design

Line: 54

                  public float[] toArray() {
        int num = checkVector(_channels, _depth);
        if(num < 0)
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
        float[] a = new float[num * _channels];
        if(num == 0)
            return a;
        get(0, 0, a); //TODO: check ret val!
        return a;

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 63

                  }

    public void fromList(List<Float> lb) {
        if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '66'-'68').
Error

Line: 66

                      if(lb==null || lb.size()==0)
            return;
        Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '68'-'68').
Error

Line: 68

                      Float ab[] = lb.toArray(new Float[0]);
        float a[] = new float[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }

    public List<Float> toList() {
        float[] a = toArray();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '74'-'76').
Error

Line: 74

              
    public List<Float> toList() {
        float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '76'-'76').
Error

Line: 76

                      float[] a = toArray();
        Float ab[] = new Float[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

modules/core/misc/java/src/java/core+MatOfDouble.java
6 issues
Avoid throwing raw exception types.
Design

Line: 54

                  public double[] toArray() {
        int num = checkVector(_channels, _depth);
        if(num < 0)
            throw new RuntimeException("Native Mat has unexpected type or size: " + toString());
        double[] a = new double[num * _channels];
        if(num == 0)
            return a;
        get(0, 0, a); //TODO: check ret val!
        return a;

            

Reported by PMD.

Substitute calls to size() == 0 (or size() != 0, size() > 0, size() < 1) with calls to isEmpty()
Design

Line: 63

                  }

    public void fromList(List<Double> lb) {
        if(lb==null || lb.size()==0)
            return;
        Double ab[] = lb.toArray(new Double[0]);
        double a[] = new double[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];

            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '66'-'68').
Error

Line: 66

                      if(lb==null || lb.size()==0)
            return;
        Double ab[] = lb.toArray(new Double[0]);
        double a[] = new double[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'a' (lines '68'-'68').
Error

Line: 68

                      Double ab[] = lb.toArray(new Double[0]);
        double a[] = new double[ab.length];
        for(int i=0; i<ab.length; i++)
            a[i] = ab[i];
        fromArray(a);
    }

    public List<Double> toList() {
        double[] a = toArray();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '74'-'76').
Error

Line: 74

              
    public List<Double> toList() {
        double[] a = toArray();
        Double ab[] = new Double[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

Found 'DD'-anomaly for variable 'ab' (lines '76'-'76').
Error

Line: 76

                      double[] a = toArray();
        Double ab[] = new Double[a.length];
        for(int i=0; i<a.length; i++)
            ab[i] = a[i];
        return Arrays.asList(ab);
    }
}

            

Reported by PMD.

samples/python/stitching.py
5 issues
Unable to import 'cv2'
Error

Line: 15 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

import argparse
import sys

modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS)

            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 14 Column: 1

              # Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv

import argparse
import sys


            

Reported by Pylint.

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

Line: 17 Column: 1

              import numpy as np
import cv2 as cv

import argparse
import sys

modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS)

parser = argparse.ArgumentParser(prog='stitching.py', description='Stitching sample.')

            

Reported by Pylint.

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

Line: 18 Column: 1

              import cv2 as cv

import argparse
import sys

modes = (cv.Stitcher_PANORAMA, cv.Stitcher_SCANS)

parser = argparse.ArgumentParser(prog='stitching.py', description='Stitching sample.')
parser.add_argument('--mode',

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 34 Column: 1

              
__doc__ += '\n' + parser.format_help()

def main():
    args = parser.parse_args()

    # read input images
    imgs = []
    for img_name in args.img:

            

Reported by Pylint.

samples/python/mser.py
5 issues
Unable to import 'cv2'
Error

Line: 21 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv

import video
import sys

def main():

            

Reported by Pylint.

Unused numpy imported as np
Error

Line: 20 Column: 1

              # Python 2/3 compatibility
from __future__ import print_function

import numpy as np
import cv2 as cv

import video
import sys


            

Reported by Pylint.

No exception type(s) specified
Error

Line: 29 Column: 5

              def main():
    try:
        video_src = sys.argv[1]
    except:
        video_src = 0

    cam = video.create_capture(video_src)
    mser = cv.MSER_create()


            

Reported by Pylint.

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

Line: 24 Column: 1

              import cv2 as cv

import video
import sys

def main():
    try:
        video_src = sys.argv[1]
    except:

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 26 Column: 1

              import video
import sys

def main():
    try:
        video_src = sys.argv[1]
    except:
        video_src = 0


            

Reported by Pylint.

modules/java/generator/android/java/org/opencv/android/CameraActivity.java
5 issues
These nested if statements could be combined
Design

Line: 41

                      super.onStart();
        boolean havePermission = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (checkSelfPermission(CAMERA) != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
                havePermission = false;
            }
        }
        if (havePermission) {

            

Reported by PMD.

Avoid unused imports such as 'android.content.Context'
Design

Line: 5

              
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;


            

Reported by PMD.

Avoid unused imports such as 'android.util.AttributeSet'
Design

Line: 8

              import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import java.util.ArrayList;
import java.util.List;


            

Reported by PMD.

Avoid unused imports such as 'android.view.View'
Design

Line: 9

              import android.content.pm.PackageManager;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import static android.Manifest.permission.CAMERA;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'havePermission' (lines '39'-'43').
Error

Line: 39

                  @Override
    protected void onStart() {
        super.onStart();
        boolean havePermission = true;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (checkSelfPermission(CAMERA) != PackageManager.PERMISSION_GRANTED) {
                requestPermissions(new String[]{CAMERA}, CAMERA_PERMISSION_REQUEST_CODE);
                havePermission = false;
            }

            

Reported by PMD.