Hi have this code, but it is not performing what I want
import cv2
import math
import matplotlib.pyplot as plt
import numpy as np
#read in the image
image = cv2.imread('inserttest.jpg')
# converting the image to hsv
img_rgb = cv2.cvtColor (image, cv2.COLOR_BGR2RGB)
hsv_img = cv2.cvtColor (img_rgb, cv2.COLOR_RGB2HSV)
#segmenting color of choice on the hsv image first by specifying color range
#mask is always in binary 1s and 0s, so cant be worked on, with the color info hidden in binary
color_value1 = (10, 10, 44) #light color --light white (0, 0, 200) light blue (90, 150, 50)
color_value2 = (145, 60, 255) #dark color -- dark white (145, 60, 255) dark blue (148, 255, 255)
mask = cv2.inRange(hsv_img, color_value1, color_value2 )
#imposing the mask on the original image // converting mask to pixel image
segmented = cv2.bitwise_and(img_rgb, img_rgb, mask = mask)
# Find contours in the image
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#getting the x,y coordinates
cnt = contours[0]
# Find the minimum area rectangle for the largest contour
rect = cv2.minAreaRect(cnt)
#to obtain 4 points of the rectangle
box = cv2.boxPoints(rect)
box = np.int0(box)
#drawing a box around the object
#cv2.drawContours(segmented,[box],0,(0,0,255),2)
angle = rect[-1]
print("tilt angle is: ", angle)
# Draw contours around the object
cv2.drawContours(segmented, contours, 0, (0, 255, 0), 2)
# Show image:
cv2.imshow("outline contour & centroid", segmented)
# Wait until a key is pressed:
cv2.waitKey(0)
# Destroy all created windows:
cv2.destroyAllWindows()