Search code examples
opencvkinectedge-detectiondepth

Detect approximately objects on depth map


I would like to find approximately object on my depth map. For now my process is the following : 1. Normalization of the depth 2. Threshold to get only the closest object 3. Gaussian blur 4. Canny edge detection 5. Contour detection

However, I'm not able to find the box around my object. Actually, I don't know if it's possible with this kind of depth map...

I have three object on the table : a box of food and two mugs.

Normalisation of the depth map

I would like to find approximately a box around my object.

enter image description here

Is there a way to do it just by image processing ? Any help would be appreciated.

Thank you very much in advance.


Solution

  • You can do this using OpenCV. Have a look at the following solution.

    I used the depth map provided in the question as my input image. I performed binary threshold of the gray scale image of the depth map

    ret,th = cv2.threshold(gray,127,255, 1)
    

    and obtained the following:

    enter image description here

    Now in order to fill the gaps in the image, I performed morphological close operation

    kernel = np.ones((15,15),np.uint8)
    dilate = cv2.morphologyEx(th, cv2.MORPH_CLOSE, kernel, 3)
    

    enter image description here

    Then I found contours using:

    contours,hierarchy = cv2.findContours(dilate,2,1)
    

    and drew them using:

    cv2.drawContours(img, contours, -1, (0,255,0), 3)
    

    finally obtained this:

    enter image description here

    Hope this is what you were looking for :)