Reputation: 31
I have to convert a video to gray format first, then to hsv but I get this error :
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 :/
Upvotes: 1
Views: 2109
Reputation: 7985
The first problem is you need to convert frame
to the gray-scale object.
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.
im_hsv = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV)
Also, please do change the rest of the vid
variable with the im_hsv
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)
Upvotes: 1