Hello everyone, I am building an object detection project which is working great in app.roboflow.com and now I am trying to move to some clients. I am using Python on macOS moving to Raspberry Pi.
The problem is this - how can I read image frames from a video and get a prediction like the JSON below against the model? There are two common examples on the 'net, I’ve tried both and can’t make either work. Seems to be something with the format of the image data I am using.
I am opening the video file using
import cv2 as cv
f = cv.VideoCapture('myfile.mp4')
while(f.isOpened()):
ret, frame = f.read()
rf = Roboflow(api_key="my_api_key")
project = rf.workspace().project("my-project-name")
model = project.version(3).model
# Encode image to base64 string
retval, buffer = cv.imencode('.jpg', frame)
project.upload(buffer)
model.predict()
But each time I am getting
Exception has occurred: AttributeError
'numpy.ndarray' object has no attribute 'startswith'
The problem seems to be that project.upload() requires an image path, but I have an image buffer. Any ideas? My Google-fu has let me down.
The output I need is something like this - just the class and confidence.
{
"predictions": [
{
"x": 469,
"y": 214,
"width": 182,
"height": 304,
"class": "my-class",
"confidence": 0.748
}
]
}
Thank you in advance for any help.