【问题标题】:How to Threshold a video in python?如何在python中对视频进行阈值处理?
【发布时间】:2020-02-18 16:04:32
【问题描述】:

我正在尝试将视频读入 python(无论是实时的还是预先录制的都无关紧要),然后使用阈值算法处理每一帧,以将视频转换为 2 色格式。

使用简单的阈值方法,我得到这个错误:

cv2.imshow('newFrame',newFrame) TypeError: Expected Ptr<cv::UMat> for argument 'mat'

图像的阈值化似乎很简单,但我似乎无法将阈值化方法产生的数据转换为后续任何东西都能识别的格式。 我在下面包含了完整的代码。

import numpy as np
import cv2

cap = cv2.VideoCapture('Loop_1.mov')

while(cap.isOpened()):
    ret, frame = cap.read()
    if ret==True:

        threshed = cv2.threshold(frame,50,255,cv2.THRESH_BINARY)
        newFrame = np.array(threshed)

        cv2.imshow('newFrame',newFrame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    else:
        break

# Release everything if job is finished
cap.release()
#out.release()
cv2.destroyAllWindows()

【问题讨论】:

标签: python opencv video image-thresholding


【解决方案1】:

阈值函数应该返回两个参数

retval, 阈值 = cv2.threshold(frame, 50, 255, cv2.THRESH_BINARY)

【讨论】:

    猜你喜欢
    • 2021-02-10
    • 1970-01-01
    • 2019-07-08
    • 1970-01-01
    • 2015-10-19
    • 2014-11-30
    • 2020-07-05
    • 2021-12-23
    • 1970-01-01
    相关资源
    最近更新 更多