所以我想要做的是使用OpenCV来检测盒子和制作感兴趣的区域。当一个盒子经过一个AOI时,它会把它算作一种用途。这很好,但它不断增加每个帧的使用。在检测到使用情况时,我只想这样做一次。
所以我在这里做的是:
这里的错误是,它要么一直在计算每一个帧的使用情况,要么只会一次又一次地计数。我想计算它的每一个独特的用法,而不是每一个帧。这就是我到目前为止所拥有的。
# # loop over the contours
for c in contours:
# Filter out the blobs that are too small to be considered cars.
contours = filter(lambda cont: cv2.contourArea(cont) > 30, contours)
# compute the bounding box for the contour
(x, y, w, h) = cv2.boundingRect(c)
#Find each Area Of Interest usage
#detectUsage(area_of_interest, c, frame)
for aoi in area_of_interest:
#Check if there is a overlap between the detected contour and AOI
if gvp.machineUseCheck(c, aoi[1]):
print("{} in use".format(aoi[0]))
cv2.rectangle(frame, (x, y), (x + w, y + h), (222, 150, 1), 2)
if aoi[2] == False:
aoi[2] = True
print("{} set to True".format(aoi[0]))
elif aoi[2] == True:
print("{} Already true".format(aoi[0]))
elif gvp.machineUseCheck(c, aoi[1]) == False:
aoi[2] = False
print("{} not in use".format(aoi[0]))
#Get all the centers for the bounding boxes
center = (int(x + w / 2), int(y + h / 2))
cv2.circle(frame, center, 4, (0, 0, 255), -1)发布于 2018-12-05 05:55:49
我想出了我所需要做的就是稍微重新组织for循环。
for aoi in area_of_interest:
cv2.putText(frame, "AOI Value:{}".format(aoi[2]), (10, 150), cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(0, 255, 0), 2)
cv2.putText(frame, "{} Count:{}".format(aoi[0], str(aoi[3])), (10, aoi[4]), cv2.FONT_HERSHEY_SIMPLEX,
0.6, (0, 255, 0), 2)
i = 0
for c in contours:
# Filter out the blobs that are too small to be considered cars.
contours = filter(lambda cont: cv2.contourArea(cont) > 30, contours)
# compute the bounding box for the contour
(x, y, w, h) = cv2.boundingRect(c)
center = (int(x + w / 2), int(y + h / 2))
cv2.circle(frame, center, 4, (0, 0, 255), -1)
if gvp.machineUseCheck(c, aoi[1]):
if not aoi[2]:
aoi[2] = True
aoi[3] += 1
cv2.putText(frame, "Machine IN USE:", (10, 130), cv2.FONT_HERSHEY_SIMPLEX, 0.6,
(0, 255, 0), 2)
cv2.rectangle(frame, (x, y), (x + w, y + h), (222, 150, 1), 2)
break
elif i == len(c):
aoi[2] = False
break
i += 1https://stackoverflow.com/questions/53624170
复制相似问题