while True:
# Stage 1: Read an image from our webcam
image = webcam.get_current_frame()
# Stage 2: Detect edges in image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (5,5), 0)
edges = cv2.Canny(gray, 100, 200)
# Stage 3: Find contours
contours, _ = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
contours = sorted(contours, key=cv2.contourArea, reverse=True)[:10]
for contour in contours:
# Stage 4: Shape check
perimeter = cv2.arcLength(contour, True)
approx = cv2.approxPolyDP(contour, 0.01*perimeter, True)
if len(approx) == QUADRILATERAL_POINTS:
# Stage 5: Perspective warping
topdown_quad = get_topdown_quad(gray, approx.reshape(4, 2))
# Stage 6: Border check
if topdown_quad[(topdown_quad.shape[0]/100.0)*5,
(topdown_quad.shape[1]/100.0)*5] > BLACK_THRESHOLD: continue在线上
if topdown_quad [(topdown_quad.shape [0] /100.0) * 5, (topdown_quad.shape [1] /100.0) * 5]> BLACK_THRESHOLD:
continue是错误发生的地方。
这一切为什么要发生?
发布于 2018-06-26 01:31:48
(topdown_quad.shape [0] /100.0) * 5和(topdown_quad.shape [1] /100.0) * 5是浮点值。
在Python中,不能将浮点值用作索引。
这就是错误消息(尽管可能是冗长的)所告诉您的: NumPy扩展了Python以处理各种不同类型的索引,但它们仍然要么是整数、整数片,要么是特殊值。
你到底想要什么还不清楚。如果topdown_quad.shape[0]是75,那么topdown_quad.shape[0] / 100 * 5是3.75,那么您想要第3行还是第4行?您可能希望截断到0(或者向负无穷远,如果值可能是负值),或者舍入到最近的,或圆形的IEEE样式,.5被向上或向下舍入,这取决于整体部分是偶数,还是其他任何东西。
不管你想要什么,你都必须明确地写出来。例如,如果您想要截断:
if topdown_quad[int((topdown_quad.shape[0]/100.0)*5),https://stackoverflow.com/questions/51033612
复制相似问题