File tree 7 files changed +140
-1
lines changed
socket-send-receive-image
7 files changed +140
-1
lines changed Original file line number Diff line number Diff line change
1
+ Streaming CV2 with HTTP
2
+
3
+ https://stackoverflow.com/questions/55539599/gstreaming-over-http-using-python-and-opencv?noredirect=1#comment97788169_55539599
4
+
Original file line number Diff line number Diff line change
1
+ See in [ pygame/cv-stream] ( ../../pygame/cv-stream )
Original file line number Diff line number Diff line change
1
+ This code use cv2 to get stream and PyGame to display it.
2
+
3
+ One version blits directly on ` screen ` so window must have the same size as stream.
4
+
5
+ Other version blits on ` Surface ` and later blit ` Surface ` on ` screen ` so window may have different size.
Original file line number Diff line number Diff line change
1
+
2
+ # date: 2019.04.06
3
+ #
4
+ # This version displays directly on screen so window must have the same size as stream
5
+
6
+
7
+ import pygame
8
+ import cv2
9
+
10
+ # --- local (built-in) camera ---
11
+ #stream = 0
12
+
13
+ # --- local file ---
14
+ #stream = '2019-03-26_08-43-15.mkv'
15
+
16
+ # --- http stream ---
17
+ # doesn't work any more
18
+ #stream = 'http://media.dumpert.nl/tablet/9f7c6290_Verstappen_vs._Rosberg_with_Horner_Smile___Streamable.mp4.mp4.mp4'
19
+
20
+ # --- rtsp stream ---
21
+ #stream = 'rtsp://streaming1.osu.edu/media2/ufsap/ufsap.mov'
22
+
23
+ # --- rtmp stream ---
24
+ # Big Buck Bunny
25
+ stream = 'rtmp://184.72.239.149/vod/mp4:bigbuckbunny_1500.mp4'
26
+
27
+ cap = cv2 .VideoCapture (stream )
28
+
29
+ ret , img = cap .read ()
30
+ if not ret :
31
+ print ("Can't read stream" )
32
+ #exit()
33
+
34
+ #img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
35
+ img = cv2 .transpose (img )
36
+ print ('shape:' , img .shape )
37
+
38
+ pygame .init ()
39
+
40
+ screen = pygame .display .set_mode ((img .shape [0 ], img .shape [1 ]))
41
+
42
+ running = True
43
+ while running :
44
+ for event in pygame .event .get ():
45
+ if event .type == pygame .QUIT :
46
+ running = False
47
+
48
+ ret , img = cap .read ()
49
+ if not ret :
50
+ running = False
51
+ break
52
+ else :
53
+ #img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
54
+ #img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
55
+ img = cv2 .transpose (img )
56
+
57
+ pygame .surfarray .blit_array (screen , img )
58
+
59
+ pygame .display .flip ()
60
+
61
+ pygame .quit ()
Original file line number Diff line number Diff line change
1
+
2
+ # date: 2019.04.06
3
+ #
4
+ # This version displays directly on screen so window must have the same size as stream
5
+
6
+
7
+ import pygame
8
+ import cv2
9
+
10
+ # --- local (built-in) camera ---
11
+ #stream = 0
12
+
13
+ # --- local file ---
14
+ #stream = '2019-03-26_08-43-15.mkv'
15
+
16
+ # --- http stream ---
17
+ # doesn't work any more
18
+ #stream = 'http://media.dumpert.nl/tablet/9f7c6290_Verstappen_vs._Rosberg_with_Horner_Smile___Streamable.mp4.mp4.mp4'
19
+
20
+ # --- rtsp stream ---
21
+ #stream = 'rtsp://streaming1.osu.edu/media2/ufsap/ufsap.mov'
22
+
23
+ # --- rtmp stream ---
24
+ # Big Buck Bunny
25
+ stream = 'rtmp://184.72.239.149/vod/mp4:bigbuckbunny_1500.mp4'
26
+
27
+ cap = cv2 .VideoCapture (stream )
28
+
29
+ ret , img = cap .read ()
30
+ if not ret :
31
+ print ("Can't read stream" )
32
+ #exit()
33
+
34
+ #img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
35
+ img = cv2 .transpose (img )
36
+ print ('shape:' , img .shape )
37
+
38
+ pygame .init ()
39
+
40
+ screen = pygame .display .set_mode ((800 , 600 ))
41
+ surface = pygame .surface .Surface ((img .shape [0 ], img .shape [1 ]))
42
+
43
+ running = True
44
+ while running :
45
+ for event in pygame .event .get ():
46
+ if event .type == pygame .QUIT :
47
+ running = False
48
+
49
+ ret , img = cap .read ()
50
+ if not ret :
51
+ running = False
52
+ break
53
+ else :
54
+ #img = cv2.rotate(img, cv2.ROTATE_90_CLOCKWISE)
55
+ #img = cv2.rotate(img, cv2.ROTATE_90_COUNTERCLOCKWISE)
56
+ img = cv2 .transpose (img )
57
+
58
+ pygame .surfarray .blit_array (surface , img )
59
+ screen .blit (surface , (0 ,0 ))
60
+
61
+ pygame .display .flip ()
62
+
63
+ pygame .quit ()
64
+
Original file line number Diff line number Diff line change
1
+ Streaming CV2 with HTTP
2
+
3
+ https://stackoverflow.com/questions/55539599/gstreaming-over-http-using-python-and-opencv?noredirect=1#comment97788169_55539599
4
+
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ Server uses loop to send image with current time.
2
2
In every loop first it sends 4 bytes with image's size and later it sends image.
3
3
4
4
Client uses loop to receive image with current time (and display it).
5
- In every loop first it receives 4 bytes wiht image's size and later it uses this information
5
+ In every loop first it receives 4 bytes with image's size and later it uses this information
6
6
to receive image in chunks.
7
7
8
8
You can’t perform that action at this time.
0 commit comments