Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Analyze contour of jigsaw puzzle pieces

Hello. As a pet project for learning OpenCV, i'm trying to make jigsaw puzzle solver that would work purely on shape (ignore colors). I found SimpleCV a great library. Thanks to everyone involved very much.

I found these posts to be very helpful (sorry for inconvenience but this site software does not let me post clickable links):

  • stackoverflow 3124915 matching jigsaw puzzle pieces
  • stackoverflow 1344677 solving a picture jumble

Although, i'm stuck at finding holes and bulges.

Here's what i do: i am really sorry for inconvenience but site software does not let me post images so the album is here imgur.com/a/j24l8

  1. Take photo of pieces on chroma key (cropped)

    (image 1 from imgur, sorry, not enough karma)

  2. Simple threshold-like processing in Gimp, although i can imagine it could be automated using OpenCV

    (image 2 from imgur, sorry, not enough karma)

  3. SimpleCV.Image('pieces.png').findBlobs(minsize=40000, maxsize=90000) for each blob: .crop().save(distinct_file)

    (image 3 from imgur, sorry, not enough karma)

  4. That's where i'm stuck. How to measure pieces in useful way? When i try to apply img.findCorners(maxnum=4, mindistnace=200) i get this: red dots are detected by computer, green - by me in Gimp. I think i could draw straight lines connecting proper corners, then any white color outside that contour would be bulge and any black color inside would be hole. I believe they even would be detected by .findBlobs().

    (image 4 from imgur, sorry, not enough karma)

    Next thing i would like to do is calculate length of two continuous lines on each side (that is excluding any hole/bulge), as shown on image. I believe these lengths, normalized to length of side is enough hint to match majority of puzzle. Probably major problem here is that pieces are not perfect squares (red side is twisted clock wise, green side is rounded) and even worse, pieces as whole are slightly rotated relative to camera view.

    (image 5 from imgur, sorry, not enough karma)

click to hide/show revision 2
added links and images

Analyze contour of jigsaw puzzle pieces

Hello. As a pet project for learning OpenCV, i'm trying to make jigsaw puzzle solver that would work purely on shape (ignore colors). I found SimpleCV a great library. Thanks to everyone involved very much.

I found these posts to be very helpful (sorry for inconvenience but this site software does not let me post clickable links): helpful:

  • stackoverflow 3124915 matching jigsaw puzzle pieces
  • stackoverflow 1344677 solving a picture jumblehttp://stackoverflow.com/questions/3124915/matching-jigsaw-puzzle-pieces
  • http://stackoverflow.com/questions/1344677/solving-a-picture-jumble

Although, i'm stuck at finding holes and bulges.

Here's what i do: i am really sorry for inconvenience but site software does not let me post images so the album is here imgur.com/a/j24l8

  1. Take photo of pieces on chroma key (cropped)

    (image 1 from imgur, sorry, not enough karma)

  2. Simple threshold-like processing in Gimp, although i can imagine it could be automated using OpenCV

    (image 2 from imgur, sorry, not enough karma)

  3. SimpleCV.Image('pieces.png').findBlobs(minsize=40000, maxsize=90000) for each blob: .crop().save(distinct_file)

    (image 3 from imgur, sorry, not enough karma)

  4. That's where i'm stuck. How to measure pieces in useful way? When i try to apply img.findCorners(maxnum=4, mindistnace=200) i get this: red dots are detected by computer, green - by me in Gimp. I think i could draw straight lines connecting proper corners, then any white color outside that contour would be bulge and any black color inside would be hole. I believe they even would be detected by .findBlobs().

    (image 4 from imgur, sorry, not enough karma)

    Next thing i would like to do is calculate length of two continuous lines on each side (that is excluding any hole/bulge), as shown on image. I believe these lengths, normalized to length of side is enough hint to match majority of puzzle. Probably major problem here is that pieces are not perfect squares (red side is twisted clock wise, green side is rounded) and even worse, pieces as whole are slightly rotated relative to camera view.

    (image 5 from imgur, sorry, not enough karma)

click to hide/show revision 3
reuploaded images, added update on manual marks

Analyze contour of jigsaw puzzle pieces

Hello. As a pet project for learning OpenCV, i'm trying to make jigsaw puzzle solver that would work purely on shape (ignore colors). I found SimpleCV a great library. Thanks to everyone involved very much.

I found these posts to be very helpful:

  • http://stackoverflow.com/questions/3124915/matching-jigsaw-puzzle-pieces
  • http://stackoverflow.com/questions/1344677/solving-a-picture-jumble

Although, i'm stuck at finding holes and bulges.

Here's what i do:

  1. Take photo of pieces on chroma key (cropped)

  2. Simple threshold-like processing in Gimp, although i can imagine it could be automated using OpenCV

  3. SimpleCV.Image('pieces.png').findBlobs(minsize=40000, maxsize=90000) for each blob: .crop().save(distinct_file)

  4. That's where i'm stuck. How to measure pieces in useful way? When i try to apply img.findCorners(maxnum=4, mindistnace=200) i get this: red dots are detected by computer, green - by me in Gimp. I think i could draw straight lines connecting proper corners, then any white color outside that contour would be bulge and any black color inside would be hole. I believe they even would be detected by .findBlobs().

    Next thing i would like to do is calculate length of two continuous lines on each side (that is excluding any hole/bulge), as shown on image. I believe these lengths, normalized to length of side is enough hint to match majority of puzzle. Probably major problem here is that pieces are not perfect squares (red side is twisted clock wise, green side is rounded) and even worse, pieces as whole are slightly rotated relative to camera view.

Update 1 to my programmer's shame i used Gimp again to align all pieces on grid on a large canvas, but it could be easily done in SimpleCV (or even PIL for that matter). Having all pieces in static grid allows for a lot of simplifications in latter processing. Next, i threw a few hours at it and marked all corners, bulges and holes by hand.

Next (this part needs comments from SimpleCV experts) i tried but failed to enumerate all red/blue blobs on that image. Naive .findBlobs returns big white blobs, with maxsize=500 it does not 'see' anything. It would seem to me a perfect fit for .findBlobsFromPalette, but it does yields AttributeError, so i called .getPalette but it does not recognize pure red and blue colors at all, (consequently?) does not find blobs by red color which is absent from palette. Even when i do .getPalette(centroids=[RED,BLUE,WHITE,BLACK]) and they're in result, it still does not 'see' any red/blue blobs by palette. Of course, all these tries were repeated on new Image object.

What has worked, although i feel this may be ugly:

corners = img.hueDistance((255,0,0)).threshold(1).invert().findBlobs(minsize=1, maxsize=1000)
features = img.hueDistance((0,0,255)).threshold(1).invert().findBlobs(minsize=1, maxsize=1000)

Smells delicious! Thanks to grid align, i can easily map each blob to corresponding puzzle piece by int(f.boundingBox()[0] / 200). Going to analyze that data right now, will update with results.

Analyze contour of jigsaw puzzle pieces

Hello. As a pet project for learning OpenCV, i'm trying to make jigsaw puzzle solver that would work purely on shape (ignore colors). I found SimpleCV a great library. Thanks to everyone involved very much.

I found these posts to be very helpful:

  • http://stackoverflow.com/questions/3124915/matching-jigsaw-puzzle-pieces
  • http://stackoverflow.com/questions/1344677/solving-a-picture-jumble

Although, i'm stuck at finding holes and bulges.

Here's what i do:

  1. Take photo of pieces on chroma key (cropped)

  2. Simple threshold-like processing in Gimp, although i can imagine it could be automated using OpenCV

  3. SimpleCV.Image('pieces.png').findBlobs(minsize=40000, maxsize=90000) for each blob: .crop().save(distinct_file)

  4. That's where i'm stuck. How to measure pieces in useful way? When i try to apply img.findCorners(maxnum=4, mindistnace=200) i get this: red dots are detected by computer, green - by me in Gimp. I think i could draw straight lines connecting proper corners, then any white color outside that contour would be bulge and any black color inside would be hole. I believe they even would be detected by .findBlobs().

    Next thing i would like to do is calculate length of two continuous lines on each side (that is excluding any hole/bulge), as shown on image. I believe these lengths, normalized to length of side is enough hint to match majority of puzzle. Probably major problem here is that pieces are not perfect squares (red side is twisted clock wise, green side is rounded) and even worse, pieces as whole are slightly rotated relative to camera view.

Update 1 to my programmer's shame i used Gimp again to align all pieces on grid on a large canvas, but it could be easily done in SimpleCV (or even PIL for that matter). Having all pieces in static grid allows for a lot of simplifications in latter processing. Next, i threw a few hours at it and marked all corners, bulges and holes by hand.

Next (this part needs comments from SimpleCV experts) i tried but failed to enumerate all red/blue blobs on that image. Naive .findBlobs returns big white blobs, with maxsize=500 it does not 'see' anything. It would seem to me a perfect fit for .findBlobsFromPalette, but it does yields AttributeError, so i called .getPalette but it does not recognize pure red and blue colors at all, (consequently?) does not find blobs by red color which is absent from palette. Even when i do .getPalette(centroids=[RED,BLUE,WHITE,BLACK]) and they're in result, it still does not 'see' any red/blue blobs by palette. Of course, all these tries were repeated on new Image object.

What has worked, although i feel this may be ugly:

corners = img.hueDistance((255,0,0)).threshold(1).invert().findBlobs(minsize=1, maxsize=1000)
features = img.hueDistance((0,0,255)).threshold(1).invert().findBlobs(minsize=1, maxsize=1000)

Smells delicious! Thanks to grid align, i can easily map each blob to corresponding puzzle piece by int(f.boundingBox()[0] / 200). Going to analyze that data right now, will update with results.