3
3
import os
4
4
import robomodules as rm
5
5
from messages import *
6
- import cv2 , pickle , pygame , numpy
6
+ import cv2
7
+ import numpy
8
+ import pickle
9
+ import pygame
7
10
8
- ADDRESS = os .environ .get ("BIND_ADDRESS" ,"localhost" )
11
+ ADDRESS = os .environ .get ("BIND_ADDRESS" , "localhost" )
9
12
PORT = os .environ .get ("BIND_PORT" , 11297 )
10
13
11
14
FREQUENCY = 0
12
15
SCREEN_SIZE = 800
13
16
17
+
14
18
class CameraDisplayModule (rm .ProtoModule ):
15
19
def __init__ (self , addr , port ):
16
20
self .subscriptions = [MsgType .CAMERA_FRAME_MSG ]
17
- super ().__init__ (addr , port , message_buffers , MsgType , FREQUENCY , self .subscriptions )
21
+ super ().__init__ (addr , port , message_buffers , MsgType , FREQUENCY ,
22
+ self .subscriptions )
18
23
self .frame = None
19
24
pygame .init ()
20
25
self .display = pygame .display .set_mode ((SCREEN_SIZE , SCREEN_SIZE ))
@@ -25,22 +30,23 @@ def msg_received(self, msg, msg_type):
25
30
if msg_type == MsgType .CAMERA_FRAME_MSG :
26
31
self .frame = msg .cameraFrame
27
32
self ._display_serialized_image ()
28
-
33
+
29
34
def tick (self ):
30
35
# FREQUENCY is 0, so this will never be called.
31
36
return
32
37
33
38
def _display_serialized_image (self ):
34
- if self .frame == None :
39
+ if self .frame is None :
35
40
print ('frame == None' )
36
41
return
37
42
frame = pickle .loads (self .frame )
38
- frame = cv2 .cvtColor (frame ,cv2 .COLOR_BGR2RGB )
43
+ frame = cv2 .cvtColor (frame , cv2 .COLOR_BGR2RGB )
39
44
frame = numpy .rot90 (frame )
40
45
frame = pygame .surfarray .make_surface (frame )
41
- self .display .blit (frame ,(0 ,0 ))
46
+ self .display .blit (frame , (0 , 0 ))
42
47
pygame .display .flip ()
43
48
49
+
44
50
def main ():
45
51
module = CameraDisplayModule (ADDRESS , PORT )
46
52
module .run ()
0 commit comments