AttributeError: 'tuple' object has no attribute 'copy' in opencv2

AttributeError: 'tuple' object has no attribute 'copy' in opencv2

我最近一直在使用 OpenCV-python 来做一些增强现实,最近我遇到了这个错误:

    imgAug = imgWebcam.copy()
AttributeError: 'tuple' object has no attribute 'copy'

启动以下代码时:

import cv2
import numpy as np
 
cap = cv2.VideoCapture(0)
imgTarget = cv2.imread('TargetImage.jpg')
myVid = cv2.VideoCapture('video.mp4')
 
detection = False
frameCounter = 0
 
success, imgVideo = myVid.read()

imgWebcam = cap.read()
imgAug = imgWebcam.copy()

有没有办法纠正这个问题?

cap.read() 返回元组,所以你必须像 myVid.read().

一样解压它
success, imgVideo = myVid.read()

ret, imgWebcam = cap.read() # unpacking
imgAug = imgWebcam.copy()