Error error: (-5:Bad argument) in function 'rectangle'

generation code

import cv2 as cv
import numpy as np
import matplotlib.pyplot as plt
from skimage import io

def geration_bb (img, threshold, rect_th, path):
  boxes = prediction(img, threshold)
  for i in range(len(boxes)):
      cv2.rectangle(img,boxes[i][0],boxes[i][1],color =(255, 0, 0),thickness=rect_th)
  plt.figure(figsize=(10,10))
  plt.imshow(img)
  plt.xticks([])
  plt.yticks([])
  plt.show()

  # for to save the prediction figure 
  io.imsave(path, img)

error generation

error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'rectangle'
> Overload resolution failed:
>  - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
>  - Can't parse 'pt1'. Sequence item with index 0 has a wrong type
>  - argument for rectangle() given by name ('color') and position (3)
>  - argument for rectangle() given by name ('color') and position (3)

it’s got to be integers. and you should use loops to their full effect:

  boxes = prediction(img, threshold).astype(int)
  for box in boxes:
      cv2.rectangle(img, box[0], box[1], color=(255, 0, 0), thickness=rect_th)

I’m hoping that thing is a numpy array. if it’s not, just use boxes = np.asarray(boxes, dtype=int) before the loop