1 | initial version |
You're using roi screenshot. Unfortunately, I cannot go any further. Fortunately, if you have whole image, I will have to work around.
import cv2 as cv
import numpy as np
def contoursConvexHull(contours):
pts = []
for i in range(0, len(contours)):
for j in range(0, len(contours[i])):
pts.append(contours[i][j])
pts = np.array(pts)
result = cv.convexHull(pts)
return result
image = cv.imread('dash_line.png')
gray = cv.cvtColor(image, cv.COLOR_BGR2GRAY)
blurred = cv.GaussianBlur(gray, (3, 35), 0)
thresh = cv.threshold(blurred, 65, 65, cv.THRESH_BINARY)[0]
imageCanny = cv.Canny(blurred, 0, 100, 0)
contours, hierarchy = cv.findContours(imageCanny, cv.RETR_TREE,
cv.CHAIN_APPROX_NONE)
ConvexHullPoints = contoursConvexHull(contours)
cv.polylines(image, [ConvexHullPoints], True, (0, 0, 0), 4)
cv.imwrite('solid_line.png', image)
cv.imshow('Image', image)
cv.waitKey(0)
Output: