openpilot is an open source driver assistance system. openpilot performs the functions of Automated Lane Centering and Adaptive Cruise Control for over 200 supported car makes and models.

55 lines
1.5 KiB

5 years ago
import sys
import pygame # pylint: disable=import-error
import cv2 # pylint: disable=import-error
5 years ago
class Window():
def __init__(self, w, h, caption="window", double=False, halve=False):
5 years ago
self.w = w
self.h = h
5 years ago
pygame.display.init()
5 years ago
pygame.display.set_caption(caption)
self.double = double
self.halve = halve
5 years ago
if self.double:
self.screen = pygame.display.set_mode((w*2, h*2))
elif self.halve:
self.screen = pygame.display.set_mode((w//2, h//2))
5 years ago
else:
self.screen = pygame.display.set_mode((w, h))
5 years ago
def draw(self, out):
5 years ago
pygame.event.pump()
5 years ago
if self.double:
5 years ago
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))
5 years ago
else:
pygame.surfarray.blit_array(self.screen, out.swapaxes(0, 1))
5 years ago
pygame.display.flip()
5 years ago
5 years ago
def getkey(self):
while 1:
event = pygame.event.wait()
if event.type == pygame.QUIT:
5 years ago
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN:
5 years ago
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
5 years ago
win = Window(200, 200, double=True)
img = np.zeros((200, 200, 3), np.uint8)
while 1:
print("draw")
img += 1
win.draw(img)