我有一个使用 OpenCV 和 mediapipe 的烧瓶程序。该应用程序创建一个 Web 服务器,该服务器接收视频文件的输入,然后使用 mediapipe 处理其上的数据。
当我在虚拟环境中运行代码时,出现以下错误。
Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
File "/Users/alexandrafalkner/Desktop/vandy/5278/CS5279-Project-Gesture-Recognition/lib/python3.9/site-packages/werkzeug/wsgi.py", line 462, in __next__
return self._next()
File "/Users/alexandrafalkner/Desktop/vandy/5278/CS5279-Project-Gesture-Recognition/lib/python3.9/site-packages/werkzeug/wrappers/response.py", line 49, in _iter_encoded
for item in iterable:
File "/Users/alexandrafalkner/Desktop/vandy/5278/CS5279-Project-Gesture-Recognition/lib/python3.9/site-packages/flask/helpers.py", line 131, in generator
yield from gen
File "/Users/alexandrafalkner/Desktop/vandy/5278/CS5279-Project-Gesture-Recognition/Elastic Beanstalk/GestureRec/application.py", line 67, in gen
image = detector.image
AttributeError: 'Detect' object has no attribute 'image'
192.168.1.248 - - [12/Jul/2021 17:25:32] "GET /video_feed HTTP/1.1" 200 -
192.168.1.248 - - [12/Jul/2021 17:25:33] "GET /favicon.ico HTTP/1.1" 200 -
OpenCV: Couldn't read video stream from file "https://r4---sn-ab5sznle.googlevideo.com/videoplayback?expire=1626146734&ei=TrPsYI7TAsi2hwbUhZzgBg&ip=69.169.5.159&id=o-AArBuxjnP3vAs1NJIUfCHWQig2OOQnb8QfLhJehoUaRc&itag=22&source=youtube&requiressl=yes&mh=Tm&mm=31%2C26&mn=sn-ab5sznle%2Csn-p5qs7n76&ms=au%2Conr&mv=m&mvi=4&pl=23&initcwndbps=2586250&vprv=1&mime=video%2Fmp4&ns=BagCNZ55LiZyxfj48GVlM_IG&ratebypass=yes&dur=291.062&lmt=1614364379358865&mt=1626124648&fvip=4&fexp=24001373%2C24007246&beids=9466587&c=WEB&txp=1432434&n=ssmaZFn8YLnHUKV5Jw&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAMayd18uVr6ho_GzGCI-xmLforRk0tlIAf2QfHrlcZKfAiEAgiGe3e3MuyQvIsHOXfObzJgrSb6LhyeL63pLdqpSwyI%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAIpFmquDVDUoAPCZjsRQbhQsPX9lA44HCguTlmnBogi1AiAgjEhIg9xY7yQvlpjxWA6GDgVNPlEqcSsodg5FW2sEWQ%3D%3D"
[ERROR:0] global /private/var/folders/rs/82_yq8xs1q15sncx9xmsh1nh0000gn/T/pip-install-7w_cmwpj/opencv-python/opencv/modules/videoio/src/cap.cpp (162) open VIDEOIO(CV_IMAGES): raised OpenCV exception:
OpenCV(4.5.3) /private/var/folders/rs/82_yq8xs1q15sncx9xmsh1nh0000gn/T/pip-install-7w_cmwpj/opencv-python/opencv/modules/videoio/src/cap_images.cpp:235: error: (-5:Bad argument) CAP_IMAGES: error, expected '0?[1-9][du]' pattern, got: https://r4---sn-ab5sznle.googlevideo.com/videoplayback?expire=1626146734&ei=TrPsYI7TAsi2hwbUhZzgBg&ip=69.169.5.159&id=o-AArBuxjnP3vAs1NJIUfCHWQig2OOQnb8QfLhJehoUaRc&itag=22&source=youtube&requiressl=yes&mh=Tm&mm=31%2C26&mn=sn-ab5sznle%2Csn-p5qs7n76&ms=au%2Conr&mv=m&mvi=4&pl=23&initcwndbps=2586250&vprv=1&mime=video%2Fmp4&ns=BagCNZ55LiZyxfj48GVlM_IG&ratebypass=yes&dur=291.062&lmt=1614364379358865&mt=1626124648&fvip=4&fexp=24001373%2C24007246&beids=9466587&c=WEB&txp=1432434&n=ssmaZFn8YLnHUKV5Jw&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cratebypass%2Cdur%2Clmt&sig=AOq0QJ8wRgIhAMayd18uVr6ho_GzGCI-xmLforRk0tlIAf2QfHrlcZKfAiEAgiGe3e3MuyQvIsHOXfObzJgrSb6LhyeL63pLdqpSwyI%3D&lsparams=mh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AG3C_xAwRQIhAIpFmquDVDUoAPCZjsRQbhQsPX9lA44HCguTlmnBogi1AiAgjEhIg9xY7yQvlpjxWA6GDgVNPlEqcSsodg5FW2sEWQ%3D%3D in function 'icvExtractPattern'
Exception in thread Thread-5:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 950, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 888, in run
self._target(*self._args, **self._kwargs)
File "/Users/alexandrafalkner/Desktop/vandy/5278/CS5279-Project-Gesture-Recognition/Elastic Beanstalk/GestureRec/get_video.py", line 226, in detect
self.mp_drawing = mp.solutions.drawing_utils # Drawing helpers
AttributeError: module 'mediapipe' has no attribute 'solutions'
下面是 HTML 代码:
header_text = '''
<html>\n<head> <title>Gesture Recognition</title> </head>\n<body>'''
instructions = '''
<p><em>Gesture Recognition</em>:</p>'''
home_link = '<p><a href="/">Back</a></p>\n'
footer_text = '</body>\n</html>'
upload_form = b'''
<!doctype html>
<title>Gesture recognition</title>
<h1>Upload MP4 video for Fortnite dance gesture recognition</h1>
<form method="POST">
<input name="YouTube URL">
<input type="submit">
</form>
'''
这是第 67 行,第一个错误:
image_path = os.path.join(os.getcwd(),'live.jpeg')
image = detector.image
第 226 行带有第二个属性错误(我将 mediapipe 导入为 mp):
def detect(self,model_name,source = 0,trail_frames=[5,15]):
if source != 0:
self.yt_url = 'https://www.youtube.com/watch?v='
vPafy = pafy.new(self.yt_url + source)
play = vPafy.getbest(preftype="mp4")
source = play.url
cap = cv2.VideoCapture(source)
# Initiate holistic model
with open(model_name + '_body_language.pkl', 'rb') as f:
model = pickle.load(f)
self.mp_drawing = mp.solutions.drawing_utils # Drawing helpers
self.mp_holistic = mp.solutions.holistic # Mediapipe Solutions
frame_num = 0
frame_list = []
它可以在我伙伴的计算机上运行,所以我认为这不是代码的问题,而是我下载和设置 mediapipe 和 OpenCV 的方式可能。谢谢!