My code is
model = ResNet50(weights='imagenet')
def read_cam(video_capture):
if video_capture.isOpened():
windowName = "yolo"
cv2.namedWindow(windowName, cv2.WINDOW_NORMAL)
cv2.resizeWindow(windowName, 1280, 720)
cv2.moveWindow(windowName, 0, 0)
cv2.setWindowTitle(windowName, "Yolo Object Detection")
while True:
# Check to see if the user closed the window
if cv2.getWindowProperty(windowName, 0) < 0:
break
ret_val, frame = video_capture.read()
print(frame)
frame = np.expand_dims(frame, axis=0)
frame = preprocess_input(frame)
preds = model.predict(frame)
# print(preds)
print('Predicted:', decode_predictions(preds, top=3)[0])
However, this causes a few errors. First, apparently, it's expecting a different sized array:
ValueError: Error when checking input: expected input_1 to have shape (224, 224, 3) but got array with shape (720, 1280, 3)
Use the cv2. resize function to change the frame before calling model.predict as the pretrained model you are using accepts only image of the size 224x224.
frame=cv2.resize(frame,(224,224))