
# draw all contours in green and accepted ones in redĬontours = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)Ĭontours = contours if len(contours) = 2 else contoursĬv2.drawContours(result,, -1, (0, 255, 0), 1)Ĭv2. # find contours and get one with area about 180*35 Thresh = cv2.threshold(gray, 30, 255, cv2.THRESH_BINARY) Gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) Here is one way to do that in Python/OpenCV. Help is appreciated, since I'm kind of unexperienced with OpenCV. If this should be the wrong way of doing it, please correct me. I tried it with cv2.findContours(image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE) and a few other functions, but I was not successful yet. Now I want to crop the image to the big box in the middle only, but I'm not able to detect the contours of it. With this being done the program outputs this: Costway 2 Pcs 48.5'' Raised Garden Bed Square Plant Box Planter Flower Vegetable White. 2662 white diamond suit : 27E1 white concave-sided diamond : 2B26 white medium diamond : 1F754 alchemical symbol for soap : 1FBAE box drawings light diagonal diamond: 25C8 White Diamond Containing Black Small Diamond: 25C9 Fisheye tainome (Japanese, a kind of bullet) 25CA Lozenge : 2662 white diamond suit. #invert colors, so every dark spots are now white Ret, thresh = cv2.threshold(s, 8, 255, cv2.THRESH_BINARY) #get the saturation plane - all black/white/gray pixels are zero, and colored pixels are above zero. Hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) Img = cv2.imread('rdm_generated_image.png') So far I was able to input it, convert its colors to a HSV color space and applying threshold on it. I'm struggling with cropping an image to the size of a rectangle, which is placed inside of the image.
