-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture_udp_server.py
103 lines (70 loc) · 1.95 KB
/
capture_udp_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import cv2
import numpy as np
cap = cv2.VideoCapture('udp://127.0.0.1:3000?overrun_nonfatal=1&fifo_size=50000000',cv2.CAP_FFMPEG)
# overrun_nonfatal and fifo has been added to avoid crashed, see https://stackoverflow.com/questions/16944024/udp-streaming-with-ffmpeg-overrun-nonfatal-option
if not cap.isOpened():
print('VideoCapture not opened')
# rescaling does not work on IP cam yet
#https://www.youtube.com/watch?v=y76C3P20rwc
# def make_240p():
# cap.set(3, 320) # width
# cap.set(4, 240) # height
#
# def make_480p():
# cap.set(3, 640) # width
# cap.set(4, 480) # height
#
# def make_720p():
# cap.set(3, 1280) # width
# cap.set(4, 720) # height
#
# def change_res(width, height):
# cap.set(3, width) # width
# cap.set(4, height) # height
#
# make_720p()
# #make_480p()
# #make_240p()
# how to install imageai
# download file manually, put in folder
from imageai.Detection import VideoObjectDetection
import os
import cv2
execution_path = os.getcwd()
detector = VideoObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath(os.path.join(execution_path , "yolo.h5"))
detector.loadModel()
video_path = detector.detectObjectsFromVideo(camera_input=cap,
output_file_path=os.path.join(execution_path, "camera_detected_video")
, frames_per_second=20, log_progress=True, minimum_percentage_probability=30)
print(video_path)
while True:
# capture frame by frame
ret, frame = cap.read()
# Display resulting frame
cv2.imshow("frame", frame)
key = cv2.waitKey(1)
if key == 27:
break
# when done, release capture
cap.release()
cv2.destroyAllWindows()
# exit(-1)
#
# while True:
# ret, frame = cap.read()
#
# if not ret:
# print('frame empty')
# break
#
# cv2.imshow('image', frame)
#
# if cv2.waitKey(1)&0XFF == ord('q'):
# break
#
# cap.release()
# cv2.destroyAllWindows()
# crashes