title: Use VideoCapture() in two different function within same class OpenCV Python
body: <p>I'm making a GUI in which one button will display the video and another button will start capturing frames from that video at certain intervals. </p>
  
  <p>Here, are the functions that are called by the buttons:-</p>
  
  <pre><code>def capture(self):
      global img_location
      global camera
  
      camera = cv2.VideoCapture(1)
      return_value, image = camera.read()
      time.sleep(2)   #set the delay you want in frame
      now_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
  
      img_location = './timelapse_focus/'+FolderName+'/'+ now_time +'.jpg'
      cv2.imwrite(img_location, image)
      del(camera)
  
  
  def display(self):
      # Create a VideoCapture object and read from input file
      # If the input is the camera, pass 0 instead of the video file name
  
      # Check if camera opened successfully
      camera = cv2.VideoCapture(1)
      if (camera.isOpened()== False): 
        print("Error opening video stream or file")
  
      # Read until video is completed
      while(camera.isOpened()):
        # Capture frame-by-frame
        ret, frame = camera.read()
        if ret == True:
  
          # Display the resulting frame
          cv2.imshow('Frame',frame)
  
          # Press &lt;q&gt; on keyboard to  exit
          if cv2.waitKey(25) &amp; 0xFF == ord('q'):
            break
  
        # Break the loop
        else: 
          break
  
      # When everything done, release the video capture object
      camera.release()
  
      # Closes all the frames
      cv2.destroyAllWindows()
      for i in range (1,5):
          cv2.waitKey(1)
  </code></pre>
  
  <p>It's showing the following error:-</p>
  
  <pre><code>HIGHGUI ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
  VIDIOC_STREAMON: Bad file descriptor
  Unable to stop the stream.: Bad file descriptor
  </code></pre>
  
  <p>To do the same I tried to declare the camera variable globally. 
  But it's not working. Even I used <code>self. camera</code>, it is also not working. 
  Please suggest something. </p>