使用 Python (jython) 的 QR 码操作 - 缩放和删除静区
QR Code manipulation using Python (jython) - Scaling and removing Quiet Zone
在执行此特定任务时遇到问题(使用 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,但不会移除静区。有人能告诉我如何实现静区的移除吗?谢谢
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
在执行此特定任务时遇到问题(使用 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,但不会移除静区。有人能告诉我如何实现静区的移除吗?谢谢
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