我目前正在做Raspberry Pi 3模型B的橙色球的實時對象檢測。下面的代碼應該是一個幀,然後用cv2.inRange()功能,使用RGB(BGR)濾除圖像。然後我應用dialation和侵蝕去除噪音。然後我找到輪廓並繪製它們。此代碼一直工作到現在。然而,當我今天跑了它在不改變它,我得到了如下因素的錯誤:Python OpenCV:inRange()停止工作,沒有變化
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,花了很多時間proggraming這一點,我有一個方案競賽機器人在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'。 – ZdaR