Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Striped cloth detection using OpenCV

Tags:

c++

opencv

I am trying to detect horizontal and vertical striped patterns in cloth pictures. Two examples of pictures that should be detected are:

enter image description here enter image description here

My first approach was trying to use a Hough Line detector. The problem is the clothes are often deformed or wrinkled so the lines aren't straight and the detector fails.

It can be assumed that the lines are horizontal or vertical with a deviation of a few degrees (horizontal and vertical striped patterns). Also that the lines are parallel

What would be a good approach to detect such slightly deformed lines?

like image 592
GuillermoMP Avatar asked May 09 '26 20:05

GuillermoMP


1 Answers

  • Convert the image to gray scale
  • Calculate the gradient (for example, using sobel)
  • Take horizontal and vertical projections of the gradient image
  • Threshold the projections and count the peaks

I quickly tried this in Matlab. You can try it with opencv. Use reduce function to take the projections. Below is the Matlab code and some results:

im = imread('pRfUL.jpg');
gr = rgb2gray(im);
h = fspecial('sobel');
grad = imfilter(gr, h) + imfilter(gr, h'); % quick gradient

hpr = sum(grad);
vpr = sum(grad');

figure,
subplot(2,2,1), imshow(gr), title('gray scale')
subplot(2,2,2), imshow(grad), title('gradient')
subplot(2,2,3), plot(hpr), title('horizontal projection')
subplot(2,2,4), plot(vpr), title('vertical projection')

enter image description here

EDIT

One possible improvement would be to consider horizontal and vertical cases separately. So, there would be two passes through the image for each cases (this might perform better for noisy/textured cases, and as Nallath pointed out- I think he's referring to bilateral filtering-, you can use some additional filtering). That is, when you look for horizontal strips, use the horizontal filter which will give strong responses for horizontally oriented edges. Same for vertical case.

grad = imfilter(gr, h); % for strong horizontal responses in the above code. use grad = imfilter(gr, h') for vertical

The result for horizontal case: note that the horizontal projection and the vertical offset have dropped significantly

enter image description here

like image 141
dhanushka Avatar answered May 12 '26 10:05

dhanushka