docstr: API for human video segmentation.
  
  Args:
     video_path (str): The path to take the video under preprocess. If video_path is None, it will capture
     the vedio from your camera.
     use_gpu (bool): Whether to use gpu.
     save_dir (str): The path to store output video.
docstr_tok: ["API","for","human","video","segmentation",".","Args",":","video_path","(","str",")",":","The","path","to","take","the","video","under","preprocess",".","If","video_path","is","None",",","it","will","capture","the","vedio","from","your","camera",".","use_gpu","(","bool",")",":","Whether","to","use","gpu",".","save_dir","(","str",")",":","The","path","to","store","output","video","."]
code: def video_segment(
      self,
      video_path=None,
      use_gpu=False,
      save_dir="humanseg_lite_video_result",
  ):
      """
      API for human video segmentation.
  
      Args:
         video_path (str): The path to take the video under preprocess. If video_path is None, it will capture
         the vedio from your camera.
         use_gpu (bool): Whether to use gpu.
         save_dir (str): The path to store output video.
  
      """
      if use_gpu:
          try:
              _places = os.environ["CUDA_VISIBLE_DEVICES"]
              int(_places[0])
          except:
              raise RuntimeError(
                  "Environment Variable CUDA_VISIBLE_DEVICES is not set correctly. "
                  "If you wanna use gpu, please set CUDA_VISIBLE_DEVICES as cuda_device_id."
              )
  
      resize_h = 192
      resize_w = 192
      if not video_path:
          cap_video = cv2.VideoCapture(0)
      else:
          cap_video = cv2.VideoCapture(video_path)
  
      if not cap_video.isOpened():
          raise IOError(
              "Error opening video stream or file, "
              "--video_path whether existing: {}"
              " or camera whether working".format(video_path)
          )
  
      width = int(cap_video.get(cv2.CAP_PROP_FRAME_WIDTH))
      height = int(cap_video.get(cv2.CAP_PROP_FRAME_HEIGHT))
      disflow = cv2.DISOpticalFlow_create(
          cv2.DISOPTICAL_FLOW_PRESET_ULTRAFAST
      )
      prev_gray = np.zeros((resize_h, resize_w), np.uint8)
      prev_cfd = np.zeros((resize_h, resize_w), np.float32)
      is_init = True
      fps = cap_video.get(cv2.CAP_PROP_FPS)
  
      if video_path is not None:
          print("Please wait. It is computing......")
          if not osp.exists(save_dir):
              os.makedirs(save_dir)
          save_path = osp.join(save_dir, "result" + ".avi")
          cap_out = cv2.VideoWriter(
              save_path,
              cv2.VideoWriter_fourcc("M", "J", "P", "G"),
              fps,
              (width, height),
          )
  
          while cap_video.isOpened():
              ret, frame_org = cap_video.read()
              if ret:
                  frame = preprocess_v(frame_org, resize_w, resize_h)
  
                  predictor = (
                      self.gpu_predictor
                      if use_gpu
                      else self.cpu_predictor
                  )
                  input_names = predictor.get_input_names()
                  input_handle = predictor.get_input_handle(
                      input_names[0]
                  )
                  input_handle.copy_from_cpu(frame.copy()[None, ...])
                  predictor.run()
                  output_names = predictor.get_output_names()
                  output_handle = predictor.get_output_handle(
                      output_names[1]
                  )
                  score_map = output_handle.copy_to_cpu()
  
                  frame = np.transpose(frame, axes=[1, 2, 0])
                  score_map = np.transpose(
                      np.squeeze(score_map, 0), axes=[1, 2, 0]
                  )
                  cur_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                  cur_gray = cv2.resize(cur_gray, (resize_w, resize_h))
                  score_map = 255 * score_map[:, :, 1]
                  optflow_map = postprocess_v(
                      cur_gray,
                      score_map,
                      prev_gray,
                      prev_cfd,
                      disflow,
                      is_init,
                  )
                  prev_gray = cur_gray.copy()
                  prev_cfd = optflow_map.copy()
  
                  optflow_map = cv2.GaussianBlur(optflow_map, (3, 3), 0)
                  optflow_map = threshold_mask(
                      optflow_map, thresh_bg=0.2, thresh_fg=0.8
                  )
                  img_matting = cv2.resize(
                      optflow_map, (width, height), cv2.INTER_LINEAR
                  )
                  img_matting = np.repeat(
                      img_matting[:, :, np.newaxis], 3, axis=2
                  )
                  bg_im = np.ones_like(img_matting) * 255
                  comb = (
                      img_matting * frame_org
                      + (1 - img_matting) * bg_im
                  ).astype(np.uint8)
                  cap_out.write(comb)
              else:
                  break
          cap_video.release()
          cap_out.release()
      else:
          while cap_video.isOpened():
              ret, frame_org = cap_video.read()
              if ret:
                  frame = preprocess_v(frame_org, resize_w, resize_h)
  
                  predictor = (
                      self.gpu_predictor
                      if use_gpu
                      else self.cpu_predictor
                  )
                  input_names = predictor.get_input_names()
                  input_handle = predictor.get_input_handle(
                      input_names[0]
                  )
                  input_handle.copy_from_cpu(frame.copy()[None, ...])
                  predictor.run()
                  output_names = predictor.get_output_names()
                  output_handle = predictor.get_output_handle(
                      output_names[1]
                  )
                  score_map = output_handle.copy_to_cpu()
  
                  frame = np.transpose(frame, axes=[1, 2, 0])
                  score_map = np.transpose(
                      np.squeeze(score_map, 0), axes=[1, 2, 0]
                  )
                  cur_gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
                  cur_gray = cv2.resize(cur_gray, (resize_w, resize_h))
                  score_map = 255 * score_map[:, :, 1]
                  optflow_map = postprocess_v(
                      cur_gray,
                      score_map,
                      prev_gray,
                      prev_cfd,
                      disflow,
                      is_init,
                  )
                  prev_gray = cur_gray.copy()
                  prev_cfd = optflow_map.copy()
                  optflow_map = cv2.GaussianBlur(optflow_map, (3, 3), 0)
                  optflow_map = threshold_mask(
                      optflow_map, thresh_bg=0.2, thresh_fg=0.8
                  )
                  img_matting = cv2.resize(
                      optflow_map, (width, height), cv2.INTER_LINEAR
                  )
                  img_matting = np.repeat(
                      img_matting[:, :, np.newaxis], 3, axis=2
                  )
                  bg_im = np.ones_like(img_matting) * 255
                  comb = (
                      img_matting * frame_org
                      + (1 - img_matting) * bg_im
                  ).astype(np.uint8)
                  cv2.imshow("HumanSegmentation", comb)
                  if cv2.waitKey(1) & 0xFF == ord("q"):
                      break
              else:
                  break
          cap_video.release()
  
imports: import argparse
  import ast
  import os
  import os.path
  import cv2
  import numpy
  import paddle.jit
  import paddle.static
  from paddle.inference import Config
  from paddle.inference import create_predictor
  from .data_feed import preprocess_v
  from .data_feed import reader
  from .optimal import postprocess_v
  from .optimal import threshold_mask
  from .processor import base64_to_cv2
  from .processor import check_dir
  from .processor import cv2_to_base64
  from .processor import postprocess
  from paddlehub.module.module import moduleinfo
  from paddlehub.module.module import runnable
  from paddlehub.module.module import serving
label_desc: Use image node_id 5 for calling the ShufflenetHumanSeg obj's underlying member method code with example usage: obj.video_segment(video_path, use_gpu, save_dir) without return types