在这个特定的任务中遇到问题(使用jes4.3)。任务是使用Python将二维码图像缩小到25×25的图像,并从图像中移除白色边界(安静区)。我没有麻烦的去除它的安静区,但我没有麻烦。我相信它必须在缩放之前完成,并且安静区的宽度可以改变。这样看来,我需要一个一个地移除每一个像素的外层,直到程序检测到它不再是安静区。很确定需要一个while循环,但不知道如何有效地实现它。目前我的代码:
def reduce(qrPicture):
file = makePicture(qrPicture)
myPicture = duplicatePicture(file)
width = getWidth(myPicture)
height = getHeight(myPicture)
newPicture = makeEmptyPicture(25, 25)
newWidth = getWidth(newPicture)
newHeight = getHeight(newPicture)
basePixel = getPixelAt(myPicture, 0, 0)
startX = 0
startY = 0
xWidth = width/float(newWidth)
yHeight = height/float(newHeight)
for x in range(startX, newWidth):
for y in range(startY, newHeight):
smallPix = getPixel(newPicture, x, y)
pixelX = x*xWidth;
pixelY = y*yHeight;
oPixel = getPixel(myPicture, int(pixelX), int(pixelY))
setColor(smallPix, getColor(oPixel))
如前所述,这只是将图像缩放到25 x 25,但不会移除安静区域。有人能告诉我如何实施这种消除安静区的措施吗?谢谢。在
相关问题 更多 >
编程相关推荐