我按照这个教程进行操作: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()
然而出现这个错误:
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 > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function cv::dnn::ConvolutionLayerImpl::getMemoryShapes
第 75 行是:detections = net.forward()
为什么我要将其转换为灰度?因为我需要在将图像输入神经网络之前进行直方图均衡,以便夜间输入的图像会更清晰。