fix this error   File "D:\Pfa\projet f_nf_flask\app.py", line 134, in gen
    cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 255, 255), 2)
cv2.error: OpenCV(4.7.0) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img'
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img' 
in this code 
# from flask import Flask, render_template, Response
# import cv2
# import numpy as np
# from keras.models import load_model
# from waitress import serve
# import tensorflow as tf
# import imutils

# model = load_model('models\Xrchi1')
# face_cascade = cv2.CascadeClassifier('cascade\haarcascade_frontalface_default.xml')

# prototxt = 'cascade\deploy.prototxt'
# model1 = 'cascade\modeldetect.caffemodel'
# net = cv2.dnn.readNetFromCaffe(prototxt, model1)

# app = Flask(__name__)

# @app.route('/')
# def index():
#     return render_template('index.html')

# def detect_faces(frame):
#     gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
#     faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
#     return faces

# def gen():
#     cap = cv2.VideoCapture(1)
#     while True:
#         ret, frame = cap.read()
#         if not ret:
#             continue

#         faces = detect_faces(frame)

#         for (x, y, w, h) in faces:
#             face = frame[y:y+h, x:x+w]
#             face = cv2.resize(face, (84, 119))
#             face = tf.expand_dims(face, axis=0)
#             face = tf.cast(face, tf.float32)
#             face /= 255.0

#             prediction = model.predict(face)
#             prediction = (prediction < 0.35)

#             color = (0, 0, 255) if prediction == False else (0, 255, 0)
#             label = "No-Focus" if prediction == False else "Focus"

#             cv2.rectangle(frame, (x, y), (x+w, y+h), color, 2)
#             cv2.putText(frame, label, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, color, 2)

#         _, jpeg = cv2.imencode('.jpg', frame)
#         frame = jpeg.tobytes()
#         yield (b'--frame\r\n'
#                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

#     cap.release()
#     cv2.destroyAllWindows()

# @app.route('/video_feed')
# def video_feed():
#     return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')

# if __name__ == '__main__':
#     app.run(host='0.0.0.0', port=8080)


from flask import Flask, render_template, Response
import cv2
import numpy as np
from keras.models import load_model
from waitress import serve
import tensorflow as tf
import imutils
#import matplotlib.pyplot as plt

model = load_model('models\Xrchi1')
face_cascade=cv2.CascadeClassifier('cascade\haarcascade_frontalface_default.xml')

prototxt = 'cascade\deploy.prototxt'
model1 = 'cascade\modeldetect.caffemodel'
net = cv2.dnn.readNetFromCaffe(prototxt, model1)

app = Flask(__name__)

@app.route('/')
def index():
    return render_template('index.html')

def gen():
    # Accéder à la webcam
    cap = cv2.VideoCapture(0)
    #width = 1000
    #height = 900
    # Set the scale factors
    #cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
    #cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
    while True:
        ret, frame = cap.read()
        print(ret)
        if not ret:
            continue
        scale_percent = 120  # Zoom factor (increase to zoom in, decrease to zoom out)
        width = int((frame.shape[1] * scale_percent / 100)-180)
        height = int((frame.shape[0] * scale_percent / 100)-150)
        frame = cv2.resize(frame, (width, height), interpolation=cv2.INTER_LINEAR)
       
       #frame = cv2.resize(frame, (frame.shape[1]-100, frame.shape[0]-90))
       
       #frame = imutils.resize(frame, width=300, height=300)
       #frame=np.resize(frame,(400,400,3))

       #print(frame.shape, face.shape)
        (h, w) = frame.shape[:2]
       
       #print(h,w)
        blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0))
        net.setInput(blob)
        detections = net.forward()
        confidence = detections[0, 0, 0, 2]
      
        for i in range(0, detections.shape[2]):
      # extract the confidence (i.e., probability) associated with the prediction
            confidence = detections[0, 0, i, 2]
      # filter out weak detections by ensuring the `confidence` is
      # greater than the minimum confidence threshold
            if confidence > 0.5:
        # compute the (x, y)-coordinates of the bounding box for the object
                box = detections[0, 0, i, 3:7] * np.array([w, h, w, h])
                (startX, startY, endX, endY) = box.astype("int")
        # draw the bounding box of the face along with the associated probability
                text = "{:.2f}%".format(confidence * 100)
                y = startY - 10 if startY - 10 > 10 else startY + 10
                cv2.rectangle(frame, (startX, startY), (endX, endY), (0, 255, 255), 2)
                face = frame[startY:endY, startX:endX]
           #print(face)
                print("face=",face.shape)
                face=np.resize(frame,(1,119,84,3))
                face=tf.data.Dataset.from_tensor_slices(face).batch(1)
                print(face)
                prediction = model.predict(face)
                print(prediction)
                prediction=(prediction<0.4)
         #print(prediction)
         #print(prediction==[False])
                color = (0, 0, 255) if prediction == False else (0, 255, 0)
                label = "Fraud" if prediction == False else "Non-Fraud"
                cv2.putText(frame, label, (startX, startY-10), cv2.FONT_HERSHEY_SIMPLEX, 0.9, color, 2)
                _, jpeg = cv2.imencode('.jpg', frame)
                frame = jpeg.tobytes()
         #print(type(frame))
                yield (b'--frame\r\n'
                    b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')     
    cap.release()
    cv2.destroyAllWindows()

@app.route('/video_feed')
def video_feed():
    return Response(gen(),
                    mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '_main_':
    app.run( host='0.0.0.0', port=8080)