Compare commits

..

11 Commits

Author SHA1 Message Date
4702d6ced1 fix: accelerate with gpu 2023-01-19 19:33:03 +07:00
08a9122c3d fix: no resize 2023-01-18 17:35:48 +07:00
38aca22168 fix: set width 2023-01-18 17:32:51 +07:00
1c65521d25 fix: subprocess communicate 2023-01-18 17:18:49 +07:00
44e79862bf fix: subprocess communicate 2023-01-18 17:15:28 +07:00
43d69f3bfd fix: use ffmpeg rtsp 2023-01-18 17:00:16 +07:00
cd7a2cdc57 fix: use ffmpeg rtsp 2023-01-18 16:58:49 +07:00
556f2f3c70 fix: use ffmpeg rtsp 2023-01-18 16:55:40 +07:00
d910d04b79 fix: use ffmpeg rtsp 2023-01-18 16:54:37 +07:00
62d0e16a89 fix: use ffmpeg rtsp 2023-01-18 16:48:48 +07:00
aedcb241dc fix: use ffmpeg rtsp 2023-01-18 16:47:12 +07:00
2 changed files with 34 additions and 13 deletions

View File

@@ -14,6 +14,7 @@ from flask import Response
from flask import Flask
from flask import jsonify
from flask_cors import CORS, cross_origin
import subprocess
t0 = time.time()
@@ -33,13 +34,28 @@ def counter():
global people_count
return jsonify([ 1000, 980, 700, 500, 670, 567, people_count ])
@app.route("/video")
@cross_origin()
def video_feed():
# return the response generated along with the specific media
# type (mime type)
return Response(generate(),
mimetype = "multipart/x-mixed-replace; boundary=frame")
# @app.route("/video")
# @cross_origin()
# def video_feed():
# # return the response generated along with the specific media
# # type (mime type)
# return Response(generate(),
# mimetype = "multipart/x-mixed-replace; boundary=frame")
def open_ffmpeg_stream_process(height, width):
# args = (
# "ffmpeg -re -stream_loop -1 -f rawvideo -pix_fmt "
# "rgb24 -s 1920x1080 -i pipe:0 -pix_fmt yuv420p "
# "-f rtsp rtsp://172.23.90.205:8554/stream"
# ).split()
args = (
"ffmpeg -hwaccel cuda -re -stream_loop -1 -f rawvideo -vcodec rawvideo -pix_fmt "
"rgb24 -s " + str(width) + "x" + str(height) + " -i pipe:0 -pix_fmt nv12 "
"-c:v libx264 -preset fast -crf 22 -bf 0 "
"-f rtsp -rtsp_transport tcp rtsp://172.17.2.39/counter"
).split()
return subprocess.Popen(args, stdin=subprocess.PIPE)
def PeopleCounter():
global outputFrame, lock, people_count
@@ -110,7 +126,7 @@ def PeopleCounter():
if config.Thread:
vs = thread.ThreadingClass(config.url)
ffmpeg_process = open_ffmpeg_stream_process(1080, 1920)
# loop over frames from the video stream
while True:
# grab the next frame and handle if we are reading from either
@@ -126,7 +142,7 @@ def PeopleCounter():
# resize the frame to have a maximum width of 500 pixels (the
# less data we have, the faster we can process it), then convert
# the frame from BGR to RGB for dlib
frame = imutils.resize(frame, width = 500)
# frame = imutils.resize(frame, width = 640)
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# if the frame dimensions are empty, set them
@@ -327,8 +343,11 @@ def PeopleCounter():
writer.write(frame)
# show the output frame
with lock:
outputFrame = frame.copy()
# with lock:
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
ffmpeg_process.stdin.write(frame.astype(np.uint8).tobytes())
# outputFrame = frame.copy()
# cv2.imshow("Real-Time Monitoring/Analysis Window", frame)
key = cv2.waitKey(1) & 0xFF
@@ -367,6 +386,8 @@ def PeopleCounter():
vs.release()
# close any open windows
ffmpeg_process.stdin.close()
ffmpeg_process.wait()
cv2.destroyAllWindows()
def generate():

View File

@@ -5,14 +5,14 @@
# e.g., 'email@gmail.com'
MAIL = ''
# Enter the ip camera url (e.g., url = 'http://191.138.0.100:8040/video')
url = 'rtsp://admin:Asainfra333@172.17.0.60:554'
url = 'rtsp://172.17.2.39/main'
# ON/OFF for mail feature. Enter True to turn on the email alert feature.
ALERT = False
# Set max. people inside limit. Optimise number below: 10, 50, 100, etc.
Threshold = 10
# Threading ON/OFF
Thread = False
Thread = True
# Simple log to log the counting data
Log = False
# Auto run/Schedule the software to run at your desired time