我遵循了本教程:https : //www.pyimagesearch.com/2017/09/11/object-detection-with-deep-learning-and-opencv/ 我改变了这部分,在插入之前将图像源转换为灰度到神经网络
frame = vs.read()
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
frame = imutils.resize(frame, width=400)
(h, w) = frame.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)),
0.007843, (300, 300), 127.5)
net.setInput(blob)
detections = net.forward()
Run Code Online (Sandbox Code Playgroud)
但是会出现这个错误:
OpenCV(3.4.1) Error: Assertion failed (ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0) in cv::dnn::ConvolutionLayerImpl::getMemoryShapes, file D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\layers\convolution_layer.cpp, line 234
Traceback (most recent call last):
File "C:/Users/Toshiba/PycharmProjects/real-time-object-detection/study7ver2.py", line 75, in <module>
detections = net.forward()
cv2.error: OpenCV(3.4.1) D:\Build\OpenCV\opencv-3.4.1\modules\dnn\src\layers\convolution_layer.cpp:234: error: (-215) ngroups > …Run Code Online (Sandbox Code Playgroud)