【问题标题】:Mac photo booth on cv2 python, why does my code result in an error?cv2 python上的Mac照片亭,为什么我的代码会导致错误?
【发布时间】:2022-01-02 23:28:15
【问题描述】:

我希望代码使用 cv2 以 1 秒的间隔拍摄 4 张照片,然后使用 hconcat 函数将它们相加。当我尝试运行此代码时,我得到('numpy.ndarray' 对象没有属性'release'),有人可以帮忙

import cv2,random
num = random.randint(0,2000)
cam = cv2.VideoCapture(0)

cv2.namedWindow("Mac")

def concat_tile(im_list_2d):
    return cv2.vconcat([cv2.hconcat(im_list_h) for im_list_h in im_list_2d])

x = []
for i in range(4):
    ret,frame = cam.read()
    x.append(frame)
    frame.release()
    cv2.destroyAllWindows()

im_v = concat_tile([[x[0],x[1]],
                    [x[2],x[3]]])
img_name = "opencv_frame_{}.png".format(num)
cv2.imwrite(img_name,im_v)

【问题讨论】:

    标签: python opencv opencv3.0 cv2 opencv-python


    【解决方案1】:

    不应该是frame.release(),而是试试cam.release()

    另外,release()cv2.destroyAllWindows() 应该写在代码的末尾,而不是在 for 循环中

    for i in range(4):
        ret,frame = cam.read()
        x.append(frame)
    
    cam.release()
    cv2.destroyAllWindows()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      • 2011-07-07
      • 1970-01-01
      • 2011-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多