title: Find contour and boundary to obtain points inside image OpenCV Python
body: <p>I have a code to draw contour of object in a image and then draw a rectangle around them. i need to find widest diameter in my shape (two point) witch is straight horizontal line Now I need to find the points(coordinates of the pixels) that are inside the boundary of the object.</p>
  
  <p>heres my code:</p>
  
  <p><a href="https://i.stack.imgur.com/8hQii.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8hQii.jpg" alt="Picture for Reference"></a></p>
  
  <pre><code>class App:
      def __init__(self, window, window_title, image_path="ex.jpg"):
          self.window = window
          self.window.title(window_title)
  
          # Load an image using OpenCV
          self.cv_img = cv2.cvtColor(cv2.imread(image_path), cv2.COLOR_BGR2RGB)
  
          # Get the image dimensions (OpenCV stores image data as NumPy ndarray)
          self.height, self.width, no_channels = self.cv_img.shape
  
          # Create a canvas that can fit the above image
          self.canvas = tkinter.Canvas(window, width = self.width, height = self.height)
          self.canvas.pack()
  
          # Use PIL (Pillow) to convert the NumPy ndarray to a PhotoImage
          self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(self.cv_img))
  
          # Add a PhotoImage to the Canvas
          self.canvas.create_image(0, 0, image=self.photo, anchor=tkinter.NW)
  
          # Button that lets the user blur the image
          self.btn_blur=tkinter.Button(window, text="Blur", width=25, command=self.blur_image)
          self.btn_blur.pack(anchor=tkinter.CENTER, expand=True)
  
          # Button that lets the user edeged the image
          self.btn_blur=tkinter.Button(window, text="edged", width=25, command=self.edged_image)
          self.btn_blur.pack(anchor=tkinter.CENTER, expand=True)
  
          # Button that lets the user edeged the image
          self.btn_blur=tkinter.Button(window, text="draw box", width=25, command=self.draw_box)
          self.btn_blur.pack(anchor=tkinter.CENTER, expand=True)
  
          self.window.mainloop()
  
      # Callback for the "Blur" button
      def blur_image(self):
          self.cv_img = cv2.blur(self.cv_img, (3, 3))
          self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(self.cv_img))
          self.canvas.create_image(0, 0, image=self.photo, anchor=tkinter.NW)
  
      # Callback for the "edged" button
      def edged_image(self):
          #edeged image
          self.cv_img=cv2.Canny(self.cv_img,50,180)
          self.cv_img = cv2.dilate(self.cv_img, None, iterations=1)
          self.cv_img = cv2.erode(self.cv_img, None, iterations=1)
          self.photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(self.cv_img))
          self.canvas.create_image(0, 0, image=self.photo, anchor=tkinter.NW)
  
      # Callback for the "draw contours" button
      def draw_box(self):        
          #draw contour
          cnts = cv2.findContours(self.cv_img.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
          cnts = cnts[0] if imutils.is_cv2() else cnts[1]
          #draw box
          for c in cnts:
              self.cv_img = cv2.drawContours(self.cv_img, [c], 0, (0,255,0), 3)
              x,y,w,h = cv2.boundingRect(c)
              self.cv_img = cv2.rectangle(self.cv_img,(x,y),(x+w,y+h),(0,255,0),2)
  
  #Create a window and pass it to the Application object
  App(tkinter.Tk(), "morteza app")
  </code></pre>