mirror of
				https://github.com/rendies/People-Counting-in-Real-Time.git
				synced 2025-11-04 21:53:04 +07:00 
			
		
		
		
	Compare commits
	
		
			9 Commits
		
	
	
		
			62d0e16a89
			...
			master
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4702d6ced1 | |||
| 08a9122c3d | |||
| 38aca22168 | |||
| 1c65521d25 | |||
| 44e79862bf | |||
| 43d69f3bfd | |||
| cd7a2cdc57 | |||
| 556f2f3c70 | |||
| d910d04b79 | 
@@ -14,6 +14,7 @@ from flask import Response
 | 
				
			|||||||
from flask import Flask
 | 
					from flask import Flask
 | 
				
			||||||
from flask import jsonify
 | 
					from flask import jsonify
 | 
				
			||||||
from flask_cors import CORS, cross_origin
 | 
					from flask_cors import CORS, cross_origin
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					
 | 
				
			||||||
t0 = time.time()
 | 
					t0 = time.time()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -33,13 +34,13 @@ def counter():
 | 
				
			|||||||
	global people_count
 | 
						global people_count
 | 
				
			||||||
	return jsonify([ 1000, 980, 700, 500, 670, 567, people_count ])
 | 
						return jsonify([ 1000, 980, 700, 500, 670, 567, people_count ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@app.route("/video")
 | 
					# @app.route("/video")
 | 
				
			||||||
@cross_origin()
 | 
					# @cross_origin()
 | 
				
			||||||
def video_feed():
 | 
					# def video_feed():
 | 
				
			||||||
	# return the response generated along with the specific media
 | 
					# 	# return the response generated along with the specific media
 | 
				
			||||||
	# type (mime type)
 | 
					# 	# type (mime type)
 | 
				
			||||||
	return Response(generate(),
 | 
					# 	return Response(generate(),
 | 
				
			||||||
					mimetype = "multipart/x-mixed-replace; boundary=frame")
 | 
					# 					mimetype = "multipart/x-mixed-replace; boundary=frame")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def open_ffmpeg_stream_process(height, width):
 | 
					def open_ffmpeg_stream_process(height, width):
 | 
				
			||||||
	# args = (
 | 
						# args = (
 | 
				
			||||||
@@ -48,7 +49,7 @@ def open_ffmpeg_stream_process(height, width):
 | 
				
			|||||||
	#     "-f rtsp rtsp://172.23.90.205:8554/stream"
 | 
						#     "-f rtsp rtsp://172.23.90.205:8554/stream"
 | 
				
			||||||
	# ).split()
 | 
						# ).split()
 | 
				
			||||||
	args = (
 | 
						args = (
 | 
				
			||||||
			"ffmpeg -re -stream_loop -1 -f rawvideo -vcodec rawvideo -pix_fmt "
 | 
								"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 "
 | 
								"rgb24 -s " + str(width) + "x" + str(height) + " -i pipe:0 -pix_fmt nv12 "
 | 
				
			||||||
			"-c:v libx264 -preset fast -crf 22 -bf 0 "
 | 
								"-c:v libx264 -preset fast -crf 22 -bf 0 "
 | 
				
			||||||
			"-f rtsp -rtsp_transport tcp rtsp://172.17.2.39/counter"
 | 
								"-f rtsp -rtsp_transport tcp rtsp://172.17.2.39/counter"
 | 
				
			||||||
@@ -125,9 +126,7 @@ def PeopleCounter():
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	if config.Thread:
 | 
						if config.Thread:
 | 
				
			||||||
		vs = thread.ThreadingClass(config.url)
 | 
							vs = thread.ThreadingClass(config.url)
 | 
				
			||||||
	ret, frame = vs.read()
 | 
						ffmpeg_process = open_ffmpeg_stream_process(1080, 1920)
 | 
				
			||||||
	height, width, ch = frame.shape
 | 
					 | 
				
			||||||
	ffmpeg_process = open_ffmpeg_stream_process(height, width)
 | 
					 | 
				
			||||||
	# loop over frames from the video stream
 | 
						# loop over frames from the video stream
 | 
				
			||||||
	while True:
 | 
						while True:
 | 
				
			||||||
		# grab the next frame and handle if we are reading from either
 | 
							# grab the next frame and handle if we are reading from either
 | 
				
			||||||
@@ -143,7 +142,7 @@ def PeopleCounter():
 | 
				
			|||||||
		# resize the frame to have a maximum width of 500 pixels (the
 | 
							# resize the frame to have a maximum width of 500 pixels (the
 | 
				
			||||||
		# less data we have, the faster we can process it), then convert
 | 
							# less data we have, the faster we can process it), then convert
 | 
				
			||||||
		# the frame from BGR to RGB for dlib
 | 
							# 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)
 | 
							rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# if the frame dimensions are empty, set them
 | 
							# if the frame dimensions are empty, set them
 | 
				
			||||||
@@ -344,9 +343,10 @@ def PeopleCounter():
 | 
				
			|||||||
			writer.write(frame)
 | 
								writer.write(frame)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		# show the output frame
 | 
							# show the output frame
 | 
				
			||||||
 | 
					 | 
				
			||||||
		ffmpeg_process.stdin.write(frame.astype(np.uint8).tobytes())
 | 
					 | 
				
			||||||
		# with lock:
 | 
							# with lock:
 | 
				
			||||||
 | 
							frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
 | 
				
			||||||
 | 
							ffmpeg_process.stdin.write(frame.astype(np.uint8).tobytes())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			# outputFrame = frame.copy()
 | 
								# outputFrame = frame.copy()
 | 
				
			||||||
		# cv2.imshow("Real-Time Monitoring/Analysis Window", frame)
 | 
							# cv2.imshow("Real-Time Monitoring/Analysis Window", frame)
 | 
				
			||||||
		key = cv2.waitKey(1) & 0xFF
 | 
							key = cv2.waitKey(1) & 0xFF
 | 
				
			||||||
@@ -386,6 +386,8 @@ def PeopleCounter():
 | 
				
			|||||||
		vs.release()
 | 
							vs.release()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	# close any open windows
 | 
						# close any open windows
 | 
				
			||||||
 | 
						ffmpeg_process.stdin.close()
 | 
				
			||||||
 | 
						ffmpeg_process.wait()
 | 
				
			||||||
	cv2.destroyAllWindows()
 | 
						cv2.destroyAllWindows()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def generate():
 | 
					def generate():
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user