Ask Your Question
0

How to solve TypeError: Expected Ptr<cv::UMat> for argument 'src'?

asked 2020-10-11 03:09:18 -0600

Ashley gravatar image

I'm trying to highlight faces in a video with face_cascade. My code:

import cv2
face_cascade = cv2.CascadeClassifier('D:/Anaconda/Lib/site-packages/cv2/data/haarcascade_frontalface_default.xml')
frame2 = cv2.VideoCapture('C:/Users/HomePC/Desktop/video.mp4')
scaling_factor = 0.5
frame2 = cv2.resize(frame2, None, fx=scaling_factor, fy = scaling_factor, interpolation = cv2.INTER_AREA)
face_rects2 = face_cascade.detectMultiScale(frame2, scaleFactor = 1.3, minNeighbors = 6)
for (x,y,w,h) in face_rects1:
    cv2.rectangle(frame2, (x,y), (x+w,y+h), (0,255,0), 3)
cv2.imshow('Input video', frame2)
print('Found {0} faces in Input video!'.format(len(face_rects2)))

And here is the error I get:

runfile('C:/Users/HomePC/Desktop/ArtInt/3lab/lab3.py', wdir='C:/Users/HomePC/Desktop/ArtInt/3lab')
Found 3 faces in Input image #2!
Traceback (most recent call last):

  File "C:\Users\HomePC\Desktop\ArtInt\3lab\lab3.py", line 29, in <module>
    frame2 = cv2.resize(frame2, None, fx=scaling_factor, fy = scaling_factor, interpolation = cv2.INTER_AREA)

TypeError: Expected Ptr<cv::UMat> for argument 'src'
edit retag flag offensive close merge delete

Comments

sturkmen gravatar imagesturkmen ( 2020-10-11 03:18:49 -0600 )edit

Typo error. Change this:

for (x,y,w,h) in face_rects1:

to:

for (x,y,w,h) in face_rects2:
supra56 gravatar imagesupra56 ( 2020-11-30 21:20:00 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-10-11 03:27:21 -0600

mvuori gravatar image

...Your code doesn't output the "Found 3 faces in Input image #2!" message so it comes from another piece of code...

But your frame2 is not a Mat, it is a VideoCapture object.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-10-11 03:09:18 -0600

Seen: 7,196 times

Last updated: Oct 11 '20