日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

从rtmp拉流后进行python鼻子定位demo

發布時間:2023/12/13 综合教程 23 生活家
生活随笔 收集整理的這篇文章主要介紹了 从rtmp拉流后进行python鼻子定位demo 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文講述從在線直播拉流中通過dlib定位鼻子的demo

拉流地址:rtmp://58.200.131.2:1935/livetv/hunantv 湖南衛視

效果:

代碼較容易,主邏輯都是和普通本地攝像頭一樣的,dlib部分要重點看看:

import cv2
import threading
import dlib
import imutils
from imutils import face_utils


predictor_path = 'models\shape_predictor_68_face_landmarks.dat'
face_rec_model_path = 'models\dlib_face_recognition_resnet_model_v1.dat'

predictor = dlib.shape_predictor(predictor_path)
detector = dlib.get_frontal_face_detector()

(noseStart, noseEnd) = face_utils.FACIAL_LANDMARKS_IDXS["nose"]


class Producer(threading.Thread):
	"""docstring for Producer"""

	def __init__(self, rtmp_str):

		super(Producer, self).__init__()

		self.rtmp_str = rtmp_str

		# 通過cv2中的類獲取視頻流操作對象cap
		self.cap = cv2.VideoCapture(self.rtmp_str)

		# 調用cv2方法獲取cap的視頻幀(幀:每秒多少張圖片)
		# fps = self.cap.get(cv2.CAP_PROP_FPS)
		self.fps = self.cap.get(cv2.CAP_PROP_FPS)
		print(self.fps)

		# 獲取cap視頻流的每幀大小
		self.width = int(self.cap.get(cv2.CAP_PROP_FRAME_WIDTH))
		self.height = int(self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
		self.size = (self.width, self.height)
		print(self.size)

	def run(self):

		print('in producer')

		ret, image = self.cap.read()

		while ret:
			frame = imutils.resize(image, width=600)
			gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
			rects = detector(gray, 0)
			for rect in rects:
				shape = predictor(gray, rect)
				shape = face_utils.shape_to_np(shape)
				nose = shape[noseStart:noseEnd]
				noseHull = cv2.convexHull(nose)
				cv2.drawContours(frame, [noseHull], -1, (0, 255, 0), 1)
				cv2.putText(frame, "nose", (nose[0][0], nose[0][1]), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (0, 0, 255), 2)

			cv2.imshow("Frame", frame)

			cv2.waitKey(int(1000 / int(self.fps)))  # 延遲

			if cv2.waitKey(1) & 0xFF == ord('q'):
				self.cap.release()
				cv2.destroyAllWindows()
				break

			ret, image = self.cap.read()


if __name__ == '__main__':
	print('run program')
	rtmp_str = 'rtmp://58.200.131.2:1935/livetv/hunantv'  # 湖南衛視
	producer = Producer(rtmp_str)
	producer.start()

  

需要安裝的python庫

pip install imutils
pip install opencv-python
pip install dlib

  

依賴的dlib模型文件:

鏈接:https://pan.baidu.com/s/1hw0bznAO7-7f1AIvYxzVBA
提取碼:8691

總結

以上是生活随笔為你收集整理的从rtmp拉流后进行python鼻子定位demo的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。