简体   繁体   English

预期 Ptr<cv::UMat> 对于参数&#39;src&#39;

[英]Expected Ptr<cv::UMat> for argument 'src'

I have to convert a video to gray format first, then to hsv but I get this error :我必须先将视频转换为灰色格式,然后再转换为 hsv,但出现此错误:

Traceback (most recent call last):
  File "c:/Users/eycan/Desktop/serittakip.py", line 8, in <module>
    im = cv2.cvtColor(vid, cv2.COLOR_BGR2GRAY) # grayscale kopya
TypeError: Expected Ptr<cv::UMat> for argument 'src'

My code:我的代码:

import cv2
import numpy as np

vid = cv2.VideoCapture("C:\\Users\\eycan\\Desktop\\serit\\yol.mp4")

while 1:    #frame cektıgımız ıcın whıle dongusune soktuk resım olsaydı boyle olmazdı
    _,frame = vid.read()
    im = cv2.cvtColor(vid, cv2.COLOR_BGR2GRAY) # grayscale kopya
    vid = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV) #bgr dan hsv ye donusturduk

    lower_white = np.array([0, 0, 212])
    upper_white = np.array([131, 255, 255])

    mask = cv2.inRange(vid,lower_white,upper_white)
    cv2.imshow("Frame",frame)
    cv2.imshow("MASK",mask)

Pls help :/请帮助:/

  • The first problem is you need to convert frame to the gray-scale object.第一个问题是您需要将frame转换为灰度对象。

    •  im = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  • The second problem is when you convert from BGR2HSV please use different variable, other than vid , since vid is reading the next video frame.第二个问题是当你从BGR2HSV转换时,请使用不同的变量,除了vid ,因为vid正在读取下一个视频帧。

    •  im_hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
  • Also, please do change the rest of the vid variable with the im_hsv另外,请使用im_hsv更改vid变量的其余部分

    • mask = cv2.inRange(im_hsv,lower_white,upper_white)

Code:代码:


import cv2
import numpy as np

vid = cv2.VideoCapture("C:\\Users\\eycan\\Desktop\\serit\\yol.mp4")

while 1:    #frame cektıgımız ıcın whıle dongusune soktuk resım olsaydı boyle olmazdı
    _,frame = vid.read()
    im = cv2.cvtColor(frane, cv2.COLOR_BGR2GRAY) # grayscale kopya
    im_hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV) #bgr dan hsv ye donusturduk

    lower_white = np.array([0, 0, 212])
    upper_white = np.array([131, 255, 255])

    mask = cv2.inRange(im_hsv,lower_white,upper_white)
    cv2.imshow("Frame",frame)
    cv2.imshow("MASK",mask)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM