【发布时间】:2017-04-01 10:20:40
【问题描述】:
我目前正在使用 Raspberry Pi 3 Model B 对橙色球进行实时对象检测。下面的代码应该采取一帧,然后使用 cv2.inRange() 函数,使用 RGB (BGR) 过滤掉图像)。然后我应用拨号和腐蚀来消除噪音。然后我找到轮廓并绘制它们。这段代码一直有效。但是,当我今天运行它而不更改它时,出现以下错误:
Traceback (most recent call last):
File "/home/pi/Desktop/maincode.py", line 12, in <module>
mask = cv2.inRange(frame, lower, upper)
error: /build/opencv-ISmtkH/opencv-2.4.9.1+dfsg/modules/core/src/arithm.cpp:2701: error: (-209) The lower bounary is neither an array of the same size and same type as src, nor a scalar in function inRange
任何帮助都会非常棒,因为我是 openCV 的新手,花了很多时间编写这个程序,而且我在 5 天内完成了机器人竞赛。
提前谢谢你
import cv2
import cv2.cv as cv
import numpy as np
capture = cv2.VideoCapture(0)
while capture.isOpened:
ret, frame = capture.read()
im = frame
lower = np.array([0, 100 ,150], dtype = 'uint8')
upper = np.array([10,180,255], dtype = 'uint8')
mask = cv2.inRange(frame, lower, upper)
eroded = cv2.erode(mask, np.ones((7, 7)))
dilated = cv2.dilate(eroded, np.ones((7, 7)))
contours, hierarchy = cv2.findContours(dilated,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(im,contours,-1,(0,255,0),3)
cv2.imshow('colors',im)
cv2.waitKey(1)
【问题讨论】:
-
您确定您在
mask = cv2.inRange(frame, lower, upper)中输入的框架不是空的吗?尝试在此语句之前打印frame.shape。
标签: python opencv object-detection