sightmachine / SimpleCV

The Open Source Framework for Machine Vision
http://simplecv.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 798 forks source link

colorDistance after img.warp (Chapter 4 of the book) #600

Open absolutelyNoWarranty opened 10 years ago

absolutelyNoWarranty commented 10 years ago

Ubuntu 13.04 Python 2.7.4 SimpleCV 1.3.0 (latest from source) OpenCV 2.4.2

I'm running the code from Chapter 4 of the book where the goal is to measure the size of a toy block. However I'm seeing very strange results from the line dist=warped.colorDistance(bgcolor). I've attached a picture of what it looks like.

img = Image('skew.png')
corners = [(0, 0), (480, 0), (336, 237), (147, 237)]
warped = img.warp(corners)
bgcolor = warped.getPixel(240, 115)
baddist = warped.colorDistance(bgcolor)
baddist.save("bad_dist.png")

bad_dist

If I first save warped to disk and then load it, there are no issues.

img = Image('skew.png')
corners = [(0, 0), (480, 0), (336, 237), (147, 237)]
warped = img.warp(corners)
bgcolor = warped.getPixel(240, 115)
warped.save("warped.png")
warped = Image('warped.png')
bgcolor = warped.getPixel(240, 115)
dist = warped.colorDistance(bgcolor)
dist.save("good_dist.png")

good_dist