Issue with posting image to prusa connect image API.
 
Notifications
Clear all

Issue with posting image to prusa connect image API.  

  RSS
Cameron
(@cameron-3)
Member
Issue with posting image to prusa connect image API.

I recently recieved my Prusa XL and things have been working well. I ordered a usb camera to use with a raspberry pi 0 w. I was unable to find a script that handled this yet so I decided to write my own. The issue I am having is that the image sent to the API looks like the following:

This has lead me to believe that my encoding is wrong but I am not sure how to correct this. I also have been unable to find anything like this on the forum. I have attempted not sending a byte string and instead sending the raw image but that did not work either My source code is below and I am currently testing said code on my laptop before deploying it to a raspberry pi. Has anyone else encountered this issue or have suggestions? .

import base64

import httpx
import cv2
import numpy
import requests

cap = cv2.VideoCapture(1)

HTTP_URL = "https://webcam.connect.prusa3d.com/c/snapshot"
FINGERPRINT = 
TOKEN = 
result, image = cap.read(cv2.CAP_FFMPEG)

headers = {
    'Content-Type': 'image/jpg',
    'fingerprint': FINGERPRINT,
    'token': TOKEN,
}
def upload_image(http_url, fingerprint, token, image):
    _, img_encoded = cv2.imencode(".jpeg", image)
    response = requests.put(
        http_url,
        headers={
            "content-type": "image/jpg",
            "fingerprint": fingerprint,
            "token": token,
        },
        data=img_encoded.tobytes(),
    )
    return response
image = cv2.resize(image, (640, 480))
#with httpx.Client() as client:
#    response = client.put(url=HTTP_URL, headers=headers, content=cv2.imencode(".jpeg", image)[1].tobytes())
response = upload_image(HTTP_URL, FINGERPRINT, TOKEN, image)
print("this is the request " + response.text)
This topic was modified 4 months ago 2 times by Cameron
Posted : 21/12/2023 6:45 am
Share: