해당 코드로 진행하였을때 주소 실행하면 무한 로딩
종료하면 여러가지 문제가 발생함
이를 토대로 코드를 수정함
기존 app.py
cv2.imshow('Korean Sign-language', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
"""def video_feed():
return Response(get_frames())"""
if __name__ == '__main__':
app.run(debug=True)
수정 app.py
cv2.imshow('Korean Sign-language', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
res, buffer = cv2.imencode('.jpg', image)
frame = buffer.tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(get_frames(),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0')
수정 html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sign-language</title>
</head>
<body>
<div class="container">
<div class ="row">
<div class = "col-lg-8 offst-lg-2">
<img src ="{{url_for('video_feed')}}" width="100%">
</div>
</div>
</div>
</body>
</html>
실행 결과
수정한 내용
1. get_frame()의 값을 받아올 함수가 없다는 것을 확인 ->video_feed()함수 재작
1.1 Response는 flask import 시 같이 진행
1.2 get_frame()를 mimetype으로 respones