parameters: (controller)
docstring: Run, run once every frames
docstring_summary: Run, run once every frames
docstring_tokens: Run run once every frames
function: def run(controller):
      """
      Run, run once every frames
      """
      if controller.sensors[0].positive:
          try:
              buff_size = 4096
              msg_raw = logic.socket.recv(buff_size)
  
              # check for header msg indicating the number of packet that'll follow
              # containing a unique frame (image)
              if len(msg_raw) == 4:
                  nb_of_packet_per_frame = msg_raw[0]
  
                  # loop over next packets to reconstitute image
                  frame_raw = b''
                  for i in range(nb_of_packet_per_frame):
                      frame_raw = frame_raw + logic.socket.recv(buff_size)
  
                  # frame = cv2.imdecode(numpy.fromstring(frame_raw, dtype=numpy.uint8), cv2.IMREAD_COLOR)
                  frame = cv2.imdecode(numpy.fromstring(frame_raw, dtype=numpy.uint8), cv2.IMREAD_GRAYSCALE)
  
  
                  if not frame is None:
  
                      width = frame.shape[1]
                      height = frame.shape[0]
  
                      l = frame.tolist()
                      lll = list(itertools.chain(*l))
  
                      # image_buffer = bgl.Buffer(bgl.GL_INT, [width*height*3], lll)
                      image_buffer = bgl.Buffer(bgl.GL_BYTE, width*height, lll)
  
                      source = texture.ImageBuff()
  
                      # Apply a filter, that way source.load does not except a 3(RGB) pixel image
                      source.filter = texture.FilterBlueScreen()
                      source.load(image_buffer, width, height)
  
                      logic.texture.source = source
                      logic.texture.refresh(False)
  
          except socket.timeout:
              pass
function_tokens: def run ( controller ) : if controller . sensors [ 0 ] . positive : try : buff_size = 4096 msg_raw = logic . socket . recv ( buff_size ) # check for header msg indicating the number of packet that'll follow # containing a unique frame (image) if len ( msg_raw ) == 4 : nb_of_packet_per_frame = msg_raw [ 0 ] # loop over next packets to reconstitute image frame_raw = b'' for i in range ( nb_of_packet_per_frame ) : frame_raw = frame_raw + logic . socket . recv ( buff_size ) # frame = cv2.imdecode(numpy.fromstring(frame_raw, dtype=numpy.uint8), cv2.IMREAD_COLOR) frame = cv2 . imdecode ( numpy . fromstring ( frame_raw , dtype = numpy . uint8 ) , cv2 . IMREAD_GRAYSCALE ) if not frame is None : width = frame . shape [ 1 ] height = frame . shape [ 0 ] l = frame . tolist ( ) lll = list ( itertools . chain ( * l ) ) # image_buffer = bgl.Buffer(bgl.GL_INT, [width*height*3], lll) image_buffer = bgl . Buffer ( bgl . GL_BYTE , width * height , lll ) source = texture . ImageBuff ( ) # Apply a filter, that way source.load does not except a 3(RGB) pixel image source . filter = texture . FilterBlueScreen ( ) source . load ( image_buffer , width , height ) logic . texture . source = source logic . texture . refresh ( False ) except socket . timeout : pass