使用Python(jython)缩放和移除安静区域的QR代码操作

2024-07-04 08:00:59 发布

您现在位置:Python中文网/ 问答频道 /正文

在这个特定的任务中遇到问题(使用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,但不会移除安静区域。有人能告诉我如何实施这种消除安静区的措施吗?谢谢。在


Tags: 图像floatwidthfileheightxwidthgetwidthstartx
1条回答
网友
1楼 · 发布于 2024-07-04 08:00:59
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

相关问题 更多 >

    热门问题