I have flask web app where I am trying to save some images into the sqlite database table using the following table code and flask code images does saved fine I can see the data for images stored in DB. But when i try to access it back and display in it image tag of Jinja template but it just shows me broken image <img src="<Response streamed [200 OK]>" />enter image description here
I am unsure what have to be done to show image in Jinja Template please help me over here Appreciate your time and valuable feedback.
Code for Image Table in model
class SVSFaceTab(db.Model):
__tablename__ = 'SVSFacesTab'
id = db.Column(db.Integer,primary_key = True)
u_id = db.Column(db.Integer,db.ForeignKey('SVS_UserReg.id'),nullable=False)
cam_id = db.Column(db.Integer,db.ForeignKey('SVS_IpCamReg.id'),nullable = False)
Face_save_date = db.Column(db.DateTime,default = datetime.utcnow())
Face_image = db.Column(db.String,nullable = False)
Code for views.py for storing image in to sqlite
self.strpath = "C:\\Users\\IBM_ADMIN\\Desktop\\svsapp\\svsapp\\app\\FD\\FaceCaps\\"
self.strpath+=framenumber
self.strpath+='.jpg'
print self.strpath
cv2.imwrite("C:\\Users\\IBM_ADMIN\\Desktop\\svsapp\\svsapp\\app\\FD\\FaceCaps\\" + framenumber + '.jpg',img)
self.imgret = Image.fromarray(img)
#return self.imgret
if self.imgret is None:
print 'its none'
else:
newimg = cv2.imread(self.strpath)
#img_str = cv2.imencode('.jpg',newimg)[1].tostring()
emid = SVSuserReg.query.filter_by(emid=current_user.emid).first()
camid = SVSIpCamReg.query.filter_by(u_id = current_user.id).first()
CamImgAdd = SVSFaceTab(u_id = emid.id,cam_id= camid.u_id,Face_image = buffer(newimg))
db.session.add(CamImgAdd)
db.session.commit()
print("data is added ")
Code for reading image from database
@FD.route('/FDViewFaces', methods=['GET', 'POST'])
@login_required
def FDViewFaces():
if camtab.FDstore == 1:
emid = SVSuserReg.query.filter_by(emid=current_user.emid).first()
camid = SVSIpCamReg.query.filter_by(u_id = current_user.id).first()
camfaces = SVSFaceTab.query.filter_by(cam_id = camid.u_id , u_id = emid.id ).all()
for rec in camfaces:
camfacesimag=rec.Face_image
rec.Face_imagenew = send_file(io.BytesIO(camfacesimag),attachment_filename='logo.jpg',mimetype='image/jpg')
return render_template('FaceDetect/FDViewFaces.html',allface = camfaces)
Jinja Template Code:-
{% extends "base.html" %}
{% block title %}
SVS Live Photo capture Result.
{% endblock %}
{%block page_content%}
<article>
<h1>Your Live Face Detect Photo are loding here </h1>
<h2>List User here:</h2>
<ul class=entries>
{% for user in allface %}
<li>{{ user.cam_id }}
<li>{{ user.Face_save_date }}
<li>{{ user.Face_imagenew }}
<li><img src="{{user.Face_imagenew}}" />
{% else %}
<li><em> No users yet</em>
{% endfor %}
</ul>
</article>
{%endblock%}
Aucun commentaire:
Enregistrer un commentaire