title: Passing an image as a function parameter in python
body: <p>I am trying to pass an image file as a function parameter in python but there is an error in it and I can't see the possible cause of it. I have to convert this image to grayscaleand show it as an output if g = 1 else I have to output the same image as it is. I have saved the code at the same place where I have stored the image. </p>
  
  <pre><code>import cv2
  
  def color_grayscale(filename, g):
      img = cv2.imread(filename)
      grayscale_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
      if g==1:
          img = grayscale_img
      cv2.imshow('image',img)
  
  color_grayscale('test_img1.jpg',1)
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:/Users/NOOR BRAR/Documents/College Stuff/5th SEM/e-yantra/task1/PS1_Task1/Task1_Practice/test_images/coeinsog", line 10, in &lt;module&gt;
  color_grayscale('test_img1.jpg',1)
  File "C:/Users/NOOR BRAR/Documents/College Stuff/5th SEM/e-yantra/task1/PS1_Task1/Task1_Practice/test_images/coeinsog", line 5, in color_grayscale
  grayscale_img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  error: ..\..\..\..\opencv\modules\imgproc\src\color.cpp:3737: error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
  </code></pre>