pull/1539/head
Harald Schafer 5 years ago
parent 6c0ad1e675
commit e864d1af2f
  1. 19
      common/window.py

@ -1,5 +1,6 @@
import sys import sys
import pygame import pygame
import cv2
class Window(): class Window():
def __init__(self, w, h, caption="window", double=False): def __init__(self, w, h, caption="window", double=False):
@ -9,20 +10,20 @@ class Window():
pygame.display.set_caption(caption) pygame.display.set_caption(caption)
self.double = double self.double = double
if self.double: if self.double:
self.screen = pygame.display.set_mode((w*2,h*2), pygame.DOUBLEBUF) self.screen = pygame.display.set_mode((w*2,h*2))
else: else:
self.screen = pygame.display.set_mode((w,h), pygame.DOUBLEBUF) self.screen = pygame.display.set_mode((w,h))
self.camera_surface = pygame.surface.Surface((w,h), 0, 24).convert()
def draw(self, out): def draw(self, out):
pygame.surfarray.blit_array(self.camera_surface, out.swapaxes(0,1)) pygame.event.pump()
if self.double: if self.double:
camera_surface_2x = pygame.transform.scale2x(self.camera_surface) out2 = cv2.resize(out, (self.w*2, self.h*2))
self.screen.blit(camera_surface_2x, (0, 0)) pygame.surfarray.blit_array(self.screen, out2.swapaxes(0,1))
else: else:
self.screen.blit(self.camera_surface, (0, 0)) pygame.surfarray.blit_array(self.screen, out.swapaxes(0,1))
pygame.display.flip() pygame.display.flip()
def getkey(self): def getkey(self):
while 1: while 1:
event = pygame.event.wait() event = pygame.event.wait()
@ -40,7 +41,7 @@ class Window():
if __name__ == "__main__": if __name__ == "__main__":
import numpy as np import numpy as np
win = Window(200, 200) win = Window(200, 200, double=True)
img = np.zeros((200,200,3), np.uint8) img = np.zeros((200,200,3), np.uint8)
while 1: while 1:
print("draw") print("draw")

Loading…
Cancel
Save