help me figure out why this isnt working as intented, it's suppose to look on the left side of the cropped image and react when there's a black dot showing, but it just says "The two images have different sizes
The two images have different sizes" "The cropped frames are empty" "Not found": 


def check_for_dot(frame, previous_frame, x, y, w, h, threshold):
    # Convert the image to grayscale
    current_frame = frame.copy()

    # Check if the two images have the same size
    if current_frame.shape != previous_frame.shape:
        print("The two images have different sizes")
        return "Not found"

    # Check if the two images have the same number of channels
    if current_frame.ndim != previous_frame.ndim:
        print("The two images have a different number of channels")
        return "Not found"

    # Crop the images to the specified area
    current_frame = current_frame[y : y + h, x : x + w]
    previous_frame = previous_frame[y : y + h, x : x + w]

    # Check if the cropped frames are not empty
    if current_frame.size != 0 and previous_frame.size != 0:
        # Convert the image to grayscale
        current_frame = cv2.cvtColor(current_frame, cv2.COLOR_BGR2GRAY)
        previous_frame = cv2.cvtColor(previous_frame, cv2.COLOR_BGR2GRAY)
    else:
        print("The cropped frames are empty")

    # Compute the absolute difference between the current frame and the previous frame
    frame_diff = cv2.absdiff(current_frame, previous_frame)

    # Convert the difference image to binary
    _, binary_diff = cv2.threshold(frame_diff, 10, 255, cv2.THRESH_BINARY)

    # Count the number of black pixels
    num_black_pixels = cv2.countNonZero(binary_diff)
    # Check if the number of black pixels is above the threshold
    if num_black_pixels > threshold:
        print("Found it")
        return "Found it"
    else:
        print("Not found")
        return "Not found"


x, y, w, h = 100, 100, 200, 200
threshold = 400


@app.post("/capture_image")
async def capture_image():
    global SERVER_RESPONSE
    previous_frame = None

    # Adjust the green color range
    green_lower = np.array([1, 177, 115], np.uint8)
    green_upper = np.array([85, 255, 255], np.uint8)

    # Load image from file instead of camera
    url = "http://192.168.229.55:8080/shot.jpg"

    while True:
        img_resp = requests.get(url)
        img_arr = np.frombuffer(img_resp.content, np.uint8)
        frame = cv2.imdecode(img_arr, -1)

        # Convert the image from BGR to HSV color space
        hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

        # Create a binary mask where white represents the green color
        green_mask = cv2.inRange(hsv, green_lower, green_upper)

        # Apply morphological operations to reduce noise
        kernel = np.ones((5, 5), np.uint8)
        green_mask = cv2.dilate(green_mask, kernel, iterations=1)
        green_mask = cv2.erode(green_mask, kernel, iterations=1)

        # Find contours in the green mask
        contours, _ = cv2.findContours(
            green_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE
        )

        if len(contours) != 0:
            max_contour = max(contours, key=cv2.contourArea)
            x, y, w, h = cv2.boundingRect(max_contour)

            # Ensure the coordinates are in the correct order
            cropped = frame[y : y + h, x : x + w]

            # Calculate the area of the largest contour
            green_area = cv2.contourArea(max_contour)

            # Check if the detected green area is of a certain size
            AREA_THRESHOLD = 5000  # adjust this value based on your requirement
            if green_area > AREA_THRESHOLD:
                # Check if the directory exists, if not create it
                if not os.path.isdir("images"):
                    os.mkdir("images")

                # Save the image
                height, width = cropped.shape[:2]
                if width < height:
                    cropped = cv2.rotate(cropped, cv2.ROTATE_90_CLOCKWISE)
                # Ensure the coordinates are in the correct order
                cropped = frame[y : y + h, x : x + w]

                # Check if the cropped frame is not empty
                if cropped.size != 0:
                    # Check if this is the first frame
                    if previous_frame is not None:
                        # Check if the sizes of the current frame and the previous frame are the same
                        if cropped.shape == previous_frame.shape:
                            # Check for dot
                            result = check_for_dot(
                                cropped, previous_frame, x, y, w, h, threshold
                            )
                            if result == "Found it":
                                print("Changed")
                                cv2.imwrite("images/captured_image2.jpg", cropped)
                                result = check_picture("images/captured_image2.jpg")
                                SERVER_RESPONSE = result[0]
                                await generate_audio()
                                return result
                        else:
                            print("The two images have different sizes")
                    # Store current frame as previous frame for next iteration
                    previous_frame = cropped.copy()
                    # Display the resulting frame
                    cv2.imshow("Frame", cropped)
                    # Press Q on keyboard to exit
                    if cv2.waitKey(1) & 0xFF == ord("q"):
                        break
                else:
                    print("The cropped frame is empty")
                    return "Not found"