class_docstr: PiGear is similar to CamGear API but exclusively made to support various Raspberry Pi Camera Modules (such as OmniVision OV5647 Camera Module and Sony IMX219 Camera Module).
  PiGear provides a flexible multi-threaded framework around complete picamera python library, and provide us the ability to exploit almost all of its parameters like brightness,
  saturation, sensor_mode, iso, exposure, etc. effortlessly. Furthermore, PiGear also supports multiple camera modules, such as in the case of Raspberry-Pi Compute Module IO boards.
  
  Best of all, PiGear contains Threaded Internal Timer - that silently keeps active track of any frozen-threads/hardware-failures and exit safely, if any does occur. That means that
  if you're running PiGear API in your script and someone accidentally pulls the Camera-Module cable out, instead of going into possible kernel panic, API will exit safely to save resources.
  
  !!! warning "Make sure to enable [Raspberry Pi hardware-specific settings](https://picamera.readthedocs.io/en/release-1.13/quickstart.html) prior using this API, otherwise nothing will work."
class_docstr_tok: ["PiGear","is","similar","to","CamGear","API","but","exclusively","made","to","support","various","Raspberry","Pi","Camera","Modules","(","such","as","OmniVision","OV5647","Camera","Module","and","Sony","IMX219","Camera","Module",")",".","PiGear","provides","a","flexible","multi-threaded","framework","around","complete","picamera","python","library",",","and","provide","us","the","ability","to","exploit","almost","all","of","its","parameters","like","brightness",",","saturation",",","sensor_mode",",","iso",",","exposure",",","etc",".","effortlessly",".","Furthermore",",","PiGear","also","supports","multiple","camera","modules",",","such","as","in","the","case","of","Raspberry-Pi","Compute","Module","IO","boards",".","Best","of","all",",","PiGear","contains","Threaded","Internal","Timer","-","that","silently","keeps","active","track","of","any","frozen-threads\/hardware-failures","and","exit","safely",",","if","any","does","occur",".","That","means","that","if","you","'re","running","PiGear","API","in","your","script","and","someone","accidentally","pulls","the","Camera-Module","cable","out",",","instead","of","going","into","possible","kernel","panic",",","API","will","exit","safely","to","save","resources",".","!","!","!","warning","``","Make","sure","to","enable","[","Raspberry","Pi","hardware-specific","settings","]","(","https",":","\/\/picamera.readthedocs.io\/en\/release-1.13\/quickstart.html",")","prior","using","this","API",",","otherwise","nothing","will","work",".","''"]
docstr: This constructor method initializes the object state and attributes of the PiGear class.
  
  Parameters:
      camera_num (int): selects the camera module index which will be used as source.
      resolution (tuple): sets the resolution (i.e. `(width,height)`) of the source..
      framerate (int/float): sets the framerate of the source.
      colorspace (str): selects the colorspace of the input stream.
      logging (bool): enables/disables logging.
      time_delay (int): time delay (in sec) before start reading the frames.
      options (dict): provides ability to alter Source Tweak Parameters.
docstr_tok: ["This","constructor","method","initializes","the","object","state","and","attributes","of","the","PiGear","class",".","Parameters",":","camera_num","(","int",")",":","selects","the","camera","module","index","which","will","be","used","as","source",".","resolution","(","tuple",")",":","sets","the","resolution","(","i.e",".","`","(","width",",","height",")","`",")","of","the","source","..","framerate","(","int\/float",")",":","sets","the","framerate","of","the","source",".","colorspace","(","str",")",":","selects","the","colorspace","of","the","input","stream",".","logging","(","bool",")",":","enables\/disables","logging",".","time_delay","(","int",")",":","time","delay","(","in","sec",")","before","start","reading","the","frames",".","options","(","dict",")",":","provides","ability","to","alter","Source","Tweak","Parameters","."]
code: def __init__(
      self,
      camera_num=0,
      resolution=(640, 480),
      framerate=30,
      colorspace=None,
      logging=False,
      time_delay=0,
      **options,
  ):
      """
      This constructor method initializes the object state and attributes of the PiGear class.
  
      Parameters:
          camera_num (int): selects the camera module index which will be used as source.
          resolution (tuple): sets the resolution (i.e. `(width,height)`) of the source..
          framerate (int/float): sets the framerate of the source.
          colorspace (str): selects the colorspace of the input stream.
          logging (bool): enables/disables logging.
          time_delay (int): time delay (in sec) before start reading the frames.
          options (dict): provides ability to alter Source Tweak Parameters.
      """
      # print current version
      logcurr_vidgear_ver(logging=logging)
  
      # raise error(s) for critical Class imports
      import_dependency_safe(
          "picamera" if picamera is None else "",
      )
  
      # enable logging if specified
      self.__logging = False
      if logging:
          self.__logging = logging
  
      assert (
          isinstance(framerate, (int, float)) and framerate > 5.0
      ), "[PiGear:ERROR] :: Input framerate value `{}` is a Invalid! Kindly read docs.".format(
          framerate
      )
      assert (
          isinstance(resolution, (tuple, list)) and len(resolution) == 2
      ), "[PiGear:ERROR] :: Input resolution value `{}` is a Invalid! Kindly read docs.".format(
          resolution
      )
      if not (isinstance(camera_num, int) and camera_num >= 0):
          camera_num = 0
          logger.warning(
              "Input camera_num value `{}` is invalid, Defaulting to index 0!"
          )
  
      # initialize the picamera stream at given index
      self.__camera = PiCamera(camera_num=camera_num)
      self.__camera.resolution = tuple(resolution)
      self.__camera.framerate = framerate
      self.__logging and logger.debug(
          "Activating Pi camera at index: {} with resolution: {} & framerate: {}".format(
              camera_num, resolution, framerate
          )
      )
  
      # initialize framerate variable
      self.framerate = framerate
  
      # initializing colorspace variable
      self.color_space = None
  
      # reformat dict
      options = {str(k).strip(): v for k, v in options.items()}
  
      # define timeout variable default value(handles hardware failures)
      self.__failure_timeout = options.pop("HWFAILURE_TIMEOUT", 2.0)
      if isinstance(self.__failure_timeout, (int, float)):
          if not (10.0 > self.__failure_timeout > 1.0):
              raise ValueError(
                  "[PiGear:ERROR] :: `HWFAILURE_TIMEOUT` value can only be between 1.0 ~ 10.0"
              )
          self.__logging and logger.debug(
              "Setting HW Failure Timeout: {} seconds".format(
                  self.__failure_timeout
              )
          )
      else:
          # reset improper values
          self.__failure_timeout = 2.0
  
      try:
          # apply attributes to source if specified
          for key, value in options.items():
              self.__logging and logger.debug(
                  "Setting Parameter: {} = '{}'".format(key, value)
              )
              setattr(self.__camera, key, value)
      except Exception as e:
          # Catch if any error occurred
          logger.exception(str(e))
  
      # separately handle colorspace value to int conversion
      if not (colorspace is None):
          self.color_space = capPropId(colorspace.strip())
          if self.__logging and not (self.color_space is None):
              logger.debug(
                  "Enabling `{}` colorspace for this video stream!".format(
                      colorspace.strip()
                  )
              )
  
      # enable rgb capture array thread and capture stream
      self.__rawCapture = PiRGBArray(self.__camera, size=resolution)
      self.stream = self.__camera.capture_continuous(
          self.__rawCapture, format="bgr", use_video_port=True
      )
  
      # frame variable initialization
      self.frame = None
      try:
          stream = next(self.stream)
          self.frame = stream.array
          self.__rawCapture.seek(0)
          self.__rawCapture.truncate()
          # render colorspace if defined
          if not (self.frame is None) and not (
              self.color_space is None
          ):
              self.frame = cv2.cvtColor(self.frame, self.color_space)
      except Exception as e:
          logger.exception(str(e))
          raise RuntimeError(
              "[PiGear:ERROR] :: Camera Module failed to initialize!"
          )
  
      # applying time delay to warm-up picamera only if specified
      if time_delay and isinstance(time_delay, (int, float)):
          time.sleep(time_delay)
  
      # thread initialization
      self.__thread = None
  
      # timer thread initialization(Keeps check on frozen thread)
      self.__timer = None
      self.__t_elasped = 0.0  # records time taken by thread
  
      # catching thread exceptions
      self.__exceptions = None
  
      # initialize termination flag
      self.__terminate = False
  
file_path: vidgear/vidgear/gears/pigear.py
imports: import cv2
  import sys
  import time
  import logging
  from threading import Thread
  from .helper import capPropId, logger_handler, import_dependency_safe, logcurr_vidgear_ver
label_desc: Use image node_id 1 to create a new PiGear object  with example: obj = PiGear(camera_num, resolution, framerate, colorspace, logging, time_delay)