Good morning everyone, I have my .mlmodel trained on license plates with size of 1920x1080.
My video test is also in the same resolution, when I am running the code it returns this error:
typeerror: Image input, 'imagePath' must be of type PIL.Image.Image in the input dict
The line is:
# Predict using Core ML model
output = model.predict({"imagePath": temp.name, "iouThreshold": 0.5, "confidenceThreshold": 0.5})
And the complete code is:
import cv2
model = coremltools.models.MLModel('NeuralVision.mlmodel')
video_path = 'anpr_video.mp4'
cap = cv2.VideoCapture(video_path)
# Desired size for the model input
new_width = 1920
new_height = 1080
# Process the video frame by frame
while cap.isOpened():
ret, frame = cap.read()
# Break the loop if we have reached the end of the video
if not ret:
break
# Convert the frame to a PIL Image
image = Image.fromarray(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
# Resize the image to the desired size
resized_image = image.resize((new_width, new_height), Image.LANCZOS)
# Save the resized image as a temporary file
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp:
resized_image.save(temp.name)
# Predict using Core ML model
output = model.predict({"imagePath": temp.name, "iouThreshold": 0.5, "confidenceThreshold": 0.5})
# Print the output
print(output)
# Display the frame
cv2.imshow('Frame', frame)
# Break the loop if the user presses the 'q' key
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the video capture object and close all windows
cap.release()
cv2.destroyAllWindows()
What I should try to change because at this point I don't know where it could be the problem