下面是在Ubuntu中运行良好的代码。但是,当我在Raspberry Pi和Raspberry Pi相机上使用它时,却没有任何结果。
import cv2
import numpy as np
video = cv2.VideoCapture(0)
while True:
ret, orig_frame = video.read()
if not ret:
video = cv2.VideoCapture(0)
continue
frame = cv2.GaussianBlur(orig_frame, (5, 5), 0)
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
low_yellow = np.array([18, 94, 140])
up_yellow = np.array([48, 255, 255])
mask = cv2.inRange(hsv, low_yellow, up_yellow)
edges = cv2.Canny(mask, 75, 150)
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 50, maxLineGap=50)
if lines is not None:
print 'yellow'
low_black=np.array([0, 0, 0])
up_black=np.array([180, 255, 30])
maskB= cv2.inRange(hsv, low_black, up_black)
edgesB = cv2.Canny(maskB, 75, 150)
linesB=cv2.HoughLinesP(edgesB, 1, np.pi/180, 50, maxLineGap=50)
if linesB is not None:
print 'Black'
key = cv2.waitKey(25)
if key == 27:
break
video.release()
cv2.destroyAllWindows()