Skip to content

Commit 0f32ec0

Browse files
committed
pygame/cv2 update
1 parent 3512e78 commit 0f32ec0

File tree

7 files changed

+140
-1
lines changed

7 files changed

+140
-1
lines changed

cv2/Notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Streaming CV2 with HTTP
2+
3+
https://stackoverflow.com/questions/55539599/gstreaming-over-http-using-python-and-opencv?noredirect=1#comment97788169_55539599
4+

cv2/pygame-CV/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
See in [pygame/cv-stream](../../pygame/cv-stream)

pygame/cv2-stream/READM.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Streaming CV2 with HTTP
2+
3+
https://stackoverflow.com/questions/55539599/gstreaming-over-http-using-python-and-opencv?noredirect=1#comment97788169_55539599
4+

pygame/socket-send-receive-image/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Server uses loop to send image with current time.
22
In every loop first it sends 4 bytes with image's size and later it sends image.
33

44
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
66
to receive image in chunks.
77

88

0 commit comments

Comments
 (0)