Detecting with MLX90640 Python Script #6

Closed
opened 2022-07-05 01:38:38 +02:00 by blacklight · 0 comments
Owner

I'm trying to detect people with MLX90640 with a Python script, however the error I believe is happening is that the temporary '/tmp/frame.jpg' is not being replaced with a new snapshot so I'm just getting the same reading of negative over and over again. This code runs fine when used as a cronjob within Platypush, just as a standalone Python script it doesn't seem to refresh the temporary frame.

import time
import os
import numpy as np
import json
from platypush.context import get_plugin
from platypush.cron import cron
from PIL import Image

camera = get_plugin('camera.ir.mlx90640')
tensorflow = get_plugin('tensorflow')

image_file = '/tmp/frame.jpg'
model_file = os.path.expanduser('~/models/people_detect/')
camera.capture_image(
   image_file=image_file, grayscale=True)

im = Image.open(open('/tmp/frame.jpg, 'rb'))
im.show()

predictions = tensorflow.predict(
   inputs=image_file, model=model_file)
string = str(predictions)
data = json.loads(string)

prediction = data['response']['output']['predictions'][0]

print(prediction)

if prediction == 'positive':
   print("yes")
elif prediction == 'negative':
   print("no")
else:
   print("error")
I'm trying to detect people with MLX90640 with a Python script, however the error I believe is happening is that the temporary '/tmp/frame.jpg' is not being replaced with a new snapshot so I'm just getting the same reading of negative over and over again. This code runs fine when used as a cronjob within Platypush, just as a standalone Python script it doesn't seem to refresh the temporary frame. ```python import time import os import numpy as np import json from platypush.context import get_plugin from platypush.cron import cron from PIL import Image camera = get_plugin('camera.ir.mlx90640') tensorflow = get_plugin('tensorflow') image_file = '/tmp/frame.jpg' model_file = os.path.expanduser('~/models/people_detect/') camera.capture_image( image_file=image_file, grayscale=True) im = Image.open(open('/tmp/frame.jpg, 'rb')) im.show() predictions = tensorflow.predict( inputs=image_file, model=model_file) string = str(predictions) data = json.loads(string) prediction = data['response']['output']['predictions'][0] print(prediction) if prediction == 'positive': print("yes") elif prediction == 'negative': print("no") else: print("error") ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: platypush/platypush#6
No description provided.