1 | initial version |
Well, if your photo is "very 2D", you can try to detect horizontal and vertical edges.
Get Gx and Gy gradients with a Soble filter, then do a vertical sum on Gx and a horizontal sum on Gy using the reduce function.
The maxima of these vectors should represent the positions of the horizontal and vertical lines. Take the first and last to get the edges of the pallet.
The advantage of this approach is that it's simple, fast, color independent and works for any kind of boxes (you need no training for the look of the box). The disadvantage is that it works only if the lines are horizontal/vertical in the image.
If the lines are not horizontal/vertical, you can try to detect the corners of the boxes using the Harris corner detector or the edges using Hough lines detector and try to find the largest rectangle. If the color is known, you can try to segment it using thresholding and make a contour detector.
2 | No.2 Revision |
Well, if your photo is "very 2D", you can try to detect horizontal and vertical edges.
Get Gx and Gy gradients with a Soble Sobel filter, then do a vertical sum on Gx and a horizontal sum on Gy using the reduce function.
The maxima of these vectors should represent the positions of the horizontal and vertical lines. Take the first and last to get the edges of the pallet.
The advantage of this approach is that it's simple, fast, color independent and works for any kind of boxes (you need no training for the look of the box). The disadvantage is that it works only if the lines are horizontal/vertical in the image.
If the lines are not horizontal/vertical, you can try to detect the corners of the boxes using the Harris corner detector or the edges using Hough lines detector HoughLines or HoughLinesP and try to find the largest rectangle. If the color is known, you can try to segment it using thresholding and make a contour detector.
For an intractive approach (with mouse input), you can use GrabCut.