Detect stitches / seams on the leather from the image. Can it be done just with Python Open CV and built in functions for image manipulation?

I am just starting with computer vision and I do not have much experience with this area. Therefore sorry for little bit generic question but I am not sure how to start and go in the correct direction.

Like in the title. I am building a system which is able to capture the image from the camera and I would like to detect if the 2 lines of stitches / seams are parallel to each other and if the gap between the lines is in specified limits / threshold. See below sample picture:

enter image description here

Can those lines be detected by some functions in open cv or do I need to use machine learning approach and built a model which will recognize the single stitch on the picture and then based on the detection draw new lines and perform calculations?

yes. a combination of multiple operations and some custom logic, of course. do not expect there to be a doWhatIWant() function.

you have a clean and well illuminated picture. that’s a good basis. what’s that third white feature, the continous stripe on top? literally what is it? is that always there? can it be relied upon?

@crackwitz thanks for your reply!

I’m fully aware that there will be no magic doWhatIWant() function :slight_smile:
For sure there will be a custom logic and it will probably vary between the parts I would like to investigate / run samples later as I have different color for the leather and seems and not all of them are in such nice color contrast like the picture provided in my initial message. Some of them are like gray seams on gray leather, so its not so easy to differentiate both.

Going back to your question, that third line on top is so called pipe and it will be always on the picture and it will always have the same color as the stitches in 2 bottom lines. Its very important later for doing the measures as I have to calculate position of first seam line to the bottom edge of that pipe and then second line of seam also to the bottom edge of that pipe. If you could just direct me in some high overview what I should start doing to try to achieve my end goal.

As I was thinking about it I need first eliminate all noise from there (in that case the leather color), just show those 3 lines (pipe and 2 seam lines). Draw some line which will go in the middle of each seam line, draw the line at the bottom edge of the pipe and then just calculate the distance between those lines. Everything should be as much automated as possible so if I just capture new image from the camera it should just run the logic and output the results without the need to tweak the inspection parameters or the parameters to adjust the image.

I would say…

  • median filter to suppress some inconvenient noise
  • threshold

image

then just go column by column. see if you have one bump (top solid line) or two bumps (one of the stitches) or three (both stitches).

where you have all three, you can, for a bump, find the beginning and end of it (top and bottom end), take the middle, and that’s a point on the center line.

much of that can be done with numpy (np.diff, comparisons like np.diff(column) > 0, np.nonzero to get indices, …). or write plain python loops, which isn’t terribly fast but it gets the job done too.

Thanks, will give it a try over the weekend and share the results.