【问题标题】:Not able to make video from numPyy array无法从 numPy 数组制作视频
【发布时间】:2020-08-24 12:33:37
【问题描述】:

如果我有一个类型为 numpy 数组的变量。我怎样才能把它转换成视频。这是一个巨大的 numpy 数组,所以我建议您使用右侧的滚动条。我从捕获自己的视频中得到了 numpy 数组,然后得到了它的数组

当我运行代码时,一个窗口正在打开并立即关闭,并打印一条错误语句:

cv2.error: OpenCV(4.2.0) C:/projects/opencv-python/opencv/modules/highgui/src/precomp.hpp:137: error: (-215:Assertion failed) src_depth != CV_16F && src_depth != 函数“convertToShow”中的 CV_32S

'cv2.error:' 不被识别为内部或外部命令,

可运行的程序或批处理文件。

由于 numpy 数组太长,代码太长,这是指向 google 驱动器文件的链接:https://drive.google.com/file/d/1v1ZQT7W3XbzcmT5oaPTAQ3hYJ94TJUCH/view?usp=sharing

代码结构如下:

import cv2 , time , numpy
frame = numpy.asarray(the long list which was too large so i could not pate it here. see it with the link above)

while True:

    # check, frame = video.read()
    # print(check)
    # print(type(frame))
    # grey = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
    #time.sleep(3)
    cv2.imshow("capturing" , frame)
    cv2.waitKey(0)
    key = cv2.waitKey(1)
    if key==ord('q'):
       break

请帮帮我..

【问题讨论】:

    标签: python arrays numpy opencv


    【解决方案1】:

    可以通过将图像转换为 uint8 格式来解决此问题。以下代码适用于您的图像。

        import cv2 , time , numpy
        frame = numpy.asarray(the long list which was too large so i could not pate it here. see it with the link above)
    
             while True:
    
                    # check, frame = video.read()
                    # print(check)
                    # print(type(frame))
                    # grey = cv2.cvtColor(frame , cv2.COLOR_BGR2GRAY)
                    time.sleep(3)
                    frame = frame.astype(numpy.uint8)
                    cv2.imshow("capturing" , frame)
                    cv2.waitKey(0)
                    key = cv2.waitKey(1)
                    if key==ord('q'):
                       break
    

    【讨论】:

    • 但这只是显示一张照片。我该怎么做才能从中获取视频?请参阅我的另一个问题,对此有更好的解释。
    猜你喜欢
    • 1970-01-01
    • 2020-11-02
    • 1970-01-01
    • 2015-09-21
    • 2021-06-17
    • 2022-11-16
    • 2015-10-26
    • 1970-01-01
    • 2012-09-04
    相关资源
    最近更新 更多