我正在使用OpenCV连接到IP摄像头进行物体检测。问题是视频流是超低的。当我评论这个位“rects = detect(灰色,级联)”时,视频流很流畅。
我读到它与imdecode有关,并且每帧将帧转换为灰色但我找不到解决方案,我该如何解决这个问题呢?
bytes=""
while True:
'''authenticated connection to IP cam'''
bytes+=stream.read(16384)
a = bytes.find('\xff\xd8')
b = bytes.find('\xff\xd9')
if a!=-1 and b!=-1:
jpg = bytes[a:b+2]
bytes= bytes[b+2:]
i = cv2.imdecode(np.fromstring(jpg, dtype=np.uint8),cv2.CV_LOAD_IMAGE_COLOR)
'''Convert frames to gray to be able to detect objects'''
gray = cv2.cvtColor(i, cv2.COLOR_BGR2GRAY)
gray = cv2.equalizeHist(gray)
'''Detect and draw whatever you specified in haarcascades'''
rects = detect(gray, cascade)
vis = i.copy()
draw_rects(vis, rects, (0, 255, 0))
'''Display the videostream'''
cv2.imshow('authenticated cam',vis)
if cv2.waitKey(1) ==27:
exit(0)