You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.2 KiB
41 lines
1.2 KiB
from counterfit_connection import CounterFitConnection
|
|
CounterFitConnection.init('127.0.0.1', 5000)
|
|
|
|
import io
|
|
from counterfit_shims_picamera import PiCamera
|
|
|
|
from azure.cognitiveservices.vision.customvision.prediction import CustomVisionPredictionClient
|
|
from msrest.authentication import ApiKeyCredentials
|
|
|
|
camera = PiCamera()
|
|
camera.resolution = (640, 480)
|
|
camera.rotation = 0
|
|
|
|
image = io.BytesIO()
|
|
camera.capture(image, 'jpeg')
|
|
image.seek(0)
|
|
|
|
with open('image.jpg', 'wb') as image_file:
|
|
image_file.write(image.read())
|
|
|
|
prediction_url = '<prediction_url>'
|
|
prediction_key = '<prediction key>'
|
|
|
|
parts = prediction_url.split('/')
|
|
endpoint = 'https://' + parts[2]
|
|
project_id = parts[6]
|
|
iteration_name = parts[9]
|
|
|
|
prediction_credentials = ApiKeyCredentials(in_headers={"Prediction-key": prediction_key})
|
|
predictor = CustomVisionPredictionClient(endpoint, prediction_credentials)
|
|
|
|
image.seek(0)
|
|
results = predictor.detect_image(project_id, iteration_name, image)
|
|
|
|
threshold = 0.3
|
|
|
|
predictions = list(prediction for prediction in results.predictions if prediction.probability > threshold)
|
|
|
|
for prediction in predictions:
|
|
print(f'{prediction.tag_name}:\t{prediction.probability * 100:.2f}%')
|