2

I'm trying to extract this mold from this picture. I've got some code to extract it, the only thing I need are the four corners. Mold

def detect_object(image):
    orig = image.copy()
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    blurry = cv2.adaptiveThreshold(image.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 11, 3)

    contours, _ = cv2.findContours(blurry, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
    contours = sorted(contours, key = cv2.contourArea, reverse = True)
    cnt = contours[1] #We don't want the outer contour.
    cv2.drawContours(orig, cnt, -1, (0,255,255))
    return orig

When I try this with for example a sudoku, it draws the contours of the outer lines perfect Sudoku contours. As a result, this sudoku can be extracted from the picture with some extra code. However, when I try this with my aluminium mold, no useful contours can be found. Contours found

I've already tried to use a lot of filters, but unfortunately it still doesn't work.

Does someone knows some helpful tips? Thanks in advance.

ZF007
  • 3,708
  • 8
  • 29
  • 48
  • Do you have a picture showing the result with the sudoku you have? – Mast Mar 19 '20 at 10:47
  • 1
    metallic surfaces are often challenging, because their reflectance behaviour differs locally and you often have reflecting objects/environment visible. In addition, in your image, the background has a low contrast to your aluminium plate. If you choose a diffuse and very dark background (AND MORE LIGHT!!!), your very simple method might work ok. – Micka Mar 19 '20 at 11:26
  • 1
    @Mast I've updated the question with a picture of the contours of the sudoku – Randpy Projects Mar 19 '20 at 11:31
  • @Micka Agreed. Putting a couple of filters/masks over the question to increase contrast may help, but a better picture would help tremendously as well. – Mast Mar 19 '20 at 12:26
  • ..and in focus would also help. Tilt the mold 90 degrees to fit the longest side of the CCD and zoom in into a single slot as far as possible... place a ruler in sight as well for calibration of dimensions. (my canny, line and corner detection algorithms don't like this image). Canny only shows left slot and center slot partially. – ZF007 Mar 19 '20 at 13:28
  • You need to photograph it on a background that has more contrast with the plate colors, such as a black background. – fmw42 Mar 19 '20 at 16:53
  • Thanks guys for your reactions. I knew my pictures were not really optimal, but I was hoping that some way it would work. Unfortunately. I will take some new pictures after COVID-19 ;) – Randpy Projects Mar 20 '20 at 09:51

0 Answers0