TypeError:函数缺少必需的参数“目标”(位置2)

时间:2019-12-25 18:40:21

标签: python python-3.x pygame

我使用Tim Youtube Channel从Tech复制了此代码(下),但是它不起作用,并给我下一条错误消息:

def ROI(self, image, method):
    if method == 'ROI':
        image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY)
        blimage = cv2.medianBlur(image, 15)
        circles = cv2.HoughCircles(blimage, cv2.HOUGH_GRADIENT, 1, 255, param1=100, param2=60, minRadius=0,
                                   maxRadius=0)
        if circles is not None:
            print(circles)
            circles = np.int16(np.around(circles)) # need int instead of uint to correctly calculate y-r (to get -1 instead of 65535)
            for x,y,r in circles[0, :]:
                print('x, y, r:', x, y, r)
                height, width = image.shape
                print('height, width:', height, width)

                border = 6

                cv2.circle(image, (x, y), r, (0, 255, 0), border)
                cv2.circle(image, (x, y), 2, (0, 0, 255), 3)

                mask = np.zeros(image.shape, np.uint8) # black background
                cv2.circle(mask, (x, y), r, (255), border)  # white mask for black border
                cv2.circle(mask, (x, y), r, (255), -1) # white mask for (filled) circle
                #image = cv2.bitwise_and(image, mask)  # image with black background
                image = cv2.bitwise_or(image, ~mask)  # image with white background

                x1 = max(x-r - border//2, 0)      # eventually  -(border//2+1)
                x2 = min(x+r + border//2, width)  # eventually  +(border//2+1)
                y1 = max(y-r - border//2, 0)      # eventually  -(border//2+1)
                y2 = min(y+r + border//2, height) # eventually  +(border//2+1)
                print('x1, x2:', x1, x2)
                print('y1, y2:', y1, y2)

                image = image[y1:y2,x1:x2]
                print('height, width:', image.shape)
    else:
        print('method is wrong')

    return image

代码:

Traceback (most recent call last):
  File "C:/Users/bence/Python/Game/kakaó.py", line 86, in <module>
    redrawGameWindow()
  File "C:/Users/bence/Python/Game/kakaó.py", line 40, in redrawGameWindow
    win.blit(walkright[walkcount//3])
TypeError: function missing required argument 'dest' (pos 2)

如果有人知道解决方案,请回答,谢谢!

1 个答案:

答案 0 :(得分:0)

等等!我找到了一个解决方案,您只需在walkLeft和walkRight上将角色的x和y值放在括号中即可。这就是所谓的缺失“目的地”。下面的示例:

def redrawGameWindow():
    global walkCount
    win.blit(bg, (0, 0))

if walkCount +1 >= 27:
    walkCount = 0

if left:
    win.blit(walkLeft[walkCount//3], (x, y))
    walkCount += 1

elif right:
    win.blit(walkRight[walkCount//3], (x, y))
    walkCount +=1

else:
    win.blit(char, (x, y))

pygame.display.update()

现在应该可以工作了。您可以考虑重置x和y的起始位置,以制作更具逻辑性的游戏。