Error finding the center of an OpenCV Python object

1
Hello, I'm studying opencv to use in a drone and while I was implementing a code from a tutorial that detected objects and drew a circle in the center of it, and for that you should get half the dimensions x+w and y+h only the problem is that when I do x+w/2 and y+h/2 the following error appears: integer argument expected, got float . HELP ME !!

Code:

import cv2
import numpy as np

cap = cv2.cv2.VideoCapture(0)
kernel = np.ones((5,5), np.uint8)

while True:
    ret, frame = cap.read()
    rangomax = np.array([50,255,50])
    rangomin = np.array([0, 51, 0])
    mascara = cv2.cv2.inRange(frame, rangomin, rangomax)
    opening = cv2.cv2.morphologyEx(mascara, cv2.cv2.MORPH_OPEN, kernel)
    x,y,w,h = cv2.cv2.boundingRect(opening)
    cv2.cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0), 3)
    cv2.cv2.circle(frame,(x+w/2, y+h/2), 5,(0,0,255), -1)
    cv2.cv2.imshow('video', frame)
    k = cv2.cv2.waitKey(1) & 0xFF
    if k == 27:
        break
cap.release()
    
asked by anonymous 19.06.2018 / 23:14

1 answer

1

It expects an int try to use the int () constructor to do what would be a cast

Python :

cv.Circle(img, center, radius, color, thickness=1, lineType=8, shift=0) → None

then it would be

cv2.cv2.circle(frame,(int(x+w/2), int(y+h/2)), 5,(0,0,255), -1)
    
20.06.2018 / 01:41