0

My function

import numpy as np


def region_of_interest(image):
    
    
    height = image.shape[0]
    
    #pixel value to be filled in mask
    #as value on depends on the number of channel
    if len(img.shape) > 2: 
        mask_color_ignore = (255,) * img.shape[2]
    else:
        mask_color_ignore = 255
        
    #shape of our interest
    triangle = np.array([[(0, (5/6)*height), (900, (5/6)*height), (400, (1/6)*height)]])

    mask = np.zeros_like(image)
    try:
        cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )
    except Exception as e:
        print(e)
    return mask

error coming out

cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )
                                                                                         ^
SyntaxError: positional argument follows keyword argument

please help me understand the reason of error and why it is coming here i am pretty new to openCv

desertnaut
  • 57,590
  • 26
  • 140
  • 166
dhruv singhal
  • 73
  • 3
  • 9
  • Exactly as the error message says. In python non-keyword arguments must come before keyword arguments. You have `... color=mask_color_ignore, **1**, lineType...`. The 1 needs an attached keyword or be moved before the keyword arguments. – deseuler May 24 '21 at 15:57

1 Answers1

1

In Python (not just opencv), Keyword arguments (parameters that are specified with name=value) must come after positional arguments (parameters that are passed only by value)

Thus in

cv2.polylines(mask, pts = np.int32([triangle]), isClosed=1, color=mask_color_ignore, 1, lineType = LINE_8, shift = 0 )

when you pass 1 after color=mask_color_ignore, you get the error.

best practice will be to also pass 1 as a named argument.

Gulzar
  • 23,452
  • 27
  • 113
  • 201