The following issues were found

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

Line: 16

              
public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {

    Feature2D extractor;
    int matSize;

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

            

Reported by PMD.

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

Line: 17

              public class BRIEFDescriptorExtractorTest extends OpenCVTestCase {

    Feature2D extractor;
    int matSize;

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

            

Reported by PMD.

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

Line: 27

                      return cross;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        extractor = createClassInstance(XFEATURES2D+"BriefDescriptorExtractor", DEFAULT_FACTORY, null, null);
        matSize = 100;
    }

            

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

                      matSize = 100;
    }

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

    public void testComputeMatListOfKeyPointMat() {
        KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -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: 38

                      fail("Not yet implemented");
    }

    public void testComputeMatListOfKeyPointMat() {
        KeyPoint point = new KeyPoint(55.775577545166016f, 44.224422454833984f, 16, 9.754629f, 8617.863f, 1, -1);
        MatOfKeyPoint keypoints = new MatOfKeyPoint(point);
        Mat img = getTestImg();
        Mat descriptors = new Mat();


            

Reported by PMD.

Double-brace initialization should be avoided
Design

Line: 47

                      extractor.compute(img, keypoints, descriptors);

        Mat truth = new Mat(1, 32, CvType.CV_8UC1) {
            {
                put(0, 0, 96, 0, 76, 24, 47, 182, 68, 137,
                          149, 195, 67, 16, 187, 224, 74, 8,
                          82, 169, 87, 70, 44, 4, 192, 56,
                          13, 128, 44, 106, 146, 72, 194, 245);
            }

            

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

                      assertMatEqual(truth, descriptors);
    }

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

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

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 62

                      assertNotNull(extractor);
    }

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

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

            

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

                      assertEquals(32, extractor.descriptorSize());
    }

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

    public void testEmpty() {
//        assertFalse(extractor.empty());

            

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

                      assertEquals(CvType.CV_8U, extractor.descriptorType());
    }

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

    public void testRead() {

            

Reported by PMD.

samples/android/camera-calibration/src/org/opencv/samples/cameracalibration/OnCameraFrameRender.java
13 issues
Potential violation of Law of Demeter (method chain calls)
Design

Line: 53

              
    @Override
    public Mat render(CvCameraViewFrame inputFrame) {
        Mat renderedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
        Calib3d.undistort(inputFrame.rgba(), renderedFrame,
                mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

        return renderedFrame;
    }

            

Reported by PMD.

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

Line: 53

              
    @Override
    public Mat render(CvCameraViewFrame inputFrame) {
        Mat renderedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
        Calib3d.undistort(inputFrame.rgba(), renderedFrame,
                mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

        return renderedFrame;
    }

            

Reported by PMD.

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

Line: 62

              }

class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;

            

Reported by PMD.

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

Line: 62

              }

class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;

            

Reported by PMD.

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

Line: 63

              
class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;
        mHeight = height;

            

Reported by PMD.

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

Line: 63

              
class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;
        mHeight = height;

            

Reported by PMD.

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

Line: 64

              class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;
        mHeight = height;
        mResources = resources;

            

Reported by PMD.

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

Line: 64

              class ComparisonFrameRender extends FrameRender {
    private int mWidth;
    private int mHeight;
    private Resources mResources;
    public ComparisonFrameRender(CameraCalibrator calibrator, int width, int height, Resources resources) {
        mCalibrator = calibrator;
        mWidth = width;
        mHeight = height;
        mResources = resources;

            

Reported by PMD.

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

Line: 74

              
    @Override
    public Mat render(CvCameraViewFrame inputFrame) {
        Mat undistortedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
        Calib3d.undistort(inputFrame.rgba(), undistortedFrame,
                mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

        Mat comparisonFrame = inputFrame.rgba();
        undistortedFrame.colRange(new Range(0, mWidth / 2)).copyTo(comparisonFrame.colRange(new Range(mWidth / 2, mWidth)));

            

Reported by PMD.

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

Line: 74

              
    @Override
    public Mat render(CvCameraViewFrame inputFrame) {
        Mat undistortedFrame = new Mat(inputFrame.rgba().size(), inputFrame.rgba().type());
        Calib3d.undistort(inputFrame.rgba(), undistortedFrame,
                mCalibrator.getCameraMatrix(), mCalibrator.getDistortionCoefficients());

        Mat comparisonFrame = inputFrame.rgba();
        undistortedFrame.colRange(new Range(0, mWidth / 2)).copyTo(comparisonFrame.colRange(new Range(mWidth / 2, mWidth)));

            

Reported by PMD.

platforms/maven/opencv-it/src/test/java/org/opencv/osgi/DeployOpenCVTest.java
13 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 43

                  protected BundleContext bundleContext;

    @Inject
    private LogService logService;

    /*
    This service is required to ensure that the native library has been loaded
    before any test is carried out.
    */

            

Reported by PMD.

Avoid unused private fields such as 'openCVInterface'.
Design

Line: 50

                  before any test is carried out.
    */
    @Inject
    private OpenCVInterface openCVInterface;

    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")

            

Reported by PMD.

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

Line: 53

                  private OpenCVInterface openCVInterface;

    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")
                .artifactId("apache-karaf")
                .version(KARAF_VERSION)
                .type("tar.gz");

            

Reported by PMD.

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

Line: 54

              
    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")
                .artifactId("apache-karaf")
                .version(KARAF_VERSION)
                .type("tar.gz");
        return new Option[]{

            

Reported by PMD.

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

Line: 54

              
    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")
                .artifactId("apache-karaf")
                .version(KARAF_VERSION)
                .type("tar.gz");
        return new Option[]{

            

Reported by PMD.

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

Line: 54

              
    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")
                .artifactId("apache-karaf")
                .version(KARAF_VERSION)
                .type("tar.gz");
        return new Option[]{

            

Reported by PMD.

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

Line: 54

              
    @Configuration
    public static Option[] configuration() throws Exception {
        MavenArtifactUrlReference karafUrl = maven()
                .groupId("org.apache.karaf")
                .artifactId("apache-karaf")
                .version(KARAF_VERSION)
                .type("tar.gz");
        return new Option[]{

            

Reported by PMD.

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

Line: 65

                          .unpackDirectory(new File("../../../build/target/exam"))
            .useDeployFolder(false),
            keepRuntimeFolder(),
            mavenBundle()
            .groupId("org.opencv")
            .artifactId("opencv")
            .versionAsInProject(),
            logLevel(LogLevelOption.LogLevel.INFO)
        };

            

Reported by PMD.

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

Line: 65

                          .unpackDirectory(new File("../../../build/target/exam"))
            .useDeployFolder(false),
            keepRuntimeFolder(),
            mavenBundle()
            .groupId("org.opencv")
            .artifactId("opencv")
            .versionAsInProject(),
            logLevel(LogLevelOption.LogLevel.INFO)
        };

            

Reported by PMD.

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

Line: 65

                          .unpackDirectory(new File("../../../build/target/exam"))
            .useDeployFolder(false),
            keepRuntimeFolder(),
            mavenBundle()
            .groupId("org.opencv")
            .artifactId("opencv")
            .versionAsInProject(),
            logLevel(LogLevelOption.LogLevel.INFO)
        };

            

Reported by PMD.

platforms/android/service/engine/src/org/opencv/engine/manager/ManagerActivity.java
13 issues
Avoid instantiating String objects; this is usually unnecessary.
Performance

Line: 98

                          Log.d(TAG, "Successful connection");
            try {
                String[] vars = { "2.4", "3.0" };
                String res = new String();
                for (String piece : vars) {
                    res += "\n\t" + piece + " -> "
                            + engine.getLibraryList(piece);
                }
                mVersionText.setText("Path: "

            

Reported by PMD.

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

Line: 26

              
public class ManagerActivity extends Activity {
    protected static final String TAG = "OpenCVEngine/Activity";
    protected MarketConnector mMarket;
    protected TextView mVersionText;
    protected boolean mExtraInfo = false;

    /** Called when the activity is first created. */
    @Override

            

Reported by PMD.

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

Line: 27

              public class ManagerActivity extends Activity {
    protected static final String TAG = "OpenCVEngine/Activity";
    protected MarketConnector mMarket;
    protected TextView mVersionText;
    protected boolean mExtraInfo = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {

            

Reported by PMD.

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

Line: 28

                  protected static final String TAG = "OpenCVEngine/Activity";
    protected MarketConnector mMarket;
    protected TextView mVersionText;
    protected boolean mExtraInfo = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

            

Reported by PMD.

Avoid using redundant field initializer for 'mExtraInfo'
Performance

Line: 28

                  protected static final String TAG = "OpenCVEngine/Activity";
    protected MarketConnector mMarket;
    protected TextView mVersionText;
    protected boolean mExtraInfo = false;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

            

Reported by PMD.

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

Line: 38

                      setContentView(R.layout.main);

        final Class<OpenCVEngineService> c = OpenCVEngineService.class;
        final String packageName = c.getPackage().getName();

        mMarket = new MarketConnector(this);

        Button updateButton = (Button) findViewById(R.id.CheckEngineUpdate);
        updateButton.setOnClickListener(new OnClickListener() {

            

Reported by PMD.

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

Line: 38

                      setContentView(R.layout.main);

        final Class<OpenCVEngineService> c = OpenCVEngineService.class;
        final String packageName = c.getPackage().getName();

        mMarket = new MarketConnector(this);

        Button updateButton = (Button) findViewById(R.id.CheckEngineUpdate);
        updateButton.setOnClickListener(new OnClickListener() {

            

Reported by PMD.

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

Line: 48

                              if (!mMarket.InstallAppFromMarket(packageName)) {
                    Toast toast = Toast.makeText(getApplicationContext(),
                            "Google Play is not available", Toast.LENGTH_SHORT);
                    toast.show();
                }
            }
        });

        TextView aboutText = (TextView) findViewById(R.id.textView4);

            

Reported by PMD.

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

Line: 54

                      });

        TextView aboutText = (TextView) findViewById(R.id.textView4);
        aboutText.setText("About (" + packageName + ")");

        if (mExtraInfo) {
            TextView extraText = (TextView) findViewById(R.id.textView6);
            extraText.setText(
                    "CPU count: "

            

Reported by PMD.

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

Line: 58

              
        if (mExtraInfo) {
            TextView extraText = (TextView) findViewById(R.id.textView6);
            extraText.setText(
                    "CPU count: "
                    + HardwareDetector.getProcessorCount()
                    + "\nABI: 0x"
                    + Integer.toHexString(HardwareDetector.getAbi())
                    + "\nFlags: "

            

Reported by PMD.

modules/videoio/src/container_avi.cpp
13 issues
Uninitialized struct member: idx1.ckid
Error

Line: 300 CWE codes: 908

                      AviIndex idx1;
        *m_file_stream >> idx1;

        if(idx1.ckid == m_stream_id)
        {
            uint64_t absolute_pos = m_movi_start + idx1.dwChunkOffset;

            if(absolute_pos < m_movi_end)
            {

            

Reported by Cppcheck.

Uninitialized struct member: idx1.dwChunkOffset
Error

Line: 302 CWE codes: 908

              
        if(idx1.ckid == m_stream_id)
        {
            uint64_t absolute_pos = m_movi_start + idx1.dwChunkOffset;

            if(absolute_pos < m_movi_end)
            {
                in_frame_list.push_back(std::make_pair(absolute_pos, idx1.dwChunkLength));
            }

            

Reported by Cppcheck.

Uninitialized struct member: strm_hdr.fccType
Error

Line: 333 CWE codes: 908

              
        if (codec_ == MJPEG)
        {
            if(strm_hdr.fccType == VIDS_CC && strm_hdr.fccHandler == MJPG_CC)
            {
                uint8_t first_digit = (stream_id/10) + '0';
                uint8_t second_digit = (stream_id%10) + '0';

                if(m_stream_id == 0)

            

Reported by Cppcheck.

Uninitialized struct member: strm_hdr.dwScale
Error

Line: 341 CWE codes: 908

                              if(m_stream_id == 0)
                {
                    m_stream_id = CV_FOURCC(first_digit, second_digit, 'd', 'c');
                    m_fps = double(strm_hdr.dwRate)/strm_hdr.dwScale;
                }
                else
                {
                    //second mjpeg video stream found which is not supported
                    fprintf(stderr, "More than one video stream found within AVI/AVIX list. Stream %c%cdc would be ignored\n", first_digit, second_digit);

            

Reported by Cppcheck.

Uninitialized struct member: avi_hdr.dwFlags
Error

Line: 393 CWE codes: 908

              
        if(m_file_stream)
        {
            m_is_indx_present = ((avi_hdr.dwFlags & 0x10) != 0);
            uint32_t number_of_streams = avi_hdr.dwStreams;
            CV_Assert(number_of_streams < 0xFF);
            m_width = avi_hdr.dwWidth;
            m_height = avi_hdr.dwHeight;


            

Reported by Cppcheck.

Uninitialized struct member: avi_hdr.dwStreams
Error

Line: 394 CWE codes: 908

                      if(m_file_stream)
        {
            m_is_indx_present = ((avi_hdr.dwFlags & 0x10) != 0);
            uint32_t number_of_streams = avi_hdr.dwStreams;
            CV_Assert(number_of_streams < 0xFF);
            m_width = avi_hdr.dwWidth;
            m_height = avi_hdr.dwHeight;

            //the number of strl lists must be equal to number of streams specified in main avi header

            

Reported by Cppcheck.

Uninitialized struct member: avi_hdr.dwWidth
Error

Line: 396 CWE codes: 908

                          m_is_indx_present = ((avi_hdr.dwFlags & 0x10) != 0);
            uint32_t number_of_streams = avi_hdr.dwStreams;
            CV_Assert(number_of_streams < 0xFF);
            m_width = avi_hdr.dwWidth;
            m_height = avi_hdr.dwHeight;

            //the number of strl lists must be equal to number of streams specified in main avi header
            for(uint32_t i = 0; i < number_of_streams; ++i)
            {

            

Reported by Cppcheck.

Uninitialized struct member: avi_hdr.dwHeight
Error

Line: 397 CWE codes: 908

                          uint32_t number_of_streams = avi_hdr.dwStreams;
            CV_Assert(number_of_streams < 0xFF);
            m_width = avi_hdr.dwWidth;
            m_height = avi_hdr.dwHeight;

            //the number of strl lists must be equal to number of streams specified in main avi header
            for(uint32_t i = 0; i < number_of_streams; ++i)
            {
                m_file_stream->seekg(next_strl_list);

            

Reported by Cppcheck.

Uninitialized struct member: strl_list.m_size
Error

Line: 410 CWE codes: 908

                              {
                    next_strl_list = m_file_stream->tellg();
                    //RiffList::m_size includes fourCC field which we have already read
                    next_strl_list += (strl_list.m_size - 4);

                    result = parseStrl((char)i, codec_);
                }
                else
                {

            

Reported by Cppcheck.

Uninitialized struct member: hdrl_list.m_size
Error

Line: 438 CWE codes: 908

                  {
        uint64_t next_list = m_file_stream->tellg();
        //RiffList::m_size includes fourCC field which we have already read
        next_list += (hdrl_list.m_size - 4);
        //parseHdrlList sets m_is_indx_present flag which would be used later
        if(parseHdrlList(codec_))
        {
            m_file_stream->seekg(next_list);


            

Reported by Cppcheck.

samples/python/tutorial_code/core/mat_operations/mat_operations.py
13 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              from __future__ import division
import cv2 as cv
import numpy as np

# Snippet code for Operations with images tutorial (not intended to be run)

def load():
    # Input/Output
    filename = 'img.jpg'

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              from __future__ import division
import cv2 as cv
import numpy as np

# Snippet code for Operations with images tutorial (not intended to be run)

def load():
    # Input/Output
    filename = 'img.jpg'

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 7 Column: 1

              
# Snippet code for Operations with images tutorial (not intended to be run)

def load():
    # Input/Output
    filename = 'img.jpg'
    ## [Load an image from a file]
    img = cv.imread(filename)
    ## [Load an image from a file]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 1

                  cv.imwrite(filename, img)
    ## [Save image]

def access_pixel():
    # Accessing pixel intensity values
    img = np.empty((4,4,3), np.uint8)
    y = 0
    x = 0
    ## [Pixel access 1]

            

Reported by Pylint.

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

Line: 25 Column: 5

              def access_pixel():
    # Accessing pixel intensity values
    img = np.empty((4,4,3), np.uint8)
    y = 0
    x = 0
    ## [Pixel access 1]
    _intensity = img[y,x]
    ## [Pixel access 1]


            

Reported by Pylint.

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

Line: 26 Column: 5

                  # Accessing pixel intensity values
    img = np.empty((4,4,3), np.uint8)
    y = 0
    x = 0
    ## [Pixel access 1]
    _intensity = img[y,x]
    ## [Pixel access 1]

    ## [Pixel access 3]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 41 Column: 1

                  img[y,x] = 128
    ## [Pixel access 5]

def reference_counting():
    # Memory management and reference counting
    ## [Reference counting 2]
    img = cv.imread('image.jpg')
    _img1 = np.copy(img)
    ## [Reference counting 2]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 53 Column: 1

                  _sobelx = cv.Sobel(img, cv.CV_32F, 1, 0)
    ## [Reference counting 3]

def primitive_operations():
    img = np.empty((4,4,3), np.uint8)
    ## [Set image to black]
    img[:] = 0
    ## [Set image to black]


            

Reported by Pylint.

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

Line: 60 Column: 5

                  ## [Set image to black]

    ## [Select ROI]
    _smallImg = img[10:110,10:110]
    ## [Select ROI]

    ## [BGR to Gray]
    img = cv.imread('image.jpg')
    _grey = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 73 Column: 1

                  _dst = src.astype(np.float32)
    ## [Convert to CV_32F]

def visualize_images():
    ## [imshow 1]
    img = cv.imread('image.jpg')
    cv.namedWindow('image', cv.WINDOW_AUTOSIZE)
    cv.imshow('image', img)
    cv.waitKey()

            

Reported by Pylint.

modules/core/misc/java/src/java/core+MatOfRotatedRect.java
13 issues
Overridable method 'fromArray' called during object construction
Error

Line: 39

              
    public MatOfRotatedRect(RotatedRect...a) {
        super();
        fromArray(a);
    }

    public void alloc(int elemNumber) {
        if(elemNumber>0)
            super.create(elemNumber, 1, CvType.makeType(_depth, _channels));

            

Reported by PMD.

No need to import a type that lives in the same package
Error

Line: 6

              import java.util.Arrays;
import java.util.List;

import org.opencv.core.RotatedRect;



public class MatOfRotatedRect extends Mat {
    // 32FC5

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 72

                      float buff[] = new float[_channels];
        for(int i=0; i<num; i++) {
            get(i, 0, buff); //TODO: check ret val!
            a[i] = new RotatedRect(new Point(buff[0],buff[1]),new Size(buff[2],buff[3]),buff[4]);
        }
        return a;
    }

    public void fromList(List<RotatedRect> lr) {

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 72

                      float buff[] = new float[_channels];
        for(int i=0; i<num; i++) {
            get(i, 0, buff); //TODO: check ret val!
            a[i] = new RotatedRect(new Point(buff[0],buff[1]),new Size(buff[2],buff[3]),buff[4]);
        }
        return a;
    }

    public void fromList(List<RotatedRect> lr) {

            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '52'-'55').
Error

Line: 52

                          return;
        int num = a.length;
        alloc(num);
        float buff[] = new float[num * _channels];
        for(int i=0; i<num; i++) {
            RotatedRect r = a[i];
            buff[_channels*i+0] = (float) r.center.x;
            buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '55'-'56').
Error

Line: 55

                      float buff[] = new float[num * _channels];
        for(int i=0; i<num; i++) {
            RotatedRect r = a[i];
            buff[_channels*i+0] = (float) r.center.x;
            buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;
            buff[_channels*i+3] = (float) r.size.height;
            buff[_channels*i+4] = (float) r.angle;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '56'-'57').
Error

Line: 56

                      for(int i=0; i<num; i++) {
            RotatedRect r = a[i];
            buff[_channels*i+0] = (float) r.center.x;
            buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;
            buff[_channels*i+3] = (float) r.size.height;
            buff[_channels*i+4] = (float) r.angle;
        }
        put(0, 0, buff); //TODO: check ret val!

            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '57'-'58').
Error

Line: 57

                          RotatedRect r = a[i];
            buff[_channels*i+0] = (float) r.center.x;
            buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;
            buff[_channels*i+3] = (float) r.size.height;
            buff[_channels*i+4] = (float) r.angle;
        }
        put(0, 0, buff); //TODO: check ret val!
    }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '58'-'59').
Error

Line: 58

                          buff[_channels*i+0] = (float) r.center.x;
            buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;
            buff[_channels*i+3] = (float) r.size.height;
            buff[_channels*i+4] = (float) r.angle;
        }
        put(0, 0, buff); //TODO: check ret val!
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'buff' (lines '59'-'55').
Error

Line: 59

                          buff[_channels*i+1] = (float) r.center.y;
            buff[_channels*i+2] = (float) r.size.width;
            buff[_channels*i+3] = (float) r.size.height;
            buff[_channels*i+4] = (float) r.angle;
        }
        put(0, 0, buff); //TODO: check ret val!
    }

    public RotatedRect[] toArray() {

            

Reported by PMD.

modules/python/test/test_texture_flow.py
13 issues
Unable to import 'cv2'
Error

Line: 14 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests



            

Reported by Pylint.

Unused import sys
Error

Line: 15 Column: 1

              
import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests


class texture_flow_test(NewOpenCVTests):

            

Reported by Pylint.

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

Line: 15 Column: 1

              
import numpy as np
import cv2 as cv
import sys

from tests_common import NewOpenCVTests


class texture_flow_test(NewOpenCVTests):

            

Reported by Pylint.

Missing class docstring
Error

Line: 20 Column: 1

              from tests_common import NewOpenCVTests


class texture_flow_test(NewOpenCVTests):

    def test_texture_flow(self):

        img = self.get_sample('samples/data/chessboard.png')


            

Reported by Pylint.

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

Line: 20 Column: 1

              from tests_common import NewOpenCVTests


class texture_flow_test(NewOpenCVTests):

    def test_texture_flow(self):

        img = self.get_sample('samples/data/chessboard.png')


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 22 Column: 5

              
class texture_flow_test(NewOpenCVTests):

    def test_texture_flow(self):

        img = self.get_sample('samples/data/chessboard.png')

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        h, w = img.shape[:2]

            

Reported by Pylint.

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

Line: 27 Column: 12

                      img = self.get_sample('samples/data/chessboard.png')

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        h, w = img.shape[:2]

        eigen = cv.cornerEigenValsAndVecs(gray, 5, 3)
        eigen = eigen.reshape(h, w, 3, 2)  # [[e1, e2], v1, v2]
        flow = eigen[:,:,2]


            

Reported by Pylint.

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

Line: 27 Column: 9

                      img = self.get_sample('samples/data/chessboard.png')

        gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)
        h, w = img.shape[:2]

        eigen = cv.cornerEigenValsAndVecs(gray, 5, 3)
        eigen = eigen.reshape(h, w, 3, 2)  # [[e1, e2], v1, v2]
        flow = eigen[:,:,2]


            

Reported by Pylint.

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

Line: 33 Column: 9

                      eigen = eigen.reshape(h, w, 3, 2)  # [[e1, e2], v1, v2]
        flow = eigen[:,:,2]

        d = 300
        eps = d / 30

        points =  np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)

        textureVectors = []

            

Reported by Pylint.

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

Line: 38 Column: 9

              
        points =  np.dstack( np.mgrid[d/2:w:d, d/2:h:d] ).reshape(-1, 2)

        textureVectors = []
        for x, y in np.int32(points):
            textureVectors.append(np.int32(flow[y, x]*d))

        for i in range(len(textureVectors)):
            self.assertTrue(cv.norm(textureVectors[i], cv.NORM_L2) < eps

            

Reported by Pylint.

samples/python/tutorial_code/ml/py_svm_opencv/hogsvm.py
13 issues
Unable to import 'cv2'
Error

Line: 3 Column: 1

              #!/usr/bin/env python

import cv2 as cv
import numpy as np

SZ=20
bin_n = 16 # Number of bins



            

Reported by Pylint.

Too many positional arguments for method call
Error

Line: 51 Column: 13

              
deskewed = [list(map(deskew,row)) for row in train_cells]
hogdata = [list(map(hog,row)) for row in deskewed]
trainData = np.float32(hogdata).reshape(-1,64)
responses = np.repeat(np.arange(10),250)[:,np.newaxis]

svm = cv.ml.SVM_create()
svm.setKernel(cv.ml.SVM_LINEAR)
svm.setType(cv.ml.SVM_C_SVC)

            

Reported by Pylint.

Too many positional arguments for method call
Error

Line: 67 Column: 12

              
deskewed = [list(map(deskew,row)) for row in test_cells]
hogdata = [list(map(hog,row)) for row in deskewed]
testData = np.float32(hogdata).reshape(-1,bin_n*4)
result = svm.predict(testData)[1]

#######   Check Accuracy   ########################
mask = result==responses
correct = np.count_nonzero(mask)

            

Reported by Pylint.

Redefining name 'img' from outer scope (line 36)
Error

Line: 13 Column: 12

              affine_flags = cv.WARP_INVERSE_MAP|cv.INTER_LINEAR

## [deskew]
def deskew(img):
    m = cv.moments(img)
    if abs(m['mu02']) < 1e-2:
        return img.copy()
    skew = m['mu11']/m['mu02']
    M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]])

            

Reported by Pylint.

Redefining name 'img' from outer scope (line 36)
Error

Line: 24 Column: 9

              ## [deskew]

## [hog]
def hog(img):
    gx = cv.Sobel(img, cv.CV_32F, 1, 0)
    gy = cv.Sobel(img, cv.CV_32F, 0, 1)
    mag, ang = cv.cartToPolar(gx, gy)
    bins = np.int32(bin_n*ang/(2*np.pi))    # quantizing binvalues in (0...16)
    bin_cells = bins[:10,:10], bins[10:,:10], bins[:10,10:], bins[10:,10:]

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              #!/usr/bin/env python

import cv2 as cv
import numpy as np

SZ=20
bin_n = 16 # Number of bins



            

Reported by Pylint.

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

Line: 7 Column: 1

              import numpy as np

SZ=20
bin_n = 16 # Number of bins


affine_flags = cv.WARP_INVERSE_MAP|cv.INTER_LINEAR

## [deskew]

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 13 Column: 1

              affine_flags = cv.WARP_INVERSE_MAP|cv.INTER_LINEAR

## [deskew]
def deskew(img):
    m = cv.moments(img)
    if abs(m['mu02']) < 1e-2:
        return img.copy()
    skew = m['mu11']/m['mu02']
    M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]])

            

Reported by Pylint.

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

Line: 14 Column: 5

              
## [deskew]
def deskew(img):
    m = cv.moments(img)
    if abs(m['mu02']) < 1e-2:
        return img.copy()
    skew = m['mu11']/m['mu02']
    M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]])
    img = cv.warpAffine(img,M,(SZ, SZ),flags=affine_flags)

            

Reported by Pylint.

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

Line: 18 Column: 5

                  if abs(m['mu02']) < 1e-2:
        return img.copy()
    skew = m['mu11']/m['mu02']
    M = np.float32([[1, skew, -0.5*SZ*skew], [0, 1, 0]])
    img = cv.warpAffine(img,M,(SZ, SZ),flags=affine_flags)
    return img
## [deskew]

## [hog]

            

Reported by Pylint.

samples/python/watershed.py
13 issues
Unable to import 'cv2'
Error

Line: 29 Column: 1

              from __future__ import print_function

import numpy as np
import cv2 as cv
from common import Sketcher

class App:
    def __init__(self, fn):
        self.img = cv.imread(fn)

            

Reported by Pylint.

Redefining name 'fn' from outer scope (line 82)
Error

Line: 33 Column: 24

              from common import Sketcher

class App:
    def __init__(self, fn):
        self.img = cv.imread(fn)
        if self.img is None:
            raise Exception('Failed to load image file: %s' % fn)

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

            

Reported by Pylint.

No exception type(s) specified
Error

Line: 83 Column: 5

                  import sys
    try:
        fn = sys.argv[1]
    except:
        fn = 'fruits.jpg'
    App(cv.samples.findFile(fn)).run()

            

Reported by Pylint.

Missing class docstring
Error

Line: 32 Column: 1

              import cv2 as cv
from common import Sketcher

class App:
    def __init__(self, fn):
        self.img = cv.imread(fn)
        if self.img is None:
            raise Exception('Failed to load image file: %s' % fn)


            

Reported by Pylint.

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

Line: 38 Column: 9

                      if self.img is None:
            raise Exception('Failed to load image file: %s' % fn)

        h, w = self.img.shape[:2]
        self.markers = np.zeros((h, w), np.int32)
        self.markers_vis = self.img.copy()
        self.cur_marker = 1
        self.colors = np.int32( list(np.ndindex(2, 2, 2)) ) * 255


            

Reported by Pylint.

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

Line: 38 Column: 12

                      if self.img is None:
            raise Exception('Failed to load image file: %s' % fn)

        h, w = self.img.shape[:2]
        self.markers = np.zeros((h, w), np.int32)
        self.markers_vis = self.img.copy()
        self.cur_marker = 1
        self.colors = np.int32( list(np.ndindex(2, 2, 2)) ) * 255


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 47 Column: 5

                      self.auto_update = True
        self.sketch = Sketcher('img', [self.markers_vis, self.markers], self.get_colors)

    def get_colors(self):
        return list(map(int, self.colors[self.cur_marker])), self.cur_marker

    def watershed(self):
        m = self.markers.copy()
        cv.watershed(self.img, m)

            

Reported by Pylint.

Missing function or method docstring
Error

Line: 50 Column: 5

                  def get_colors(self):
        return list(map(int, self.colors[self.cur_marker])), self.cur_marker

    def watershed(self):
        m = self.markers.copy()
        cv.watershed(self.img, m)
        overlay = self.colors[np.maximum(m, 0)]
        vis = cv.addWeighted(self.img, 0.5, overlay, 0.5, 0.0, dtype=cv.CV_8UC3)
        cv.imshow('watershed', vis)

            

Reported by Pylint.

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

Line: 51 Column: 9

                      return list(map(int, self.colors[self.cur_marker])), self.cur_marker

    def watershed(self):
        m = self.markers.copy()
        cv.watershed(self.img, m)
        overlay = self.colors[np.maximum(m, 0)]
        vis = cv.addWeighted(self.img, 0.5, overlay, 0.5, 0.0, dtype=cv.CV_8UC3)
        cv.imshow('watershed', vis)


            

Reported by Pylint.

Missing function or method docstring
Error

Line: 57 Column: 5

                      vis = cv.addWeighted(self.img, 0.5, overlay, 0.5, 0.0, dtype=cv.CV_8UC3)
        cv.imshow('watershed', vis)

    def run(self):
        while cv.getWindowProperty('img', 0) != -1 or cv.getWindowProperty('watershed', 0) != -1:
            ch = cv.waitKey(50)
            if ch == 27:
                break
            if ch >= ord('1') and ch <= ord('7'):

            

Reported by Pylint.