Ask Your Question
2

Defect detection in mechanical object

asked 2014-05-26 00:11:15 -0600

Sayali gravatar image

updated 2017-08-01 18:42:26 -0600

I have to find out defects in mechanical objects like screw, gear etc. for Quality check purpose using image processing.

image description

For example I want to detect defects like extra material (red circled in above image) remained while manufacturing components like pinion or gear, missing teeth in gear etc. In short find out faulty piece among other objects of same kind moving on conveyor belt. I am using OpenCV 2.4.8 with visual studio 2012.Please guide me for the same... Thanks in advance..

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2014-05-28 05:05:47 -0600

Hi @Sayali!

If you want to compare a known shape with an imperfect one then hausdorff distance is the key for your problem. Here is the source code for calculating the Hausdorff distance.

Perform the following steps:

Training Stage:

Crop the Desired object with its bounding Rectangle & save this as Template Image.

Test Image

  1. Load Scene Image
  2. Load Template Image
  3. Create a Temp Image of Size equivalent to Scene image Size.
  4. Find Contours in scene image & Find the Bounding box.
  5. Set the Temp Image ROI to the Current Bounding Box Region.
  6. Copy the Template image into the Temp image.
  7. Find Contours of Template Image
  8. Now compare the Hausdorff distance of the two Objects by using this code snippet.

You can also refer this post

int distance_2( const std::vector<cv::Point> & a, const std::vector<cv::Point>  & b )
{
    int maxDistAB = 0;
    for (size_t i=0; i<a.size(); i++)
    {
        int minB = 1000000;
        for (size_t j=0; j<b.size(); j++)
        {
            int dx = (a[i].x - b[j].x);     
            int dy = (a[i].y - b[j].y);     
            int tmpDist = dx*dx + dy*dy;

            if (tmpDist < minB)
            {
                minB = tmpDist;
            }
            if ( tmpDist == 0 )
            {
                break; // can't get better than equal.
            }
        }
        maxDistAB += minB;
    }
    return maxDistAB;
}

double distance_hausdorff( const std::vector<cv::Point> & a, const std::vector<cv::Point> & b )
{
    int maxDistAB = distance_2( a, b );
    int maxDistBA = distance_2( b, a );   
    int maxDist = std::max(maxDistAB,maxDistBA);

    return std::sqrt((double)maxDist);
}
edit flag offensive delete link more

Comments

Thank you so much....ill try it out..

Sayali gravatar imageSayali ( 2014-06-03 03:57:27 -0600 )edit

Question Tools

Stats

Asked: 2014-05-26 00:11:15 -0600

Seen: 3,729 times

Last updated: May 28 '14