What's new

Help How to display python output on my webpage?

ransky_24

Established
Joined
May 5, 2015
Posts
157
Reaction
30
Age
27
i'm currently working saking personal project, simple object recognition in python na nakaka detect ng cup or bottle, gusto ko sanan forward yung output ng prediction model ko sa webpage, para dun ko na lang idisplay yung output , for example gaya ng sa heat sensor na nakaka display ng temperature sa webpage pag may heat na nadedect , pahelp naman po kung sino marunong, your help will be very much appreciated, thank you.


this is the source code for my python cup and bottle recognition:
import cv2
import tensorflow.keras as keras
import numpy as np

np.set_printoptions(suppress=True)

webcam = cv2.VideoCapture(0)
model = keras.models.load_model('keras_model.h5')
data_for_model = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32)


def load_labels(path):
f = open(path, 'r')
lines = f.readlines()
labels = []
for line in lines:
labels.append(line.split(' ')[1].strip('\n'))
return labels


label_path = 'labels.txt'
labels = load_labels(label_path)
print(labels)



def image_resize(image, height, inter=cv2.INTER_AREA):
dim = None
(h, w) = image.shape[:2]
r = height / float(h)
dim = (int(w * r), height)
resized = cv2.resize(image, dim, interpolation=inter)
return resized



def cropTo(img):
size = 224
height, width = img.shape[:2]

sideCrop = (width - 224) // 2
return img[:, sideCrop:(width - sideCrop)]


while True:
ret, img = webcam.read()
if ret:

img = image_resize(img, height=224)
img = cropTo(img)


img = cv2.flip(img, 1)


normalized_img = (img.astype(np.float32) / 127.0) - 1
data_for_model[0] = normalized_img


prediction = model.predict(data_for_model)
for i in range(0, len(prediction[0])):
print('{}: {}'.format(labels, prediction[0]))
cv2.imshow('webcam', img)
if cv2.waitKey(1) == 27:
break

cv2.destroyAllWindows()




eto naman po young sample output na gusto kong display as webpage, gusto ko po sana kada may madetec na cup or bottle, mag didisplay din sa webpage:

bottle: 0.9784454107284546
cup: 0.04396909475326538
bottle: 0.9560309052467346
cup: 0.04825812205672264
bottle: 0.9517418742179871
cup: 0.01662440039217472
bottle: 0.983375608921051
 

m1k3y

Journeyman
alamin mo muna lods paano gumamit ng Flask or Django, pero tingin ko kahit Flask okay na. sundan mo ung tutorial dito You do not have permission to view the full content of this post. Log in or register now. (official docs ng flask), tas copy paste mo lang yan code mo sa flask app mo, at syempre replace mo lang ung print functions mo sa flask way ng pag print sa webpage.
 

ransky_24

Established
alamin mo muna lods paano gumamit ng Flask or Django, pero tingin ko kahit Flask okay na. sundan mo ung tutorial dito You do not have permission to view the full content of this post. Log in or register now. (official docs ng flask), tas copy paste mo lang yan code mo sa flask app mo, at syempre replace mo lang ung print functions mo sa flask way ng pag print sa webpage.
thank you
 

m1k3y

Journeyman
thank you
aralin mo din panu i deploy yang site mo, para live sa internett, sa pythonanywhere.com libre lang mag deploy (with limited features), mejo need pag aralan lang ng konti ung linux commands, pero sulit naman pag natutunan mo.
 
Top