@@ -15,7 +15,8 @@ class CamIndex(Enum):
1515
1616class ImageServer :
1717 def __init__ (self , addr , img_w , img_h , camera ):
18- self .img_dim = (img_w , img_h ) # image dimensions
18+ self .img_h = img_h
19+ self .img_w = img_w
1920 self .img_bytes = img_w * img_h * 2 # image size in bytes
2021 self .camera = camera # camera
2122 self .running = True
@@ -47,17 +48,15 @@ def stop(self):
4748
4849
4950 def bgra2yuv (self , buf ):
50- bgra = np .frombuffer (buf , dtype = np .uint8 ).reshape (* self .img_dim , 4 )
51+ bgra = np .frombuffer (buf , dtype = np .uint8 ).reshape (self .img_h , self . img_w , 4 )
5152 bgr = cv2 .cvtColor (bgra , cv2 .COLOR_BGRA2BGR )
52- y , u , v = cv2 .split (cv2 .cvtColor (bgra , cv2 .COLOR_BGR2YUV ))
53-
54- rows , cols = y .shape
53+ y , u , v = cv2 .split (cv2 .cvtColor (bgr , cv2 .COLOR_BGR2YUV ))
5554
5655 # Downsample u horizontally
57- u = cv2 .resize (u , (cols // 2 , rows ), interpolation = cv2 .INTER_LINEAR )
56+ u = cv2 .resize (u , (self . img_w // 2 , self . img_h ), interpolation = cv2 .INTER_LINEAR )
5857
5958 # Downsample v horizontally
60- v = cv2 .resize (v , (cols // 2 , rows ), interpolation = cv2 .INTER_LINEAR )
59+ v = cv2 .resize (v , (self . img_w // 2 , self . img_h ), interpolation = cv2 .INTER_LINEAR )
6160
6261 # Interleave u and v:
6362 uv = np .zeros_like (y )
@@ -81,7 +80,7 @@ def run(self):
8180
8281 if conn :
8382 img = self .bgra2yuv (img )
84- header = struct .pack ("8sHBBHH" , b'wbimage\x00 ' , tick , self .camera .value , 2 , * self .img_dim )
83+ header = struct .pack ("8sHBBHH" , b'wbimage\x00 ' , tick , self .camera .value , 2 , self .img_w , self . img_h )
8584
8685 try :
8786 conn .send (header )
0 commit comments