I saw that page, but the examples for BlobMedia only pertain to files saved on disk or loaded from a URL, but not passed from a server call, like my situation. The documentation for BlobMedia is quite scant, and I really need more explicit help, as I am still learning this platform.
I tried this suggestion, and used
@anvil.server.callable
def img_to_media_obj(img):
img_byte_arr = io.BytesIO()
img.save(img_byte_arr, format='JPEG')
img_byte_arr = img_byte_arr.getvalue()
media_obj = anvil.BlobMedia(content_type="image/jpeg", content=img_byte_arr)
return media_obj
and then change the last two lines of my uplinked server code to:
@anvil.server.callable
def bound_box (file):
with anvil.media.TempFile(file) as filename:
img_bgr = cv2.imread(filename)
img_rgb = cv2.cvtColor(img_bgr, cv2.COLOR_BGR2RGB)
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
face = face_cascade.detectMultiScale(img_gray, 1.5, 5)
class_names=list(classes.keys()) #List of the class names
label = class_names[np.argmax(score)][5:]
height, width, _ = img_rgb.shape
left = int(width/17)
down = int(height/11)
fontsize = 0.00211*width + 0.01
for (x,y,w,h) in face:
box_img = cv2.rectangle(img_rgb,(x, y),(x + w, y + h),(255,255,0),2)
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img_rgb, label, (x,y-15), font, fontsize, (200,255,155),2)
roi_gray = img_gray[y: y + h, x: x + w]
roi_color = img_rgb[y: y + h, x: x + w]
boxes = img_to_media_obj(box_img) # call to img_to_media_obj function above
return boxes # supposedly returns a medial object
But I get the same error msg that I am still need to connect the .source attribute to a Media object or URL.