move common.window to xx (#30777)
	
		
	
				
					
				
			
							parent
							
								
									77bafb0708
								
							
						
					
					
						commit
						2c30421b16
					
				
				 2 changed files with 0 additions and 105 deletions
			
			
		@ -1,61 +0,0 @@ | 
				
			||||
import sys | 
				
			||||
import pygame | 
				
			||||
import cv2 | 
				
			||||
 | 
				
			||||
class Window: | 
				
			||||
  def __init__(self, w, h, caption="window", double=False, halve=False): | 
				
			||||
    self.w = w | 
				
			||||
    self.h = h | 
				
			||||
    pygame.display.init() | 
				
			||||
    pygame.display.set_caption(caption) | 
				
			||||
    self.double = double | 
				
			||||
    self.halve = halve | 
				
			||||
    if self.double: | 
				
			||||
      self.rw, self.rh = w*2, h*2 | 
				
			||||
    elif self.halve: | 
				
			||||
      self.rw, self.rh = w//2, h//2 | 
				
			||||
    else: | 
				
			||||
      self.rw, self.rh = w, h | 
				
			||||
    self.screen = pygame.display.set_mode((self.rw, self.rh)) | 
				
			||||
    pygame.display.flip() | 
				
			||||
 | 
				
			||||
    # hack for xmonad, it shrinks the window by 6 pixels after the display.flip | 
				
			||||
    if self.screen.get_width() != self.rw: | 
				
			||||
      self.screen = pygame.display.set_mode((self.rw+(self.rw-self.screen.get_width()), self.rh+(self.rh-self.screen.get_height()))) | 
				
			||||
      pygame.display.flip() | 
				
			||||
 | 
				
			||||
  def draw(self, out): | 
				
			||||
    pygame.event.pump() | 
				
			||||
    if self.double: | 
				
			||||
      out2 = cv2.resize(out, (self.w*2, self.h*2)) | 
				
			||||
      pygame.surfarray.blit_array(self.screen, out2.swapaxes(0, 1)) | 
				
			||||
    elif self.halve: | 
				
			||||
      out2 = cv2.resize(out, (self.w//2, self.h//2)) | 
				
			||||
      pygame.surfarray.blit_array(self.screen, out2.swapaxes(0, 1)) | 
				
			||||
    else: | 
				
			||||
      pygame.surfarray.blit_array(self.screen, out.swapaxes(0, 1)) | 
				
			||||
    pygame.display.flip() | 
				
			||||
 | 
				
			||||
  def getkey(self): | 
				
			||||
    while 1: | 
				
			||||
      event = pygame.event.wait() | 
				
			||||
      if event.type == pygame.QUIT: | 
				
			||||
        pygame.quit() | 
				
			||||
        sys.exit() | 
				
			||||
      if event.type == pygame.KEYDOWN: | 
				
			||||
        return event.key | 
				
			||||
 | 
				
			||||
  def getclick(self): | 
				
			||||
    for event in pygame.event.get(): | 
				
			||||
      if event.type == pygame.MOUSEBUTTONDOWN: | 
				
			||||
        mx, my = pygame.mouse.get_pos() | 
				
			||||
        return mx, my | 
				
			||||
 | 
				
			||||
if __name__ == "__main__": | 
				
			||||
  import numpy as np | 
				
			||||
  win = Window(200, 200, double=True) | 
				
			||||
  img: np.ndarray = np.zeros((200, 200, 3), np.uint8) | 
				
			||||
  while 1: | 
				
			||||
    print("draw") | 
				
			||||
    img += 1 | 
				
			||||
    win.draw(img) | 
				
			||||
@ -1,44 +0,0 @@ | 
				
			||||
#!/usr/bin/env python | 
				
			||||
import os | 
				
			||||
import sys | 
				
			||||
import numpy as np | 
				
			||||
os.environ['ZMQ'] = '1' | 
				
			||||
 | 
				
			||||
from openpilot.common.window import Window | 
				
			||||
import cereal.messaging as messaging | 
				
			||||
 | 
				
			||||
# start camerad with 'SEND_ROAD=1 SEND_DRIVER=1 SEND_WIDE_ROAD=1 XMIN=771 XMAX=1156 YMIN=483 YMAX=724 ./camerad' | 
				
			||||
# also start bridge | 
				
			||||
# then run this "./receive.py <ip>" | 
				
			||||
 | 
				
			||||
if "FULL" in os.environ: | 
				
			||||
  SCALE = 2 | 
				
			||||
  XMIN, XMAX = 0, 1927 | 
				
			||||
  YMIN, YMAX = 0, 1207 | 
				
			||||
else: | 
				
			||||
  SCALE = 1 | 
				
			||||
  XMIN = 771 | 
				
			||||
  XMAX = 1156 | 
				
			||||
  YMIN = 483 | 
				
			||||
  YMAX = 724 | 
				
			||||
H, W = ((YMAX-YMIN+1)//SCALE, (XMAX-XMIN+1)//SCALE) | 
				
			||||
 | 
				
			||||
if __name__ == '__main__': | 
				
			||||
  cameras = ['roadCameraState', 'wideRoadCameraState', 'driverCameraState'] | 
				
			||||
  if "CAM" in os.environ: | 
				
			||||
    cam = int(os.environ['CAM']) | 
				
			||||
    cameras = cameras[cam:cam+1] | 
				
			||||
  sm = messaging.SubMaster(cameras, addr=sys.argv[1]) | 
				
			||||
  win = Window(W*len(cameras), H) | 
				
			||||
  bdat = np.zeros((H, W*len(cameras), 3), dtype=np.uint8) | 
				
			||||
 | 
				
			||||
  while 1: | 
				
			||||
    sm.update() | 
				
			||||
    for i,k in enumerate(cameras): | 
				
			||||
      if sm.updated[k]: | 
				
			||||
        #print("update", k) | 
				
			||||
        bgr_raw = sm[k].image | 
				
			||||
        dat = np.frombuffer(bgr_raw, dtype=np.uint8).reshape(H, W, 3)[:, :, [2,1,0]] | 
				
			||||
        bdat[:, W*i:W*(i+1)] = dat | 
				
			||||
    win.draw(bdat) | 
				
			||||
 | 
				
			||||
					Loading…
					
					
				
		Reference in new issue