I want to draw the ellipse contour around the given figure append below. I am not getting the correct result since the figure consist of two lines.
I have tried the following:-
- Read the Image
- Convert the BGR to HSV
- Define the Range of color blue
- Create the inRange Mask to capture the value of between lower and upper blue
- Find the contour & Draw the fit ellipse.
Here is the source code-
import cv2
import numpy as np
image=cv2.imread('./source image.jpg')
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
lower_blue= np.array([75, 0, 0])
upper_blue= np.array([105, 255, 255])
mask = cv2.inRange(hsv, lower_blue, upper_blue)
res=cv2.bitwise_and(image,image,mask=mask)
_,contours,_=cv2.findContours(close,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
ellipse = cv2.fitEllipse(max(contours,key=cv2.contourArea))
cv2.ellipse(image,ellipse,(0,255,0),2)
cv2.imshow('mask',image)
cv2.waitKey(0)
cv2.destroyAllWindows()
The figure/Image below show the Expected & Actual Output-
Expected & Actual display image
Source Image Source Image
Output Contour Array Contour file