遇到此特定任务的问题(使用JES 4.3)。任务是使用Python将QR码图像缩小为25 x 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,但不会删除静区。有人能告诉我如何实现这个安静区域的删除?感谢。
答案 0 :(得分:2)
def findQuietZone(pic):
width = getWidth(pic)
height = getHeight(pic)
for x in range(0, width):
for y in range(0, height):
px = getPixel(pic, x, y)
color = getColor(px)
if (colour != white):
value = getX(px)
quietZone = width - value