The following issues were found

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.

samples/python/tutorial_code/video/meanshift/camshift.py
5 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the camshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the camshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

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

Line: 3 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the camshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Unnecessary parens after 'while' keyword
Error

Line: 30 Column: 1

              # Setup the termination criteria, either 10 iteration or move by atleast 1 pt
term_crit = ( cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 10, 1 )

while(1):
    ret, frame = cap.read()

    if ret == True:
        hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
        dst = cv.calcBackProject([hsv],[0],roi_hist,[0,180],1)

            

Reported by Pylint.

Comparison 'ret == True' should be 'ret is True' if checking for the singleton value True, or 'ret' if testing for truthiness
Error

Line: 33 Column: 8

              while(1):
    ret, frame = cap.read()

    if ret == True:
        hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
        dst = cv.calcBackProject([hsv],[0],roi_hist,[0,180],1)

        # apply camshift to get the new location
        ret, track_window = cv.CamShift(dst, track_window, term_crit)

            

Reported by Pylint.

samples/python/tutorial_code/video/meanshift/meanshift.py
5 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the meanshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the meanshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

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

Line: 3 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates the meanshift algorithm. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Unnecessary parens after 'while' keyword
Error

Line: 30 Column: 1

              # Setup the termination criteria, either 10 iteration or move by atleast 1 pt
term_crit = ( cv.TERM_CRITERIA_EPS | cv.TERM_CRITERIA_COUNT, 10, 1 )

while(1):
    ret, frame = cap.read()

    if ret == True:
        hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
        dst = cv.calcBackProject([hsv],[0],roi_hist,[0,180],1)

            

Reported by Pylint.

Comparison 'ret == True' should be 'ret is True' if checking for the singleton value True, or 'ret' if testing for truthiness
Error

Line: 33 Column: 8

              while(1):
    ret, frame = cap.read()

    if ret == True:
        hsv = cv.cvtColor(frame, cv.COLOR_BGR2HSV)
        dst = cv.calcBackProject([hsv],[0],roi_hist,[0,180],1)

        # apply meanshift to get the new location
        ret, track_window = cv.meanShift(dst, track_window, term_crit)

            

Reported by Pylint.

samples/python/tutorial_code/video/optical_flow/optical_flow.py
5 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates Lucas-Kanade Optical Flow calculation. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates Lucas-Kanade Optical Flow calculation. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

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

Line: 3 Column: 1

              import numpy as np
import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates Lucas-Kanade Optical Flow calculation. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()

            

Reported by Pylint.

Line too long (111/100)
Error

Line: 5 Column: 1

              import cv2 as cv
import argparse

parser = argparse.ArgumentParser(description='This sample demonstrates Lucas-Kanade Optical Flow calculation. \
                                              The example file can be downloaded from: \
                                              https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4')
parser.add_argument('image', type=str, help='path to image file')
args = parser.parse_args()


            

Reported by Pylint.

Unnecessary parens after 'while' keyword
Error

Line: 35 Column: 1

              # Create a mask image for drawing purposes
mask = np.zeros_like(old_frame)

while(1):
    ret,frame = cap.read()
    frame_gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

    # calculate optical flow
    p1, st, err = cv.calcOpticalFlowPyrLK(old_gray, frame_gray, p0, None, **lk_params)

            

Reported by Pylint.

samples/python/tutorial_code/video/optical_flow/optical_flow_dense.py
5 issues
Unable to import 'cv2'
Error

Line: 2 Column: 1

              import numpy as np
import cv2 as cv
cap = cv.VideoCapture(cv.samples.findFile("vtest.avi"))
ret, frame1 = cap.read()
prvs = cv.cvtColor(frame1,cv.COLOR_BGR2GRAY)
hsv = np.zeros_like(frame1)
hsv[...,1] = 255
while(1):
    ret, frame2 = cap.read()

            

Reported by Pylint.

Redefining built-in 'next'
Error

Line: 10 Column: 5

              hsv[...,1] = 255
while(1):
    ret, frame2 = cap.read()
    next = cv.cvtColor(frame2,cv.COLOR_BGR2GRAY)
    flow = cv.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
    mag, ang = cv.cartToPolar(flow[...,0], flow[...,1])
    hsv[...,0] = ang*180/np.pi/2
    hsv[...,2] = cv.normalize(mag,None,0,255,cv.NORM_MINMAX)
    bgr = cv.cvtColor(hsv,cv.COLOR_HSV2BGR)

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              import numpy as np
import cv2 as cv
cap = cv.VideoCapture(cv.samples.findFile("vtest.avi"))
ret, frame1 = cap.read()
prvs = cv.cvtColor(frame1,cv.COLOR_BGR2GRAY)
hsv = np.zeros_like(frame1)
hsv[...,1] = 255
while(1):
    ret, frame2 = cap.read()

            

Reported by Pylint.

Unnecessary parens after 'while' keyword
Error

Line: 8 Column: 1

              prvs = cv.cvtColor(frame1,cv.COLOR_BGR2GRAY)
hsv = np.zeros_like(frame1)
hsv[...,1] = 255
while(1):
    ret, frame2 = cap.read()
    next = cv.cvtColor(frame2,cv.COLOR_BGR2GRAY)
    flow = cv.calcOpticalFlowFarneback(prvs,next, None, 0.5, 3, 15, 3, 5, 1.2, 0)
    mag, ang = cv.cartToPolar(flow[...,0], flow[...,1])
    hsv[...,0] = ang*180/np.pi/2

            

Reported by Pylint.

Unnecessary "elif" after "break"
Error

Line: 18 Column: 5

                  bgr = cv.cvtColor(hsv,cv.COLOR_HSV2BGR)
    cv.imshow('frame2',bgr)
    k = cv.waitKey(30) & 0xff
    if k == 27:
        break
    elif k == ord('s'):
        cv.imwrite('opticalfb.png',frame2)
        cv.imwrite('opticalhsv.png',bgr)
    prvs = next

            

Reported by Pylint.

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

Line: 11 Column: 1

              from __future__ import print_function

from glob import glob
import cv2 as cv
import re

if __name__ == '__main__':
    cv2_callable = set(['cv.'+name for name in dir(cv) if callable( getattr(cv, name) )])


            

Reported by Pylint.

Anomalous backslash in string: '\w'. String constant might be missing an r prefix.
Error

Line: 21 Column: 40

                  for fn in glob('*.py'):
        print(' --- ', fn)
        code = open(fn).read()
        found |= set(re.findall('cv2?\.\w+', code))

    cv2_used = found & cv2_callable
    cv2_unused = cv2_callable - cv2_used
    with open('unused_api.txt', 'w') as f:
        f.write('\n'.join(sorted(cv2_unused)))

            

Reported by Pylint.

Anomalous backslash in string: '\.'. String constant might be missing an r prefix.
Error

Line: 21 Column: 38

                  for fn in glob('*.py'):
        print(' --- ', fn)
        code = open(fn).read()
        found |= set(re.findall('cv2?\.\w+', code))

    cv2_used = found & cv2_callable
    cv2_unused = cv2_callable - cv2_used
    with open('unused_api.txt', 'w') as f:
        f.write('\n'.join(sorted(cv2_unused)))

            

Reported by Pylint.

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

Line: 12 Column: 1

              
from glob import glob
import cv2 as cv
import re

if __name__ == '__main__':
    cv2_callable = set(['cv.'+name for name in dir(cv) if callable( getattr(cv, name) )])

    found = set()

            

Reported by Pylint.

Consider using a set comprehension
Error

Line: 15 Column: 20

              import re

if __name__ == '__main__':
    cv2_callable = set(['cv.'+name for name in dir(cv) if callable( getattr(cv, name) )])

    found = set()
    for fn in glob('*.py'):
        print(' --- ', fn)
        code = open(fn).read()

            

Reported by Pylint.

3rdparty/openexr/Imath/ImathExc.h
5 issues
syntax error
Error

Line: 53

              IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

// Attempt to normalize null vector
DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize a point at infinity
DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize null quaternion

            

Reported by Cppcheck.

syntax error
Error

Line: 53

              IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

// Attempt to normalize null vector
DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize a point at infinity
DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize null quaternion

            

Reported by Cppcheck.

syntax error
Error

Line: 53

              IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

// Attempt to normalize null vector
DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize a point at infinity
DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize null quaternion

            

Reported by Cppcheck.

syntax error
Error

Line: 53

              IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

// Attempt to normalize null vector
DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize a point at infinity
DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize null quaternion

            

Reported by Cppcheck.

syntax error
Error

Line: 53

              IMATH_INTERNAL_NAMESPACE_HEADER_ENTER

// Attempt to normalize null vector
DEFINE_EXC_EXP (IMATH_EXPORT, NullVecExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize a point at infinity
DEFINE_EXC_EXP (IMATH_EXPORT, InfPointExc, ::IEX_NAMESPACE::MathExc)

// Attempt to normalize null quaternion

            

Reported by Cppcheck.

modules/gapi/test/gapi_fluid_test_kernels.hpp
5 issues
syntax error
Error

Line: 20

              using cv::gapi::core::GMat3;
using GMat2 = std::tuple<GMat, GMat>;

G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
    static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
        return a;
    }
};


            

Reported by Cppcheck.

syntax error
Error

Line: 20

              using cv::gapi::core::GMat3;
using GMat2 = std::tuple<GMat, GMat>;

G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
    static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
        return a;
    }
};


            

Reported by Cppcheck.

syntax error
Error

Line: 20

              using cv::gapi::core::GMat3;
using GMat2 = std::tuple<GMat, GMat>;

G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
    static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
        return a;
    }
};


            

Reported by Cppcheck.

syntax error
Error

Line: 20

              using cv::gapi::core::GMat3;
using GMat2 = std::tuple<GMat, GMat>;

G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
    static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
        return a;
    }
};


            

Reported by Cppcheck.

syntax error
Error

Line: 20

              using cv::gapi::core::GMat3;
using GMat2 = std::tuple<GMat, GMat>;

G_TYPED_KERNEL(TAddSimple, <GMat(GMat, GMat)>, "test.fluid.add_simple") {
    static cv::GMatDesc outMeta(cv::GMatDesc a, cv::GMatDesc) {
        return a;
    }
};


            

Reported by Cppcheck.

samples/dnn/shrink_tf_graph_weights.py
5 issues
Unable to import 'tensorflow'
Error

Line: 7 Column: 1

              #
# Copyright (C) 2017, Intel Corporation, all rights reserved.
# Third party copyrights are property of their respective owners.
import tensorflow as tf
import struct
import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Convert weights of a frozen TensorFlow graph to fp16.')

            

Reported by Pylint.

Missing module docstring
Error

Line: 1 Column: 1

              # This file is part of OpenCV project.
# It is subject to the license terms in the LICENSE file found in the top-level directory
# of this distribution and at http://opencv.org/license.html.
#
# Copyright (C) 2017, Intel Corporation, all rights reserved.
# Third party copyrights are property of their respective owners.
import tensorflow as tf
import struct
import argparse

            

Reported by Pylint.

standard import "import struct" should be placed before "import tensorflow as tf"
Error

Line: 8 Column: 1

              # Copyright (C) 2017, Intel Corporation, all rights reserved.
# Third party copyrights are property of their respective owners.
import tensorflow as tf
import struct
import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Convert weights of a frozen TensorFlow graph to fp16.')
parser.add_argument('--input', required=True, help='Path to frozen graph.')

            

Reported by Pylint.

standard import "import argparse" should be placed before "import tensorflow as tf"
Error

Line: 9 Column: 1

              # Third party copyrights are property of their respective owners.
import tensorflow as tf
import struct
import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Convert weights of a frozen TensorFlow graph to fp16.')
parser.add_argument('--input', required=True, help='Path to frozen graph.')
parser.add_argument('--output', required=True, help='Path to output graph.')

            

Reported by Pylint.

Line too long (101/100)
Error

Line: 12 Column: 1

              import argparse
import numpy as np

parser = argparse.ArgumentParser(description='Convert weights of a frozen TensorFlow graph to fp16.')
parser.add_argument('--input', required=True, help='Path to frozen graph.')
parser.add_argument('--output', required=True, help='Path to output graph.')
parser.add_argument('--ops', default=['Conv2D', 'MatMul'], nargs='+',
                    help='List of ops which weights are converted.')
args = parser.parse_args()

            

Reported by Pylint.