'An error occurred while performing face recognition using opencv
I took a face recognition lecture using opencv and I followed it, but I get an error
import cv2
model = 'data/res10_300x300_ssd_iter_140000.caffemodel'
config = 'data/deploy.prototxt'
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print('Camera open failed!')
exit()
net = cv2.dnn.readNet(model, config)
if net.empty():
print('Net open failed!')
exit()
while True:
ret, frame = cap.read()
if frame is None:
break
blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), (104.0, 177.0, 123.0))
net.setInput(blob)
detect = net.forward()
detect = detect[0, 0, :, :]
(h, w) = frame.shape[:2]
for i in range(detect.shape[0]):
confidence = detect[i, 2]
if confidence < 0.5:
break
x1 = int(detect[i, 3] * w)
y1 = int(detect[i, 4] * h)
x2 = int(detect[i, 5] * w)
y2 = int(detect[i, 6] * h)
cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0))
label = 'Face: %4.3f' % confidence
cv2.putText(frame, label, (x1, y1 - 1), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 255, 0),1, cv2.LINE_AA)
cv2.imshow('frame', frame)
if cv2.waitKey(1) == 27:
break
cv2.destroyAllWindows()
I get the following error message
error Traceback (most recent call last)
<ipython-input-12-06c753864c1d> in <module>
23 blob = cv2.dnn.blobFromImage(frame, 1.0, (300, 300), (104.0, 177.0, 123.0))
24 net.setInput(blob)
---> 25 detect = net.forward()
26
27 detect = detect[0, 0, :, :]
error: OpenCV(4.5.1) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-
kh7iq4w7\opencv\modules\dnn\src\layers\convolution_layer.cpp:352: error: (-215:Assertion failed)
!blobs.empty() || inputs.size() > 1 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
what is the problem and what should i do
could anyone advice on this?
version
python 3.8.5
opencv-python 4.5.1.48
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|