[opencv-python] cv2.rectangle() TypeError: an integer is required (got type tuple)
cv2.rectangle() TypeError: an integer is required (got type tuple)
'tuple에 integer형이 필요'하다는 에러입니다.
cv2.rectangle() parameter를 보면
start_point와 end_point는 tuple type으로 두 개의 좌표 값을 가져야 한다고 나옵니다.
이때 start와 end_point는 모두 int형의 값을 취해야 합니다.
Example 1
import cv2
img = cv2.imread("image/cat.jpg")
rect_img = cv2.rectangle(img, (0, 0), (100.1, 100), (0, 0, 255), -1)
cv2.imshow("rect", rect_img)
cv2.waitKey()
# 출력 (에러)
# Traceback (most recent call last):
# File "D:/python_projects/mine/blog/retacgle_error.py", line 5, in <module>
# rect_img = cv2.rectangle(img, (0, 0), (100.1, 100), (0, 0, 255), -1)
# TypeError: an integer is required (got type tuple)
img = cv2.imread("image/cat.jpg")
rect_img = cv2.rectangle(img, (0, 0), (100.1, 100), (0, 0, 255), -1)
cv2.imshow("rect", rect_img)
cv2.waitKey()
# 출력 (에러)
# Traceback (most recent call last):
# File "D:/python_projects/mine/blog/retacgle_error.py", line 5, in <module>
# rect_img = cv2.rectangle(img, (0, 0), (100.1, 100), (0, 0, 255), -1)
# TypeError: an integer is required (got type tuple)
start_point에서 int를 취하지 않아 에러가 발생했습니다.
Example 2
import cv2
img = cv2.imread("image/cat.jpg")
rect_img = cv2.rectangle(img, (0, 0), (100, 100), (0, 0, 255), -1)
cv2.imshow("rect", rect_img)
cv2.waitKey()
img = cv2.imread("image/cat.jpg")
rect_img = cv2.rectangle(img, (0, 0), (100, 100), (0, 0, 255), -1)
cv2.imshow("rect", rect_img)
cv2.waitKey()
start_point와 end_point 안에 int 형을 취했을 때 정상 동작함을 볼 수 있습니다.
참고문헌
[1] https://www.geeksforgeeks.org/python-opencv-cv2-rectangle-method/[2] https://stackoverflow.com/questions/52598221/typeerror-an-integer-is-required-got-type-tuple
댓글
댓글 쓰기