I am trying to draw a line into an image but I couldnt. I tried the contours features. I am open to any kind of opinion and help. I am leaving the code I tried to draw but I couldnt draw line.
import time
import cv2
import numpy as np
import sys
sys.maxsize
img = cv2.pyrDown(cv2.imread("ellipse.png", cv2.IMREAD_UNCHANGED))
# threshold image
ret, threshed_img = cv2.threshold(cv2.cvtColor(img, cv2.COLOR_BGR2GRAY),
127, 255, cv2.THRESH_BINARY)
# find contours and get the external one
contours, hier = cv2.findContours(threshed_img, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for c in contours:
# get the bounding rect
x, y, w, h = cv2.boundingRect(c)
# draw a green rectangle to visualize the bounding rect
# cv2.rectangle(img, (x, y), (x+w, y+h), (0, 1, 0), 2)
# get the min area rect
rect = cv2.minAreaRect(c)
box = cv2.boxPoints(rect)
# convert all coordinates floating point values to int
box = np.int0(box)
# draw a red 'nghien' rectangle
cv2.drawContours(img, [box], 0, (0, 0, 255))
print(len(contours))
cv2.drawContours(img, contours, -1, (255, 255, 0), 1)
cv2.imshow("contours", img)
cv2.imshow("contours", img)
while True:
key = cv2.waitKey(1)
if key == 27: #ESC key to break
break
cv2.destroyAllWindows()